/************************************************************************** /* 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.awt.*; import java.awt.geom.*; /** Low-level axis class. This is a line with additional decorators, like a label or tickmarks. Although this is a composite, we treat it as an AbstractPlottable to simplify construction. All elements share the same basic-properties (e.g. color).

The current implementation has no intelligent algorithm for placing the axis-label or for calculating sensible tickmarks. Therefore it is advisable to create the label and tickmarks-object yourself. @version $Revision: 1.4 $ @author $Author: bablokb $ */ public class Axis extends AbstractPlottable { ////////////////////////////////////////////////////////////////////////////// /** Start-point of axis. */ private Point2D iTail = null; ////////////////////////////////////////////////////////////////////////////// /** End-point of axis. */ private Point2D iHead = null; ////////////////////////////////////////////////////////////////////////////// /** Major tickmarks. This object is only used if not null. */ TickMarks iMajorTickMarks = null; ////////////////////////////////////////////////////////////////////////////// /** Minor tickmarks. This object is only used if not null. */ TickMarks iMinorTickMarks = null; ////////////////////////////////////////////////////////////////////////////// /** Label of axis. This object is only used if not null. */ PLabel iLabel = null; ////////////////////////////////////////////////////////////////////////////// /** Construct an axis from start and endpoint, given in Point2D coordinates. */ public Axis(Point2D p1, Point2D p2) { iTail = p1; iHead = p2; } ///////////////////////////////////////////////////////////////////////////// /** Construct an axis from specified double coordinates. */ public Axis(double x1, double y1, double x2, double y2) { iTail = Toolkit.getDefaultToolkit().getPoint2D(); iHead = Toolkit.getDefaultToolkit().getPoint2D(); iTail.setLocation(x1,y1); iHead.setLocation(x2,y2); } ///////////////////////////////////////////////////////////////////////////// /** Set axis-properties. */ public void setProperties(AxisProperties prop) { iProperties = prop; } ///////////////////////////////////////////////////////////////////////////// /** Set major tickmarks. This object is only used if not null. */ public void setMajorTickMarks(TickMarks t) { iMajorTickMarks = t; } ///////////////////////////////////////////////////////////////////////////// /** Set minor tickmarks. This object is only used if not null. */ public void setMinorTickMarks(TickMarks t) { iMinorTickMarks = t; } ///////////////////////////////////////////////////////////////////////////// /** Set axis label. This object is only used if not null. */ public void setLabel(PLabel l) { iLabel = l; } ///////////////////////////////////////////////////////////////////////////// /** Return orientation of the axis. */ public int getOrientation() { if (iTail == null || iHead == null) return Plotlib.UNDEFINED; else if (iTail.getX() == iHead.getX()) return Plotlib.VERTICAL; else if (iTail.getY() == iHead.getY()) return Plotlib.VERTICAL; else return Plotlib.UNDEFINED; // e.g. z-axis as a diagonal } ///////////////////////////////////////////////////////////////////////////// /** Plot the axis. */ public void plotObjects(PlottingContext pc) { if (iTail == null || iHead == null) // we need at least start and end return; AxisProperties props = (AxisProperties) iProperties; Graphics2D g2 = pc.getG2(); // construct axis-line Lines line = new Lines(iTail,iHead); // construct symbols Symbols head = new Symbols(iHead); if (props != null) { SymbolProperties sph = new SymbolProperties(props); sph.setSymbolType(props.getHeadSymbolType()); sph.setSize(props.getHeadSymbolSize()); head.setProperties(sph); } Symbols tail = new Symbols(iTail); if (props != null) { SymbolProperties spt = new SymbolProperties(props); spt.setSymbolType(props.getTailSymbolType()); spt.setSize(props.getTailSymbolSize()); tail.setProperties(spt); } tail.plot(pc); line.plot(pc); head.plot(pc); if (iLabel != null) iLabel.plot(pc); if (iMajorTickMarks != null) iMajorTickMarks.plot(pc); if (iMinorTickMarks != null) iMinorTickMarks.plot(pc); } }