Package com.positive.charts.title

Source Code of com.positive.charts.title.LegendItemBlockContainer

/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
* USA. 
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -----------------------------
* LegendItemBlockContainer.java
* -----------------------------
* (C) Copyright 2006, 2007, by Object Refinery Limited.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* Changes
* -------
* 20-Jul-2006 : Version 1 (DG);
* 06-Oct-2006 : Added tooltip and URL text fields (DG);
* 18-May-2007 : Added seriesKey and dataset fields (DG);
*
*/

package com.positive.charts.title;

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

import com.positive.charts.block.Arrangement;
import com.positive.charts.block.BlockContainer;
import com.positive.charts.block.BlockResult;
import com.positive.charts.block.EntityBlockParams;
import com.positive.charts.block.EntityBlockResult;
import com.positive.charts.data.general.Dataset;
import com.positive.charts.entity.EntityCollection;
import com.positive.charts.entity.LegendItemEntity;
import com.positive.charts.entity.StandardEntityCollection;

/**
* A container that holds all the pieces of a single legend item.
*
* @since 1.0.2
*/
public class LegendItemBlockContainer extends BlockContainer {

  /**
   * The dataset.
   *
   * @since 1.0.6
   */
  private Dataset dataset;

  /**
   * The series key.
   *
   * @since 1.0.6
   */
  private Comparable seriesKey;

  /** The dataset index. */
  private int datasetIndex;

  /** The series index. */
  private int series;

  /** The tool tip text (can be <code>null</code>). */
  private String toolTipText;

  /** The URL text (can be <code>null</code>). */
  private String urlText;

  /**
   * Creates a new legend item block.
   *
   * @param arrangement
   *            the arrangement.
   * @param dataset
   *            the dataset.
   * @param seriesKey
   *            the series key.
   *
   * @since 1.0.6
   */
  public LegendItemBlockContainer(final Arrangement arrangement,
      final Dataset dataset, final Comparable seriesKey) {
    super(arrangement);
    this.dataset = dataset;
    this.seriesKey = seriesKey;
  }

  /**
   * Creates a new legend item block.
   *
   * @param arrangement
   *            the arrangement.
   * @param datasetIndex
   *            the dataset index.
   * @param series
   *            the series index.
   *
   * @deprecated As of 1.0.6, use the other constructor.
   */
  public LegendItemBlockContainer(final Arrangement arrangement,
      final int datasetIndex, final int series) {
    super(arrangement);
    this.datasetIndex = datasetIndex;
    this.series = series;
  }

  /**
   * Draws the block within the specified area.
   *
   * @param g2
   *            the graphics device.
   * @param area
   *            the area.
   * @param params
   *            passed on to blocks within the container (<code>null</code>
   *            permitted).
   *
   * @return An instance of {@link EntityBlockResult}, or <code>null</code>.
   */
  public Object draw(final GC g2, final Rectangle area, final Object params) {
    // draw the block without collecting entities
    super.draw(g2, area, null);
    EntityBlockParams ebp = null;
    final BlockResult r = new BlockResult();
    if (params instanceof EntityBlockParams) {
      ebp = (EntityBlockParams) params;
      if (ebp.getGenerateEntities()) {
        final EntityCollection ec = new StandardEntityCollection();
        final LegendItemEntity entity = new LegendItemEntity(
            new Rectangle(area.x, area.y, area.width, area.height));
        entity.setSeriesIndex(this.series);
        entity.setSeriesKey(this.seriesKey);
        entity.setDataset(this.dataset);
        entity.setToolTipText(this.getToolTipText());
        entity.setURLText(this.getURLText());
        ec.add(entity);
        r.setEntityCollection(ec);
      }
    }
    return r;
  }

  /**
   * Returns a reference to the dataset for the associated legend item.
   *
   * @return A dataset reference.
   *
   * @since 1.0.6
   */
  public Dataset getDataset() {
    return this.dataset;
  }

  /**
   * Returns the dataset index.
   *
   * @return The dataset index.
   *
   * @deprecated As of 1.0.6, use the {@link #getDataset()} method.
   */
  public int getDatasetIndex() {
    return this.datasetIndex;
  }

  /**
   * Returns the series index.
   *
   * @return The series index.
   */
  public int getSeriesIndex() {
    return this.series;
  }

  /**
   * Returns the series key.
   *
   * @return The series key.
   *
   * @since 1.0.6
   */
  public Comparable getSeriesKey() {
    return this.seriesKey;
  }

  /**
   * Returns the tool tip text.
   *
   * @return The tool tip text (possibly <code>null</code>).
   *
   * @since 1.0.3
   */
  public String getToolTipText() {
    return this.toolTipText;
  }

  /**
   * Returns the URL text.
   *
   * @return The URL text (possibly <code>null</code>).
   *
   * @since 1.0.3
   */
  public String getURLText() {
    return this.urlText;
  }

  /**
   * Sets the tool tip text.
   *
   * @param text
   *            the text (<code>null</code> permitted).
   *
   * @since 1.0.3
   */
  public void setToolTipText(final String text) {
    this.toolTipText = text;
  }

  /**
   * Sets the URL text.
   *
   * @param text
   *            the text (<code>null</code> permitted).
   *
   * @since 1.0.3
   */
  public void setURLText(final String text) {
    this.urlText = text;
  }
}
TOP

Related Classes of com.positive.charts.title.LegendItemBlockContainer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.