Package com.positive.charts.plot

Source Code of com.positive.charts.plot.CategoryMarker

/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2006, 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.]
*
* -------------------
* CategoryMarker.java
* -------------------
* (C) Copyright 2005, 2006, by Object Refinery Limited.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   Nicolas Brodu;
*
* $Id: CategoryMarker.java,v 1.1 2007/08/24 12:43:41 slapukhov Exp $
*
* Changes
* -------
* 20-May-2005 : Version 1 (DG);
* 19-Aug-2005 : Implemented equals(), fixed bug in constructor (DG);
* ------------- JFREECHART 1.0.x ---------------------------------------------
* 05-Sep-2006 : Added MarkerChangeListener support (DG);
*
*/

package com.positive.charts.plot;

import java.io.Serializable;

import org.eclipse.swt.graphics.Color;

import com.positive.charts.event.MarkerChangeEvent;
import com.positive.charts.util.LengthAdjustmentType;
import com.positive.charts.util.Stroke;

/**
* A marker for a category. <br>
* <br>
* Note that for serialization to work correctly, the category key must be an
* instance of a serializable class.
*
* @see CategoryPlot#addDomainMarker(CategoryMarker)
*/
public class CategoryMarker extends Marker implements Cloneable, Serializable {

  /** The category key. */
  private Comparable key;

  /**
   * A hint that the marker should be drawn as a line rather than a region.
   */
  private boolean drawAsLine = false;

  /**
   * Creates a new category marker.
   *
   * @param key
   *            the key.
   * @param paint
   *            the paint (<code>null</code> not permitted).
   * @param stroke
   *            the stroke (<code>null</code> not permitted).
   * @param outlinePaint
   *            the outline paint (<code>null</code> permitted).
   * @param outlineStroke
   *            the outline stroke (<code>null</code> permitted).
   * @param alpha
   *            the alpha transparency.
   */
  public CategoryMarker(final Comparable key, final Color paint,
      final Stroke stroke, final Color outlinePaint,
      final Stroke outlineStroke, final int alpha) {
    super(paint, stroke, outlinePaint, outlineStroke, alpha);
    this.key = key;
    this.setLabelOffsetType(LengthAdjustmentType.EXPAND);
  }

  /**
   * Tests the marker for equality with an arbitrary object.
   *
   * @param obj
   *            the object (<code>null</code> permitted).
   *
   * @return A boolean.
   */
  public boolean equals(final Object obj) {
    if (obj == null) {
      return false;
    }
    if (!(obj instanceof CategoryMarker)) {
      return false;
    }
    if (!super.equals(obj)) {
      return false;
    }
    final CategoryMarker that = (CategoryMarker) obj;
    if (!this.key.equals(that.key)) {
      return false;
    }
    if (this.drawAsLine != that.drawAsLine) {
      return false;
    }
    return true;
  }

  /**
   * Returns the flag that controls whether the marker is drawn as a region or
   * a line.
   *
   * @return A line.
   */
  public boolean getDrawAsLine() {
    return this.drawAsLine;
  }

  /**
   * Returns the key.
   *
   * @return The key.
   */
  public Comparable getKey() {
    return this.key;
  }

  /**
   * Sets the flag that controls whether the marker is drawn as a region or as
   * a line, and sends a {@link MarkerChangeEvent} to all registered
   * listeners.
   *
   * @param drawAsLine
   *            the flag.
   */
  public void setDrawAsLine(final boolean drawAsLine) {
    this.drawAsLine = drawAsLine;
    this.notifyListeners(new MarkerChangeEvent(this));
  }

  /**
   * Sets the key and sends a {@link MarkerChangeEvent} to all registered
   * listeners.
   *
   * @param key
   *            the key (<code>null</code> not permitted).
   *
   * @since 1.0.3
   */
  public void setKey(final Comparable key) {
    if (key == null) {
      throw new IllegalArgumentException("Null 'key' argument.");
    }
    this.key = key;
    this.notifyListeners(new MarkerChangeEvent(this));
  }

}
TOP

Related Classes of com.positive.charts.plot.CategoryMarker

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.