Package com.positive.charts.renderer.xy

Source Code of com.positive.charts.renderer.xy.XYLineAndShapeRenderer$State

package com.positive.charts.renderer.xy;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

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

import com.positive.charts.axis.ValueAxis;
import com.positive.charts.common.RectangleEdge;
import com.positive.charts.data.xy.XYDataItem;
import com.positive.charts.data.xy.XYDataset;
import com.positive.charts.entity.EntityCollection;
import com.positive.charts.event.RendererChangeEvent;
import com.positive.charts.plot.CrosshairState;
import com.positive.charts.plot.PlotOrientation;
import com.positive.charts.plot.PlotRenderingInfo;
import com.positive.charts.plot.xy.XYPlot;
import com.positive.charts.util.Stroke;

/**
* A renderer that can be used with the {@link XYPlot} class.
*/
/**
* @author slapukhov
*
*/
/**
* @author slapukhov
*
*/
public class XYLineAndShapeRenderer extends AbstractXYItemRenderer implements
    XYItemRenderer {

  /**
   * Records the state for the renderer. This is used to preserve state
   * information between calls to the drawItem() method for a single chart
   * drawing.
   */
  public static class State extends XYItemRendererState {

    /** The path for the current series. */
    public Path seriesPath;

    /**
     * A flag that indicates if the last (x, y) point was 'good' (non-null).
     */
    private boolean lastPointGood;

    /**
     * Creates a new state instance.
     *
     * @param info
     *            the plot rendering info.
     */
    public State(final PlotRenderingInfo info) {
      super(info);
    }

    /**
     * Returns a flag that indicates if the last point drawn (in the current
     * series) was 'good' (non-null).
     *
     * @return A boolean.
     */
    public boolean isLastPointGood() {
      return this.lastPointGood;
    }

    /**
     * Sets a flag that indicates if the last point drawn (in the current
     * series) was 'good' (non-null).
     *
     * @param good
     *            the flag.
     */
    public void setLastPointGood(final boolean good) {
      this.lastPointGood = good;
    }
  }

  /**
   * Returns <code>true</code> if the specified point (x, y) falls within or
   * on the boundary of the specified rectangle.
   *
   * @param rect
   *            the rectangle (<code>null</code> not permitted).
   * @param x
   *            the x-coordinate.
   * @param y
   *            the y-coordinate.
   *
   * @return A boolean.
   *
   * @since 1.0.10
   */
  public static boolean isPointInRect(final Rectangle rect, final double x,
      final double y) {
    // TODO: For JFreeChart 1.2.0, this method should go in the
    // ShapeUtilities class
    return rect.contains((int) x, (int) y);
  }

  /** A flag that controls whether or not lines are visible for ALL series. */
  private Boolean linesVisible;

  /**
   * A table of flags that control (per series) whether or not lines are
   * visible.
   */
  private final List seriesLinesVisible;

  /** The default value returned by the getLinesVisible() method. */
  private boolean baseLinesVisible;

  /**
   * A flag that controls whether or not shapes are visible for ALL series.
   */
  private Boolean shapesVisible = Boolean.TRUE;

  /**
   * A table of flags that control (per series) whether or not shapes are
   * visible.
   */
  private final List seriesShapesVisible;

  /** The default value returned by the getShapeVisible() method. */
  private boolean baseShapesVisible;

  /** A flag that controls whether or not shapes are filled for ALL series. */
  private Boolean shapesFilled = Boolean.TRUE;

  /**
   * A table of flags that control (per series) whether or not shapes are
   * filled.
   */
  private final List seriesShapesFilled;

  /** The default value returned by the getShapeFilled() method. */
  private boolean baseShapesFilled;

  /** A flag that controls whether outlines are drawn for shapes. */
  private boolean drawOutlines;

  /**
   * A flag that controls whether the fill paint is used for filling shapes.
   */
  private boolean useFillPaint;

  /**
   * A flag that controls whether the outline paint is used for drawing shape
   * outlines.
   */
  private boolean useOutlinePaint;

  /**
   * A flag that controls whether or not each series is drawn as a single
   * path.
   */
  private boolean drawSeriesLineAsPath;

  /**
   * Creates a new renderer with both lines and shapes visible.
   */
  public XYLineAndShapeRenderer() {
    this(true, true);
  }

  /**
   * Creates a new renderer.
   *
   * @param lines
   *            lines visible?
   * @param shapes
   *            shapes visible?
   */
  public XYLineAndShapeRenderer(final boolean lines, final boolean shapes) {
    this.linesVisible = null;
    this.seriesLinesVisible = new ArrayList();
    this.baseLinesVisible = lines;

    this.shapesVisible = Boolean.TRUE;
    this.seriesShapesVisible = new ArrayList();
    this.baseShapesVisible = shapes;

    this.shapesFilled = Boolean.TRUE;
    this.useFillPaint = false; // use item paint for fills by default
    this.seriesShapesFilled = new ArrayList();
    this.baseShapesFilled = true;

    this.drawOutlines = true;
    this.useOutlinePaint = false; // use item paint for outlines by
    // default, not outline paint

    this.drawSeriesLineAsPath = true;
  }

  /**
   * Draws the first pass shape.
   *
   * @param gc
   *            the graphics device.
   * @param series
   *            the series index.
   * @param item
   *            the item index.
   * @param shape
   *            the shape.
   */
  protected void drawFirstPassShape(final GC gc, final int series,
      final int item, final Path shape) {
    final Color color = this.getItemColor(series, item);
    if (color != null) {
      gc.setForeground(color);
    }

    final Stroke stroke = this.getItemStroke(series, item);
    if (stroke != null) {
      stroke.set(gc);
    }

    // gc.setAntialias(SWT.ON);
    // gc.setAlpha(200);
    gc.drawPath(shape);
    // gc.setAlpha(255);
    // gc.setAntialias(SWT.OFF);
  }

  /**
   * Draws the visual representation of a single data item.
   *
   * @param gc
   *            the graphics device.
   * @param state
   *            the renderer state.
   * @param dataArea
   *            the area within which the data is being drawn.
   * @param info
   *            collects information about the drawing.
   * @param plot
   *            the plot (can be used to obtain standard color information
   *            etc).
   * @param domainAxis
   *            the domain axis.
   * @param rangeAxis
   *            the range axis.
   * @param dataset
   *            the dataset.
   * @param series
   *            the series index (zero-based).
   * @param item
   *            the item index (zero-based).
   * @param crosshairState
   *            crosshair information for the plot (<code>null</code>
   *            permitted).
   * @param pass
   *            the pass index.
   */
  public void drawItem(final GC gc, final XYItemRendererState state,
      final Rectangle dataArea, final PlotRenderingInfo info,
      final XYPlot plot, final ValueAxis domainAxis,
      final ValueAxis rangeAxis, final XYDataset dataset,
      final int series, final int item,
      final CrosshairState crosshairState, final int pass) {

    // do nothing if item is not visible
    if (!this.getItemVisible(series, item)) {
      return;
    }

    // first pass draws the background (lines, for instance)
    if (this.isLinePass(pass)) {
      if (item == 0) {
        if (this.drawSeriesLineAsPath) {
          final State s = (State) state;
          s.lastPointGood = false;
          s.seriesPath = new Path(gc.getDevice());
        }
      }

      if (this.getItemLineVisible(series, item)) {
        this.drawPrimaryLineAsPath(state, gc, plot, dataset, pass,
            series, item, domainAxis, rangeAxis, dataArea);
      }
    }
    // TODO Draw shapes and labels
    // second pass adds shapes where the items are ..
    else if (this.isItemPass(pass)) {

      // setup for collecting optional entity info...
      EntityCollection entities = null;
      if (info != null) {
        entities = info.getOwner().getEntityCollection();
      }

      this.drawSecondaryPass(gc, plot, dataset, pass, series, item,
          domainAxis, dataArea, rangeAxis, crosshairState, entities);
    }
  }

  /**
   * Draws the item (first pass). This method draws the lines connecting the
   * items. Instead of drawing separate lines, a GeneralPath is constructed
   * and drawn at the end of the series painting.
   *
   * @param gc
   *            the graphics device.
   * @param state
   *            the renderer state.
   * @param plot
   *            the plot (can be used to obtain standard color information
   *            etc).
   * @param dataset
   *            the dataset.
   * @param pass
   *            the pass.
   * @param series
   *            the series index (zero-based).
   * @param item
   *            the item index (zero-based).
   * @param domainAxis
   *            the domain axis.
   * @param rangeAxis
   *            the range axis.
   * @param dataArea
   *            the area within which the data is being drawn.
   */
  protected void drawPrimaryLineAsPath(final XYItemRendererState state,
      final GC gc, final XYPlot plot, final XYDataset dataset,
      final int pass, final int series, final int item,
      final ValueAxis domainAxis, final ValueAxis rangeAxis,
      final Rectangle dataArea) {

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    final double transX1 = domainAxis.valueToJava2D(x1, dataArea,
        xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
        yAxisLocation);

    final State s = (State) state;
    // update path to reflect latest point
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
      float x = (float) transX1;
      float y = (float) transY1;
      final PlotOrientation orientation = plot.getOrientation();
      if (orientation == PlotOrientation.HORIZONTAL) {
        x = (float) transY1;
        y = (float) transX1;
      }
      if (s.isLastPointGood()) {
        s.seriesPath.lineTo(x, y);
      } else {
        s.seriesPath.moveTo(x, y);
      }
      s.setLastPointGood(true);
    } else {
      s.setLastPointGood(false);
    }
    // if this is the last item, draw the path ...
    if (item == dataset.getItemCount(series) - 1) {
      // draw path
      this.drawFirstPassShape(gc, series, item, s.seriesPath);
      s.seriesPath.dispose();
    }
  }

  /**
   * Draws the item shapes and adds chart entities (second pass). This method
   * draws the shapes which mark the item positions. If <code>entities</code>
   * is not <code>null</code> it will be populated with entity information for
   * points that fall within the data area.
   *
   * @param g2
   *            the graphics device.
   * @param plot
   *            the plot (can be used to obtain standard color information
   *            etc).
   * @param domainAxis
   *            the domain axis.
   * @param dataArea
   *            the area within which the data is being drawn.
   * @param rangeAxis
   *            the range axis.
   * @param dataset
   *            the dataset.
   * @param pass
   *            the pass.
   * @param series
   *            the series index (zero-based).
   * @param item
   *            the item index (zero-based).
   * @param crosshairState
   *            the crosshair state.
   * @param entities
   *            the entity collection.
   */
  protected void drawSecondaryPass(final GC gr, final XYPlot plot,
      final XYDataset dataset, final int pass, final int series,
      final int item, final ValueAxis domainAxis,
      final Rectangle dataArea, final ValueAxis rangeAxis,
      final CrosshairState crosshairState, final EntityCollection entities) {

    Rectangle entityArea = null;

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
      return;
    }

    final PlotOrientation orientation = plot.getOrientation();
    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transX1 = domainAxis.valueToJava2D(x1, dataArea,
        xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
        yAxisLocation);

    if (this.getItemShapeVisible(series, item)) {
      Rectangle shape = this.getItemShape(series, item);
      if (orientation == PlotOrientation.HORIZONTAL) {
        shape = new Rectangle((int) (shape.x + transY1),
            (int) (shape.y + transX1), shape.width, shape.height);
      } else if (orientation == PlotOrientation.VERTICAL) {
        shape = new Rectangle((int) (shape.x + transX1),
            (int) (shape.y + transY1), shape.width, shape.height);
      }
      entityArea = shape;
      if (shape.intersects(dataArea)) {
        if (this.getItemShapeFilled(series, item)) {
          if (this.useFillPaint) {
            gr.setBackground(this.getItemFillPaint(series, item));
          } else {
            gr.setBackground(this.getItemPaint(series, item));
          }
          gr.fillRectangle(shape);
        }
        if (this.drawOutlines) {
          if (this.getUseOutlinePaint()) {
            gr
                .setForeground(this.getItemOutlinePaint(series,
                    item));
          } else {
            gr.setForeground(this.getItemPaint(series, item));
          }
          final Stroke itemOutlineStroke = this.getItemOutlineStroke(
              series, item);
          itemOutlineStroke.set(gr);
          gr.drawRectangle(shape);
        }
      }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
      xx = transY1;
      yy = transX1;
    }

    // draw the item label if there is one...
    if (this.isItemLabelVisible(series, item)) {
      this.drawItemLabel(gr, orientation, dataset, series, item, xx, yy,
          (y1 < 0.0));
    }

    final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    this.updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
        rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if ((entities != null) && isPointInRect(dataArea, xx, yy)) {
      this.addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
  }

  // LINES VISIBLE

  public void drawSeriesItems(final GC gc, final Rectangle dataArea,
      final PlotRenderingInfo info, final XYPlot plot,
      final ValueAxis domainAxis, final ValueAxis rangeAxis,
      final XYDataset dataset, final int seriesIndex, final List items) {

    if (!this.isSeriesVisible(seriesIndex)) {
      return;
    }

    final State s = (State) this.initialise(gc, dataArea, plot, dataset,
        info);

    s.seriesPath = new Path(gc.getDevice());

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    for (final Iterator iter = items.iterator(); iter.hasNext();) {
      final XYDataItem item = (XYDataItem) iter.next();
      // get the data point...
      final double x1 = item.getX().doubleValue();
      final Number yValue = item.getY();
      if (yValue == null) {
        s.setLastPointGood(false);
        continue;
      }
      final double y1 = item.getY().doubleValue();
      final double transX1 = domainAxis.valueToJava2D(x1, dataArea,
          xAxisLocation);
      final double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
          yAxisLocation);

      // update path to reflect latest point
      if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        float x = (float) transX1;
        float y = (float) transY1;
        final PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
          x = (float) transY1;
          y = (float) transX1;
        }
        if (s.isLastPointGood()) {
          s.seriesPath.lineTo(x, y);
        } else {
          s.seriesPath.moveTo(x, y);
        }
        s.setLastPointGood(true);
      } else {
        s.setLastPointGood(false);
      }
    }

    // draw path
    this.drawFirstPassShape(gc, seriesIndex, 0, s.seriesPath);
    s.seriesPath.dispose();
  }

  /**
   * Returns the base 'lines visible' attribute.
   *
   * @return The base flag.
   */
  public boolean getBaseLinesVisible() {
    return this.baseLinesVisible;
  }

  /**
   * Returns the base 'shape filled' attribute.
   *
   * @return The base flag.
   */
  public boolean getBaseShapesFilled() {
    return this.baseShapesFilled;
  }

  /**
   * Returns the base 'shape visible' attribute.
   *
   * @return The base flag.
   */
  public boolean getBaseShapesVisible() {
    return this.baseShapesVisible;
  }

  /**
   * Returns <code>true</code> if outlines should be drawn for shapes, and
   * <code>false</code> otherwise.
   *
   * @return A boolean.
   */
  public boolean getDrawOutlines() {
    return this.drawOutlines;
  }

  /**
   * Returns a flag that controls whether or not each series is drawn as a
   * single path.
   *
   * @return A boolean.
   *
   * @see #setDrawSeriesLineAsPath(boolean)
   */
  public boolean getDrawSeriesLineAsPath() {
    return this.drawSeriesLineAsPath;
  }

  /**
   * Returns the flag used to control whether or not the shape for an item is
   * visible.
   *
   * @param series
   *            the series index (zero-based).
   * @param item
   *            the item index (zero-based).
   *
   * @return A boolean.
   */
  public boolean getItemLineVisible(final int series, final int item) {
    Boolean flag = this.linesVisible;
    if (flag == null) {
      flag = this.getSeriesLinesVisible(series);
    }
    if (flag != null) {
      return flag.booleanValue();
    } else {
      return this.baseLinesVisible;
    }
  }

  /**
   * Returns the flag used to control whether or not the shape for an item is
   * filled.
   * <p>
   * The default implementation passes control to the
   * <code>getSeriesShapesFilled</code> method. You can override this method
   * if you require different behaviour.
   *
   * @param series
   *            the series index (zero-based).
   * @param item
   *            the item index (zero-based).
   *
   * @return A boolean.
   */
  public boolean getItemShapeFilled(final int series, final int item) {
    Boolean flag = this.shapesFilled;
    if (flag == null) {
      flag = this.getSeriesShapesFilled(series);
    }
    if (flag != null) {
      return flag.booleanValue();
    } else {
      return this.baseShapesFilled;
    }
  }

  /**
   * Returns the flag used to control whether or not the shape for an item is
   * visible.
   * <p>
   * The default implementation passes control to the
   * <code>getSeriesShapesVisible</code> method. You can override this method
   * if you require different behaviour.
   *
   * @param series
   *            the series index (zero-based).
   * @param item
   *            the item index (zero-based).
   *
   * @return A boolean.
   */
  public boolean getItemShapeVisible(final int series, final int item) {
    Boolean flag = this.shapesVisible;
    if (flag == null) {
      flag = this.getSeriesShapesVisible(series);
    }
    if (flag != null) {
      return flag.booleanValue();
    } else {
      return this.baseShapesVisible;
    }
  }

  // SHAPES VISIBLE

  /**
   * Returns a flag that controls whether or not lines are drawn for ALL
   * series. If this flag is <code>null</code>, then the "per series" settings
   * will apply.
   *
   * @return A flag (possibly <code>null</code>).
   */
  public Boolean getLinesVisible() {
    return this.linesVisible;
  }

  /**
   * Returns the number of passes through the data that the renderer requires
   * in order to draw the chart. Most charts will require a single pass, but
   * some require two passes.
   *
   * @return The pass count.
   */
  public int getPassCount() {
    return 2; // XXX Pass count was 2
  }

  /**
   * Returns the flag used to control whether or not the lines for a series
   * are visible.
   *
   * @param series
   *            the series index (zero-based).
   *
   * @return The flag (possibly <code>null</code>).
   */
  public Boolean getSeriesLinesVisible(final int series) {
    try {
      return (Boolean) this.seriesLinesVisible.get(series);
    } catch (final IndexOutOfBoundsException e) {
      return null;
    }
  }

  /**
   * Returns the flag used to control whether or not the shapes for a series
   * are filled.
   *
   * @param series
   *            the series index (zero-based).
   *
   * @return A boolean.
   */
  public Boolean getSeriesShapesFilled(final int series) {
    return (Boolean) this.seriesShapesFilled.get(series);
  }

  /**
   * Returns the flag used to control whether or not the shapes for a series
   * are visible.
   *
   * @param series
   *            the series index (zero-based).
   *
   * @return A boolean.
   */
  public Boolean getSeriesShapesVisible(final int series) {
    return (Boolean) this.seriesShapesVisible.get(series);
  }

  /**
   * Returns the flag that controls whether the shapes are visible for the
   * items in ALL series.
   *
   * @return The flag (possibly <code>null</code>).
   */
  public Boolean getShapesVisible() {
    return this.shapesVisible;
  }

  /**
   * Returns <code>true</code> if the renderer should use the fill paint
   * setting to fill shapes, and <code>false</code> if it should just use the
   * regular paint.
   *
   * @return A boolean.
   */
  public boolean getUseFillPaint() {
    return this.useFillPaint;
  }

  /**
   * Returns <code>true</code> if the renderer should use the outline paint
   * setting to draw shape outlines, and <code>false</code> if it should just
   * use the regular paint.
   *
   * @return A boolean.
   */
  public boolean getUseOutlinePaint() {
    return this.useOutlinePaint;
  }

  /**
   * Initialises the renderer.
   * <P>
   * This method will be called before the first item is rendered, giving the
   * renderer an opportunity to initialise any state information it wants to
   * maintain. The renderer can do nothing if it chooses.
   *
   * @param gc
   *            the graphics device.
   * @param dataArea
   *            the area inside the axes.
   * @param plot
   *            the plot.
   * @param data
   *            the data.
   * @param info
   *            an optional info collection object to return data back to the
   *            caller.
   *
   * @return The renderer state.
   */
  public XYItemRendererState initialise(final GC gc,
      final Rectangle dataArea, final XYPlot plot, final XYDataset data,
      final PlotRenderingInfo info) {

    final State state = new State(info);
    return state;
  }

  // SHAPES FILLED

  /**
   * Returns <code>true</code> if the specified pass is the one for drawing
   * items.
   *
   * @param pass
   *            the pass.
   *
   * @return A boolean.
   */
  protected boolean isItemPass(final int pass) {
    return pass == 1;
  }

  /**
   * Returns <code>true</code> if the specified pass is the one for drawing
   * lines.
   *
   * @param pass
   *            the pass.
   *
   * @return A boolean.
   */
  protected boolean isLinePass(final int pass) {
    return pass == 0;
  }

  /**
   * Sets the base 'lines visible' flag.
   *
   * @param flag
   *            the flag.
   */
  public void setBaseLinesVisible(final boolean flag) {
    this.baseLinesVisible = flag;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the base 'shapes filled' flag.
   *
   * @param flag
   *            the flag.
   */
  public void setBaseShapesFilled(final boolean flag) {
    this.baseShapesFilled = flag;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the base 'shapes visible' flag.
   *
   * @param flag
   *            the flag.
   */
  public void setBaseShapesVisible(final boolean flag) {
    this.baseShapesVisible = flag;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the flag that controls whether outlines are drawn for shapes, and
   * sends a {@link RendererChangeEvent} to all registered listeners.
   * <P>
   * In some cases, shapes look better if they do NOT have an outline, but
   * this flag allows you to set your own preference.
   *
   * @param flag
   *            the flag.
   */
  public void setDrawOutlines(final boolean flag) {
    this.drawOutlines = flag;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the flag that controls whether or not each series is drawn as a
   * single path.
   *
   * @param flag
   *            the flag.
   *
   * @see #getDrawSeriesLineAsPath()
   */
  public void setDrawSeriesLineAsPath(final boolean flag) {
    if (this.drawSeriesLineAsPath != flag) {
      this.drawSeriesLineAsPath = flag;
      this.notifyListeners(new RendererChangeEvent(this));
    }
  }

  /**
   * Sets a flag that controls whether or not lines are drawn between the
   * items in ALL series, and sends a {@link RendererChangeEvent} to all
   * registered listeners.
   *
   * @param visible
   *            the flag.
   */
  public void setLinesVisible(final boolean visible) {
    this.setLinesVisible(Boolean.valueOf(visible));
  }

  /**
   * Sets a flag that controls whether or not lines are drawn between the
   * items in ALL series, and sends a {@link RendererChangeEvent} to all
   * registered listeners. You need to set this to <code>null</code> if you
   * want the "per series" settings to apply.
   *
   * @param visible
   *            the flag (<code>null</code> permitted).
   */
  public void setLinesVisible(final Boolean visible) {
    this.linesVisible = visible;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the 'lines visible' flag for a series.
   *
   * @param series
   *            the series index (zero-based).
   * @param visible
   *            the flag.
   */
  public void setSeriesLinesVisible(final int series, final boolean visible) {
    this.setSeriesLinesVisible(series, Boolean.valueOf(visible));
  }

  /**
   * Sets the 'lines visible' flag for a series.
   *
   * @param series
   *            the series index (zero-based).
   * @param flag
   *            the flag (<code>null</code> permitted).
   */
  public void setSeriesLinesVisible(final int series, final Boolean flag) {
    this.seriesLinesVisible.set(series, flag);
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the 'shapes filled' flag for a series.
   *
   * @param series
   *            the series index (zero-based).
   * @param flag
   *            the flag.
   */
  public void setSeriesShapesFilled(final int series, final boolean flag) {
    this.setSeriesShapesFilled(series, Boolean.valueOf(flag));
  }

  /**
   * Sets the 'shapes filled' flag for a series.
   *
   * @param series
   *            the series index (zero-based).
   * @param flag
   *            the flag.
   */
  public void setSeriesShapesFilled(final int series, final Boolean flag) {
    this.seriesShapesFilled.set(series, flag);
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the 'shapes visible' flag for a series and sends a
   * {@link RendererChangeEvent} to all registered listeners.
   *
   * @param series
   *            the series index (zero-based).
   * @param visible
   *            the flag.
   */
  public void setSeriesShapesVisible(final int series, final boolean visible) {
    this.setSeriesShapesVisible(series, Boolean.valueOf(visible));
  }

  /**
   * Sets the 'shapes visible' flag for a series and sends a
   * {@link RendererChangeEvent} to all registered listeners.
   *
   * @param series
   *            the series index (zero-based).
   * @param flag
   *            the flag.
   */
  public void setSeriesShapesVisible(final int series, final Boolean flag) {
    this.seriesShapesVisible.set(series, flag);
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the 'shapes filled' for ALL series and sends a
   * {@link RendererChangeEvent} to all registered listeners.
   *
   * @param filled
   *            the flag.
   */
  public void setShapesFilled(final boolean filled) {
    this.setShapesFilled(Boolean.valueOf(filled));
  }

  /**
   * Sets the 'shapes filled' for ALL series and sends a
   * {@link RendererChangeEvent} to all registered listeners.
   *
   * @param filled
   *            the flag (<code>null</code> permitted).
   */
  public void setShapesFilled(final Boolean filled) {
    this.shapesFilled = filled;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the 'shapes visible' for ALL series and sends a
   * {@link RendererChangeEvent} to all registered listeners.
   *
   * @param visible
   *            the flag.
   */
  public void setShapesVisible(final boolean visible) {
    this.setShapesVisible(Boolean.valueOf(visible));
  }

  /**
   * Sets the 'shapes visible' for ALL series and sends a
   * {@link RendererChangeEvent} to all registered listeners.
   *
   * @param visible
   *            the flag (<code>null</code> permitted).
   */
  public void setShapesVisible(final Boolean visible) {
    this.shapesVisible = visible;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the flag that controls whether the fill paint is used to fill
   * shapes, and sends a {@link RendererChangeEvent} to all registered
   * listeners.
   *
   * @param flag
   *            the flag.
   */
  public void setUseFillPaint(final boolean flag) {
    this.useFillPaint = flag;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Sets the flag that controls whether the outline paint is used to draw
   * shape outlines, and sends a {@link RendererChangeEvent} to all registered
   * listeners.
   *
   * @param flag
   *            the flag.
   */
  public void setUseOutlinePaint(final boolean flag) {
    this.useOutlinePaint = flag;
    this.notifyListeners(new RendererChangeEvent(this));
  }

  /**
   * Considers the current (x, y) coordinate and updates the crosshair point
   * if it meets the criteria (usually means the (x, y) coordinate is the
   * closest to the anchor point so far).
   *
   * @param crosshairState
   *            the crosshair state (<code>null</code> permitted, but the
   *            method does nothing in that case).
   * @param x
   *            the x-value (in data space).
   * @param y
   *            the y-value (in data space).
   * @param domainAxisIndex
   *            the index of the domain axis for the point.
   * @param rangeAxisIndex
   *            the index of the range axis for the point.
   * @param transX
   *            the x-value translated to Java2D space.
   * @param transY
   *            the y-value translated to Java2D space.
   * @param orientation
   *            the plot orientation (<code>null</code> not permitted).
   *
   * @since 1.0.4
   */
  protected void updateCrosshairValues(final CrosshairState crosshairState,
      final double x, final double y, final int domainAxisIndex,
      final int rangeAxisIndex, final double transX, final double transY,
      final PlotOrientation orientation) {

    if (orientation == null) {
      throw new IllegalArgumentException("Null 'orientation' argument.");
    }

    if (crosshairState != null) {
      // do we need to update the crosshair values?
      if (this.plot.isDomainCrosshairLockedOnData()) {
        if (this.plot.isRangeCrosshairLockedOnData()) {
          // both axes
          crosshairState.updateCrosshairPoint(x, y, domainAxisIndex,
              rangeAxisIndex, transX, transY, orientation);
        } else {
          // just the domain axis...
          crosshairState.updateCrosshairX(x, domainAxisIndex);
        }
      } else {
        if (this.plot.isRangeCrosshairLockedOnData()) {
          // just the range axis...
          crosshairState.updateCrosshairY(y, rangeAxisIndex);
        }
      }
    }

  }

}
TOP

Related Classes of com.positive.charts.renderer.xy.XYLineAndShapeRenderer$State

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.