⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elementstylesheet.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            parents.toArray(new ElementStyleSheet[parents.size()]);
      }

      for (int i = parentsCached.length - 1; i >= 0; i--)
      {
        sc.addParent(parentsCached[i]);
        cloneParentsCached[i] = parentsCached[i];
      }

      // Clone all default parents ...
      sc.defaultSheets = new ArrayList();// defaultSheets.clone();

      if (defaultCached == null)
      {
        defaultCached = (ElementStyleSheet[])
            defaultSheets.toArray(new ElementStyleSheet[defaultSheets.size()]);
      }

      for (int i = defaultCached.length - 1; i >= 0; i--)
      {
        sc.addDefaultParent(defaultCached[i]);
        cloneDefaultCached[i] = defaultCached[i];
      }
      sc.parentsCached = cloneParentsCached;
      sc.defaultCached = cloneDefaultCached;
      return sc;
    }
    catch (CloneNotSupportedException cne)
    {
      throw new IllegalStateException("Clone failed.");
    }
  }

  /**
   * Returns a boolean style (defaults to false if the style is not found).
   *
   * @param key  the style key.
   *
   * @return <code>true</code> or <code>false</code>.
   */
  public boolean getBooleanStyleProperty(final StyleKey key)
  {
    return getBooleanStyleProperty(key, false);
  }

  /**
   * Returns a boolean style.
   *
   * @param key  the style key.
   * @param defaultValue  the default value.
   *
   * @return true or false.
   */
  public boolean getBooleanStyleProperty(final StyleKey key, final boolean defaultValue)
  {
    final Boolean b = (Boolean) getStyleProperty(key, null);
    if (b == null)
    {
      return defaultValue;
    }
    return b.booleanValue();
  }

  /**
   * Returns an integer style.
   *
   * @param key  the style key.
   * @param def  the default value.
   *
   * @return the style value.
   */
  public int getIntStyleProperty(final StyleKey key, final int def)
  {
    final Integer i = (Integer) getStyleProperty(key, new Integer(def));
    return i.intValue();
  }

  /**
   * Returns the font for this style-sheet.
   *
   * @deprecated use getFontDefinition()
   * @return the font.
   */
  public Font getFontStyleProperty()
  {
    final String name = (String) getStyleProperty(FONT);
    final int size = getIntStyleProperty(FONTSIZE, -1);
    final boolean bold = getBooleanStyleProperty(BOLD);
    final boolean italic = getBooleanStyleProperty(ITALIC);
    int style = Font.PLAIN;
    if (bold)
    {
      style += Font.BOLD;
    }
    if (italic)
    {
      style += Font.ITALIC;
    }
    final Font retval = new Font(name, style, size);
    return retval;
  }

  /**
   * Sets the font for this style-sheet.
   *
   * @deprecated use setFontDefinition()
   * @param font  the font (<code>null</code> not permitted).
   */
  public void setFontStyleProperty(final Font font)
  {
    if (font == null)
    {
      throw new NullPointerException("ElementStyleSheet.setFontStyleProperty: font is null.");
    }
    setStyleProperty(FONT, font.getName());
    setBooleanStyleProperty(BOLD, font.isBold());
    setBooleanStyleProperty(ITALIC, font.isItalic());
    setStyleProperty(FONTSIZE, new Integer(font.getSize()));
  }

  /**
   * Returns the font for this style-sheet.
   *
   * @return the font.
   */
  public FontDefinition getFontDefinitionProperty()
  {
    final String name = (String) getStyleProperty(FONT);
    final int size = getIntStyleProperty(FONTSIZE, -1);
    final boolean bold = getBooleanStyleProperty(BOLD);
    final boolean italic = getBooleanStyleProperty(ITALIC);
    final boolean underlined = getBooleanStyleProperty(UNDERLINED);
    final boolean strike = getBooleanStyleProperty(STRIKETHROUGH);
    final boolean embed = getBooleanStyleProperty(EMBEDDED_FONT);
    final String encoding = (String) getStyleProperty(FONTENCODING);

    final FontDefinition retval = new FontDefinition(name, size, bold, italic, underlined, strike,
        encoding, embed);
    return retval;
  }

  /**
   * Sets the font for this style-sheet.
   *
   * @param font  the font (<code>null</code> not permitted).
   */
  public void setFontDefinitionProperty(final FontDefinition font)
  {
    if (font == null)
    {
      throw new NullPointerException("ElementStyleSheet.setFontStyleProperty: font is null.");
    }
    setStyleProperty(FONT, font.getFontName());
    setStyleProperty(FONTSIZE, new Integer(font.getFontSize()));
    setBooleanStyleProperty(BOLD, font.isBold());
    setBooleanStyleProperty(ITALIC, font.isItalic());
    setBooleanStyleProperty(UNDERLINED, font.isUnderline());
    setBooleanStyleProperty(STRIKETHROUGH, font.isStrikeThrough());
    setBooleanStyleProperty(EMBEDDED_FONT, font.isEmbeddedFont());
    setStyleProperty(FONTENCODING, font.getFontEncoding(null));
  }

  /**
   * Returns an enumeration of all local property keys.
   *
   * @return an enumeration of all localy defined style property keys.
   */
  public Iterator getDefinedPropertyNames()
  {
    return properties.keySet().iterator();
  }

  /**
   * Adds a {@link StyleChangeListener}.
   *
   * @param l  the listener.
   */
  public void addListener(final StyleChangeListener l)
  {
    styleChangeSupport.addListener(l);
  }

  /**
   * Removes a {@link StyleChangeListener}.
   *
   * @param l  the listener.
   */
  public void removeListener(final StyleChangeListener l)
  {
    styleChangeSupport.removeListener(l);
  }

  /**
   * Sends a change event notification to all registered {@link StyleChangeListener} objects.
   *
   * @param source  the source of the change.
   * @param key  the style key.
   * @param value  the new value.
   */
  public void styleChanged(final ElementStyleSheet source, final StyleKey key, final Object value)
  {
    if (styleCache != null)
    {
      styleCache.remove(key);
    }
    styleChangeSupport.fireStyleChanged(key, value);
  }

  /**
   * Sends a change event notification to all registered {@link StyleChangeListener} objects.
   *
   * @param source  the source of the change.
   * @param key  the style key.
   */
  public void styleRemoved(final ElementStyleSheet source, final StyleKey key)
  {
    if (styleCache != null)
    {
      styleCache.remove(key);
    }
    styleChangeSupport.fireStyleRemoved(key);
  }

  /**
   * Helper method for serialization.
   *
   * @param out the output stream where to write the object.
   * @throws IOException if errors occur while writing the stream.
   */
  private void writeObject(final ObjectOutputStream out)
      throws IOException
  {
    out.defaultWriteObject();
    final int size = properties.size();
    out.writeInt(size);
    final Iterator it = properties.keySet().iterator();
    while (it.hasNext())
    {
      final Object key = it.next();
      out.writeObject(key);
      final Object value = properties.get(key);
      SerializerHelper.getInstance().writeObject(value, out);
    }
  }

  /**
   * Helper method for serialization.
   *
   * @param in the input stream from where to read the serialized object.
   * @throws IOException when reading the stream fails.
   * @throws ClassNotFoundException if a class definition for a serialized object
   * could not be found.
   */
  private void readObject(final ObjectInputStream in)
      throws IOException, ClassNotFoundException
  {
    styleChangeSupport = new StyleChangeSupport(this);

    in.defaultReadObject();
    final int size = in.readInt();
    properties = new HashMap(size);
    for (int i = 0; i < size; i++)
    {
      final Object key = in.readObject();
      final Object value = SerializerHelper.getInstance().readObject(in);
      properties.put(key, value);
    }
  }

  /**
   * Creates and returns a copy of this object. This method calls getCopy().
   *
   * @return     a clone of this instance.
   * @see Cloneable
   */
  public Object clone()
  {
    return getCopy();
  }

  /**
   * Returns the stylesheet collection of this element stylesheet, or null,
   * if this stylessheet is not assigned with an collection.
   *
   * @return the collection or null.
   */
  public StyleSheetCollection getStyleSheetCollection()
  {
    return collectionHelper.getStyleSheetCollection();
  }

  /**
   * Registers the given StyleSheet collection with this ElementStyleSheet.
   * If there is already another stylesheet collection registered, this method
   * will throw an <code>InvalidStyleSheetCollectionException</code>.
   *
   * @param styleSheetCollection the stylesheet collection that should be registered.
   * @throws InvalidStyleSheetCollectionException if there is already an other
   * stylesheet registered.
   * @throws NullPointerException if the given stylesheet collection is null.
   */
  public void registerStyleSheetCollection(final StyleSheetCollection styleSheetCollection)
  {
    collectionHelper.registerStyleSheetCollection(styleSheetCollection);
  }

  /**
   * Unregisters the given stylesheet collection from this ElementStyleSheet. If this stylesheet
   * collection is not registered with this ElementStyleSheet, this method will throw an
   * <code>InvalidStyleSheetCollectionException</code>
   *
   * @param styleSheetCollection the stylesheet collection that should be unregistered.
   * @throws InvalidStyleSheetCollectionException  if there is already an other stylesheet
   * registered.
   * @throws NullPointerException if the given stylesheet collection is null.
   */
  public void unregisterStyleSheetCollection(final StyleSheetCollection styleSheetCollection)
  {
    collectionHelper.unregisterStyleSheetCollection(styleSheetCollection);
  }

  /**
   * Returns the ID of the stylesheet. The ID does identify an element stylesheet an
   * all all cloned instances of that stylesheet.
   *
   * @return the ID of this stylesheet.
   */
  public InstanceID getId()
  {
    return id;
  }

  /**
   * Returns true, if this stylesheet is one of the global default stylesheets.
   * Global default stylesheets are unmodifiable and shared among all element stylesheets.
   *
   * @return true, if this is one of the unmodifiable global default stylesheets,
   * false otherwise.
   */
  public boolean isGlobalDefault()
  {
    return false;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -