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

📄 stylesheetpropertyeditorpane.java

📁 报表设计软件,很好的
💻 JAVA
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner (taquera@sherito.org);
 *
 * (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * ------------------------------
 * StyleSheetPropertyEditorPane.java
 * ------------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: StyleSheetPropertyEditorPane.java,v 1.2 2004/04/20 18:55:01 taqua Exp $
 *
 * Changes
 * -------------------------
 * 25.10.2003 : Initial version
 *
 */

package org.jfree.designer.visualeditor.elementeditor;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jfree.report.modules.parser.ext.factory.stylekey.DefaultStyleKeyFactory;
import org.jfree.report.modules.parser.ext.factory.stylekey.PageableLayoutStyleKeyFactory;
import org.jfree.report.modules.parser.ext.factory.stylekey.StyleKeyFactory;
import org.jfree.report.style.ElementStyleSheet;
import org.jfree.report.style.StyleChangeListener;
import org.jfree.report.style.StyleKey;

public final class StyleSheetPropertyEditorPane
        extends JComponent
{

  private static final class StyleKeyComparator
          implements Comparator
  {
    /**
     * Compares its two arguments for order.  Returns a negative integer, zero, or a
     * positive integer as the first argument is less than, equal to, or greater than the
     * second.<p>
     *
     * @param o1 the first object to be compared.
     * @param o2 the second object to be compared.
     * @return a negative integer, zero, or a positive integer as the first argument is
     *         less than, equal to, or greater than the second.
     *
     * @throws ClassCastException if the arguments' types prevent them from being compared
     *                            by this Comparator.
     */
    public final int compare (final Object o1, final Object o2)
    {
      final StyleKey k1 = (StyleKey) o1;
      final StyleKey k2 = (StyleKey) o2;
      return k1.getName().compareTo(k2.getName());
    }
  }

  private final class StyleSheetChangeHandler
          implements StyleChangeListener
  {
    /**
     * Receives notification that a style has changed.
     *
     * @param source the source of the change.
     * @param key    the style key.
     * @param value  the value.
     */
    public final void styleChanged (final ElementStyleSheet source, final StyleKey key,
                              final Object value)
    {
      if (getChangeListener() != null)
      {
        getChangeListener().stateChanged(new ChangeEvent(StyleSheetPropertyEditorPane.this));
      }
    }

    /**
     * Receives notification that a style has been removed.
     *
     * @param source the source of the change.
     * @param key    the style key.
     */
    public final void styleRemoved (final ElementStyleSheet source, final StyleKey key)
    {
      if (getChangeListener() != null)
      {
        getChangeListener().stateChanged(new ChangeEvent(StyleSheetPropertyEditorPane.this));
      }
    }
  }

  private ElementStyleSheet styleSheet;
  private final ArrayList allKeys;
  private final HashMap allElements;
  private final StyleKeyComparator comparator;
  private ChangeListener changeListener;
  private final StyleSheetChangeHandler styleSheetChangeHandler;

  public StyleSheetPropertyEditorPane ()
  {
    styleSheetChangeHandler = new StyleSheetChangeHandler();
    comparator = new StyleKeyComparator();
    allKeys = new ArrayList();
    allElements = new HashMap();

    setLayout(new GridBagLayout());

    addStyleKeyFactory(new DefaultStyleKeyFactory());
    addStyleKeyFactory(new PageableLayoutStyleKeyFactory());
  }

  public final void addStyleKeyFactory (final StyleKeyFactory factory)
  {
    final Iterator it = factory.getRegisteredKeys();
    while (it.hasNext())
    {
      final String name = (String) it.next();
      final StyleKey key = factory.getStyleKey(name);
      if (isSystemKey(key) == false)
      {
        allKeys.add(key);
      }
    }
    Collections.sort(allKeys, comparator);
    rebuild();
  }

  public final boolean isSystemKey (final StyleKey key)
  {
    if (key.equals(ElementStyleSheet.BOUNDS))
    {
      return true;
    }
    return false;
  }

  protected final void rebuild ()
  {
    removeAll();
    allElements.clear();

    for (int i = 0; i < allKeys.size(); i++)
    {
      final StyleKey key = (StyleKey) allKeys.get(i);
      final StyleKeyCarrier carrier = new StyleKeyCarrier
              (key, new PropertyEditorContainer(key.getValueType()));
      allElements.put(key, carrier);

      GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = i;
      gbc.anchor = GridBagConstraints.WEST;
      add(carrier.getEnableTrigger(), gbc);

      gbc = new GridBagConstraints();
      gbc.gridx = 1;
      gbc.gridy = i;
      gbc.anchor = GridBagConstraints.WEST;
      add(carrier.getLabel(), gbc);

      gbc = new GridBagConstraints();
      gbc.gridx = 2;
      gbc.gridy = i;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.weightx = 1;
      gbc.anchor = GridBagConstraints.WEST;
      add(carrier.getContainer(), gbc);
    }
  }

  public final void clearStyleKeyFactories ()
  {
    allKeys.clear();
  }

  public final ElementStyleSheet getStyleSheet ()
  {
    return styleSheet;
  }

  /**
   * Defines the stylesheet edited by this component. If the stylesheet is null, the
   * editors will be disabled, else the editors will be updated to reflect the settings
   * contained in the stylesheet.
   *
   * @param styleSheet the stylesheet.
   */
  public final void setStyleSheet (final ElementStyleSheet styleSheet)
  {
    if (this.styleSheet != null)
    {
      this.styleSheet.removeListener(styleSheetChangeHandler);
    }
    this.styleSheet = null;
    for (int i = 0; i < allKeys.size(); i++)
    {
      final StyleKey key = (StyleKey) allKeys.get(i);
      final StyleKeyCarrier carrier = (StyleKeyCarrier) allElements.get(key);
      carrier.setStyleSheet(null);
    }

    this.styleSheet = styleSheet;
    if (this.styleSheet != null)
    {
      for (int i = 0; i < allKeys.size(); i++)
      {
        final StyleKey key = (StyleKey) allKeys.get(i);
        final StyleKeyCarrier carrier = (StyleKeyCarrier) allElements.get(key);
        carrier.setStyleSheet(styleSheet);
      }
      this.styleSheet.addListener(styleSheetChangeHandler);
    }
  }

  public final ChangeListener getChangeListener ()
  {
    return changeListener;
  }

  public final void setChangeListener (final ChangeListener changeListener)
  {
    this.changeListener = changeListener;
  }
}

⌨️ 快捷键说明

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