/************************************************************************** /* This class is part of the Java Plotlib Toolkit. /* /* Copyright (c) 1999-2004 by Bernhard Bablok (bablokb@gmx.de) /* /* This program is free software; you can redistribute it and/or modify /* it under the terms of the GNU General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This program 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 Library General Public License for more details. /* /* You should have received a copy of the GNU General Public License /* along with this program; see the file COPYING. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ package de.bablokb.plotlib.core; import java.util.*; import java.awt.geom.*; /** Plottable object for a set of tickmarks and labels. Although this is a composite, we treat it as an AbstractPlottable to simplify construction. @version $Revision: 1.4 $ @author $Author: bablokb $ */ public class TickMarks extends AbstractPlottable { /** List of points of type Point2D. Note that this is not verified. */ private java.util.List iPoints = null; ///////////////////////////////////////////////////////////////////////////// /** List of labels. Normally, there a less labels than ticks and the labels are somewhat lined up with their corresponding tickmark. */ private PlotList iLabels = null; ///////////////////////////////////////////////////////////////////////////// /** Construct a TickMarks object with empty Symbols object and empty list. */ public TickMarks() { iPoints = new ArrayList(); iLabels = new PlotList(); } ///////////////////////////////////////////////////////////////////////////// /** Construct a TickMarks object from given points and list of labels. Note that the elements of the list should be objects of the PLabel class, but this is not verified. */ public TickMarks(java.util.List points, PlotList labels) { iPoints = points; iLabels = labels; } ///////////////////////////////////////////////////////////////////////////// /** Set the list of labels. Note that the elements of the list should be objects of the PLabel class, but this is not verified. */ public void setLabels(PlotList l) { iLabels = l; } ///////////////////////////////////////////////////////////////////////////// /** Add a PLabel to the list of labels. This is a convinience wrapper to the add()-method of PlotList. If no list exists, a list is created. */ public void addLabel(PLabel l) { if (iLabels == null) iLabels = new PlotList(); iLabels.add(l); } ///////////////////////////////////////////////////////////////////////////// /** Query the list of labels. */ public PlotList getLabels() { return iLabels; } ///////////////////////////////////////////////////////////////////////////// /** Set list of points. Note that the elements of the list should be objects of the Point2D class, but this is not verified. */ public void setPoints(java.util.List l) { iPoints = l; } ///////////////////////////////////////////////////////////////////////////// /** Add a point to the list of points. This is a convinience wrapper to the add()-method of the internal ArrayList. */ public void addPoint(Point2D p) { if (iPoints == null) iPoints = new ArrayList(); iPoints.add(p); } ///////////////////////////////////////////////////////////////////////////// /** Query list of points. */ public java.util.List getPoints() { return iPoints; } ///////////////////////////////////////////////////////////////////////////// /** Sets properties-object. */ public void setProperties(TickMarkProperties tprop) { iProperties = tprop; } ///////////////////////////////////////////////////////////////////////////// /** Generate points from given start, end, delta and x-or-y-value @param start: start-value of first dimension @param end: end-value of first dimension @param delta: delta-value of first dimension @param value: value for second dimension */ public void createTicks(double start,double end,double delta,double value) { TickMarkProperties prop = (TickMarkProperties) iProperties; int orientation = prop.getOrientation(); if (delta == 0) return; int count = 1 + (int) ((end-start)/delta); if (iPoints == null) iPoints = new ArrayList(count); else if (iPoints != null) iPoints.clear(); int i; double x, y; Toolkit kit = Toolkit.getDefaultToolkit(); if (orientation == Plotlib.HORIZONTAL) { for (x=start,i=0; i