/************************************************************************** /* 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.test; import java.util.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import de.bablokb.plotlib.core.*; /** Test application for the Plotlib Toolkit. @version $Revision: 1.5 $ @author $Author: bablokb $ */ public class AxisTest extends Canvas { private PlottingContext iPlottingContext; private PlotList iList; public AxisTest() { iPlottingContext = new PlottingContext(); iList = new PlotList(); iPlottingContext.setRange(new Rectangle2D.Float(-12.0f,-10.0f,42.0f,20.0f)); } ///////////////////////////////////////////////////////////////////////////// public static void main(String[] args) { JFrame frame = new JFrame("Plotlib Test"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); }}); AxisTest t = new AxisTest(); t.setFont(new Font("Helvetica", Font.ITALIC, 8)); t.addPlotObjects(); frame.getContentPane().add(t); frame.pack(); frame.show(); } ///////////////////////////////////////////////////////////////////////////// private void addPlotObjects() { iList.add(createXAxis()); iList.add(createYAxis()); } ///////////////////////////////////////////////////////////////////////////// /** Create an X-Axis (red, arrow right, major- and minor-tickmarks) */ private Axis createXAxis() { // first, setup property objects BasicProperties baseProps = new BasicProperties(); baseProps.setColor(Color.red); AxisProperties xAxisProps = new AxisProperties(baseProps); xAxisProps.setHeadSymbolType(Plotlib.EARROW); xAxisProps.setHeadSymbolSize(Plotlib.LARGE); xAxisProps.setTailSymbolType(Plotlib.NONE); TickMarkProperties majorProperties = new TickMarkProperties(baseProps); majorProperties.setTickMarksType(Plotlib.MAJOR); majorProperties.setSize(Plotlib.LARGE); majorProperties.setOrientation(Plotlib.HORIZONTAL); TickMarkProperties minorProperties = new TickMarkProperties(baseProps); minorProperties.setTickMarksType(Plotlib.MINOR); minorProperties.setSize(Plotlib.BIG); minorProperties.setOrientation(Plotlib.HORIZONTAL); // create components: tick-marks TickMarks majorTicks = new TickMarks(); majorTicks.setProperties(majorProperties); float xOffset = -1.8f; for (float x=-10; x<25; x+=10) { Point2D.Float p = new Point2D.Float(x,0); majorTicks.addPoint(p); majorTicks.addLabel(new PLabel(String.valueOf(x), new Point2D.Float(x-1,xOffset))); } TickMarks minorTicks = new TickMarks(); minorTicks.setProperties(minorProperties); for (float x=-5; x<30; x+=10) { Point2D.Float p = new Point2D.Float(x,0); minorTicks.addPoint(p); } // create components: label PLabel xLabel = new PLabel("x-Axis",new Point2D.Float(25.0f,1.2f)); // finally, add everything to the axis Axis xAxis = new Axis(-10.,0.,28.,0.); xAxis.setProperties(xAxisProps); xAxis.setMajorTickMarks(majorTicks); xAxis.setMinorTickMarks(minorTicks); xAxis.setLabel(xLabel); return xAxis; } ///////////////////////////////////////////////////////////////////////////// /** Create an Y-Axis (green, with arrows on both sides, no tickmarks) */ private Axis createYAxis() { // first, setup property objects BasicProperties baseProps = new BasicProperties(); baseProps.setColor(Color.green); AxisProperties yAxisProps = new AxisProperties(baseProps); yAxisProps.setHeadSymbolType(Plotlib.NARROW); yAxisProps.setHeadSymbolSize(Plotlib.LARGE); yAxisProps.setTailSymbolType(Plotlib.SARROW); yAxisProps.setTailSymbolSize(Plotlib.LARGE); // create components: label PLabel yLabel = new PLabel("y-Axis",new Point2D.Float(1,8)); // finally, add everything to the axis Axis yAxis = new Axis(0.,-8.,0.,8.); yAxis.setProperties(yAxisProps); yAxis.setLabel(yLabel); return yAxis; } ///////////////////////////////////////////////////////////////////////////// public Dimension getPreferredSize() { return getMinimumSize(); } ///////////////////////////////////////////////////////////////////////////// public Dimension getMinimumSize() { return new Dimension(400,200); } ///////////////////////////////////////////////////////////////////////////// public void paint(Graphics g) { iPlottingContext.setSize(getSize()); iPlottingContext.setG2((Graphics2D) g); iPlottingContext.setDefaults(); iList.plot(iPlottingContext); } }