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

📄 element.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner;
 *
 * (C) Copyright 2000-2003, by Object Refinery 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.
 *
 * ------------
 * Element.java
 * ------------
 * (C)opyright 2000-2003, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   Thomas Morgner;
 *
 * $Id: Element.java,v 1.13 2003/11/07 18:33:47 taqua Exp $
 *
 * Changes (from 8-Feb-2002)
 * -------------------------
 * 08-Feb-2002 : Updated code to work with latest version of the JCommon class library (DG);
 * 05-Mar-2002 : Integration of Thomas Morgner's code, plus PDF report generation via iText (DG);
 * 10-May-2002 : Removed complex-Constructor to support automatic generation of elements using
 *               generic parsers.
 * 16-May-2002 : Line delimiters adjusted
 *               paint now protected member
 * 20-May-2002 : Support for DataTarget interface added. The drawing scheme has changed to fit
 *               the new OutputTarget implementation
 * 26-May-2002 : Elements visible property controls whether an element is drawn by its band
 * 04-Jun-2002 : Documentation tags changed. A default name is generated, a default datasource
 *               is set. Elements paint is no longer protected, the paint is retrieved by the
 *               getPaint (Band) method. If neither band nor element have a paint declared, fail
 *               with and exception.
 * 04-Jul-2002 : Serializable and Cloneable
 * 05-Sep-2002 : Documentation
 * 06-Dec-2002 : Updated Javadocs (DG);
 * 06-Dec-2002 : Also updated the docs, declared setPaint(),getPaint deprecated, removed
 *               setStyleSheet
 * 13-Dec-2002 : Added support for parent property
 * 22-Jan-2003 : Paint parameter is now restricted to java.awt.Color
 * 27-Jan-2003 : Changed ParentRegistration, now the band is responsible for setting the parent
 *               property and the BandDefaultStyleSheet.
 * 04-Feb-2003 : removed equals() method. Element equality is no longer bound to names.
 */

package org.jfree.report;

import java.awt.geom.Dimension2D;
import java.io.Serializable;

import org.jfree.report.filter.DataSource;
import org.jfree.report.filter.DataTarget;
import org.jfree.report.filter.EmptyDataSource;
import org.jfree.report.style.ElementDefaultStyleSheet;
import org.jfree.report.style.ElementStyleSheet;
import org.jfree.report.style.InvalidStyleSheetCollectionException;
import org.jfree.report.style.StyleSheetCollection;
import org.jfree.report.style.StyleSheetCollectionHelper;
import org.jfree.report.util.InstanceID;

/**
 * Base class for all report elements (display items that can appear within a report band).
 * <p>
 * All elements have a non-null name and have a style sheet defined. The style sheet is
 * used to store and access all element properties that can be used to layout the
 * element or affect the elements appeareance in a ReportProcessor.
 *
 * @author David Gilbert
 * @author Thomas Morgner
 */
public abstract class Element implements DataTarget, Serializable, Cloneable
{
  /** The internal constant to mark anonymous element names. */
  public static final String ANONYMOUS_ELEMENT_PREFIX = "anonymousElement@";

  /**
   * Internal helper class to handle the style sheet collection properly.
   */
  private static class ElementStyleSheetCollectionHelper extends StyleSheetCollectionHelper
  {
    /** The Element for which we handle the style sheet collection. */
    private Element element;

    /**
     * Creates a new ElementStyleSheetCollectionHelper for the given element.
     *
     * @param e the element.
     * @throws NullPointerException if the given element is null.
     */
    public ElementStyleSheetCollectionHelper(final Element e)
    {
      if (e == null)
      {
        throw new NullPointerException();
      }
      this.element = e;
    }

    /**
     * Handles the stylesheet collection registration.
     * Forwards the call to the element.
     */
    protected void handleRegisterStyleSheetCollection()
    {
      element.handleRegisterStyleSheetCollection();
    }

    /**
     * Handles the stylesheet collection removal.
     * Forwards the call to the element.
     */
    protected void handleUnregisterStyleSheetCollection()
    {
      element.handleUnregisterStyleSheetCollection();
    }
  }

