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

📄 stylekeycarrier.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.
 *
 * ------------------------------
 * StyleKeyCarrier.java
 * ------------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: StyleKeyCarrier.java,v 1.2 2004/04/20 18:55:01 taqua Exp $
 *
 * Changes
 * -------------------------
 * 08.11.2003 : Initial version
 *
 */

package org.jfree.designer.visualeditor.elementeditor;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;

import org.jfree.report.style.ElementStyleSheet;
import org.jfree.report.style.StyleChangeListener;
import org.jfree.report.style.StyleKey;

public final class StyleKeyCarrier
        implements ItemListener, PropertyChangeListener, StyleChangeListener
{
  final private StyleKey key;
  final private JCheckBox enableTrigger;
  final private JLabel label;
  final private PropertyEditorContainer container;
  private ElementStyleSheet styleSheet;
  private boolean lock;

  public StyleKeyCarrier (final StyleKey key,
                          final PropertyEditorContainer container)
  {
    this.key = key;
    this.enableTrigger = new JCheckBox();
    this.enableTrigger.addItemListener(this);
    this.enableTrigger.setEnabled(false);
    this.label = new JLabel(key.getName());
    this.label.setEnabled(false);
    this.container = container;
    this.container.setEnabled(false);
    this.container.addPropertyChangeListener("value", this);
  }

  public final ElementStyleSheet getStyleSheet ()
  {
    return styleSheet;
  }

  public final synchronized void setStyleSheet (final ElementStyleSheet styleSheet)
  {
    if (this.styleSheet != null)
    {
      this.styleSheet.removeListener(this);
    }
    this.styleSheet = styleSheet;
    if (this.styleSheet != null)
    {
      try
      {
        lock = true;
        this.enableTrigger.setEnabled(true);
        this.container.setEnabled(styleSheet.isLocalKey(key));
        this.label.setEnabled(true);
        setValueDefined(styleSheet.isLocalKey(key));
        container.setValue(styleSheet.getStyleProperty(key));
        this.styleSheet.addListener(this);
      }
      finally
      {
        lock = false;
      }
    }
    else
    {
      setValueDefined(false);
      container.setValue(null);
      this.enableTrigger.setEnabled(false);
      this.container.setEnabled(false);
      this.label.setEnabled(false);
    }
  }

  public final JComponent getContainer ()
  {
    return container;
  }

  public final JComponent getEnableTrigger ()
  {
    return enableTrigger;
  }

  public final JLabel getLabel ()
  {
    return label;
  }

  public final void itemStateChanged (final ItemEvent e)
  {
    this.container.setEnabled(enableTrigger.isSelected());
    if ((styleSheet != null) && (lock == false))
    {
      if (enableTrigger.isSelected() == false)
      {
        styleSheet.setStyleProperty(getKey(), null);
      }
      else
      {
        styleSheet.setStyleProperty(getKey(), container.getValue());
      }
    }
  }

  /**
   * This method gets called when a bound property is changed.
   *
   * @param evt A PropertyChangeEvent object describing the event source and the property
   *            that has changed.
   */
  public final void propertyChange (final PropertyChangeEvent evt)
  {
    if (styleSheet == null)
    {
      return;
    }
    if (styleSheet.isGlobalDefault())
    {
      return;
    }
    if (isValueDefined())
    {
      styleSheet.setStyleProperty(getKey(), container.getValue());
    }
    else
    {
      styleSheet.setStyleProperty(getKey(), null);
    }
  }

  public final StyleKey getKey ()
  {
    return key;
  }

  private boolean isValueDefined ()
  {
    return enableTrigger.isSelected();
  }

  private void setValueDefined (final boolean enabled)
  {
    this.enableTrigger.setSelected(enabled);
  }

  /**
   * 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 synchronized void styleChanged
          (final ElementStyleSheet source, final StyleKey key, final Object value)
  {
    if (lock == true)
    {
      return;
    }
    if (source != styleSheet)
    {
      return;
    }
    if (key != getKey())
    {
      return;
    }
    lock = true;

    enableTrigger.setSelected(styleSheet.isLocalKey(key));
    // Log.warn ("StyleChanged:" + key + " -> " +value);
    try
    {
      container.setValue(value);
    }
    catch (IllegalArgumentException iae)
    {
      // ignored ...
    }
    finally
    {
      lock = false;
    }
  }


  /**
   * Receives notification that a style has been removed.
   *
   * @param source the source of the change.
   * @param key    the style key.
   */
  public final synchronized void styleRemoved (final ElementStyleSheet source,
                                         final StyleKey key)
  {
    if (lock == true)
    {
      return;
    }
    if (source != styleSheet)
    {
      return;
    }
    if (key != getKey())
    {
      return;
    }
    // Log.debug ("StyleRemoved: " + key);
    lock = true;
    try
    {
      // the style was removed, but a default value may exist...
      container.setValue(styleSheet.getStyleProperty(key));
    }
    catch (IllegalArgumentException iae)
    {
      // ignored ...
    }
    finally
    {
      lock = false;
    }
  }
}

⌨️ 快捷键说明

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