  /** A null datasource. */
  private static final DataSource NULL_DATASOURCE = new EmptyDataSource();

  /** The head of the data source chain. */
  private DataSource datasource;

  /** The name of the element. */
  private String name;

  /** The stylesheet defines global appearance for elements. */
  private ElementStyleSheet style;

  /**
   * The stylesheet collection helper is used to manage the StyleSheetCollection of
   * this element. The use of the stylesheet collection is evil voodo, so we dont
   * handle it in the element ...
   */
  private ElementStyleSheetCollectionHelper styleSheetCollectionHelper;

  /** the parent for the element (the band where the element is contained in). */
  private Band parent;

  /** the tree lock to synchronize the element. */
  private final InstanceID treeLock;

  /**
   * Constructs an element.
   * <p>
   * The element inherits the DefaultElementStyleSheet. When the element is added
   * to the band, the bands default stylesheet is also added to the elements style.
   * <p>
   * A datasource is assigned with this element is set to a default source,
   * which always returns null.
   */
  protected Element()
  {
    treeLock = new InstanceID();
    setName(ANONYMOUS_ELEMENT_PREFIX + super.hashCode());
    datasource = NULL_DATASOURCE;
    style = new ElementStyleSheet(getName());
    style.setAllowCaching(true);
    style.addDefaultParent(ElementDefaultStyleSheet.getDefaultStyle());
    styleSheetCollectionHelper = new ElementStyleSheetCollectionHelper(this);
  }

  /**
   * Return the parent of the element.
   * You can use this to explore the component tree.
   *
   * @return the parent of the element.
   */
  public final Band getParent()
  {
    return parent;
  }

  /**
   * defines the parent of the element. Only a band should call this method.
   *
   * @param parent (null allowed).
   */
  protected final void setParent(final Band parent)
  {
    this.parent = parent;
  }

  /**
   * Defines the name for this element. The name must not be empty,
   * or a NullPointerException is thrown.
   *
   * @param name  the name of this element (null not permitted)
   */
  public void setName(final String name)
  {
    if (name == null)
    {
      throw new NullPointerException("Element.setName(...): name is null.");
    }
    this.name = name;
  }

  /**
   * Returns the name of the element. The name of the element cannot be null.
   *
   * @return the name.
   */
  public String getName()
  {
    return this.name;
  }

  /**
   * Returns the datasource for this element. You cannot override this function as the
   * element needs always be the last consumer in the chain of filters. This function
   * must never return null.
   *
   * @return the assigned datasource.
   */
  public final DataSource getDataSource()
  {
    return datasource;
  }

  /**
   * Sets the data source for this element. This datasource is queried on populateElements(),
   * to fill in the values.
   *
   * @param ds  the datasource (<code>null</code> not permitted).
   */
  public void setDataSource(final DataSource ds)
  {
    if (ds == null)
    {
      throw new NullPointerException("Element.setDataSource(...) : null data source.");
    }
    this.datasource = ds;
  }

  /**
   * Queries this element's datasource for a value.
   *
   * @return the value of the datasource, which can be null.
   */
  public Object getValue()
  {
    final DataSource ds = getDataSource();
    return ds.getValue();
  }

  /**
   * Defines whether this element should be painted. The detailed implementation is
   * up to the outputtarget.
   *
   * @return the current visiblity state.
   */
  public boolean isVisible()
  {
    final Boolean b = (Boolean) getStyle().getStyleProperty
        (ElementStyleSheet.VISIBLE, Boolean.FALSE);
    return b.booleanValue();
  }

  /**
   * Defines, whether this element should be drawn.
   *
   * @param b the new visibility state
   */
  public void setVisible(final boolean b)
  {
    getStyle().setStyleProperty(ElementStyleSheet.VISIBLE, b ? Boolean.TRUE : Boolean.FALSE);
  }

  /**
   * Clones this Element, the datasource and the private stylesheet of this element.
   * If this element was previously assigned with an stylesheet collection, then the
   * clone is no longer assiged with that collection. You will have to register the
   * element manually again.
   *

⌨️ 快捷键说明

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