/************************************************************************** /* 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.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import de.bablokb.plotlib.core.*; /** This test tests lines. It uses a PlotHashTable to store all objects. @version $Revision: 1.5 $ @author $Author: bablokb $ */ public class LineTest extends Canvas { private PlottingContext iPlottingContext; private PlotHashtable iTable; ///////////////////////////////////////////////////////////////////////////// /** Constructor. Create the PlottingContext and PlotHashTable. Set the mathematical range of the context. */ public LineTest() { iPlottingContext = new PlottingContext(); iTable = new PlotHashtable(); iPlottingContext.setRange(new Rectangle2D.Float(-10.0f,-10.0f,40.0f,20.0f)); } ///////////////////////////////////////////////////////////////////////////// /** Main-method: Create a JFrame, add a LineTest-Object and show the frame. */ public static void main(String[] args) { JFrame frame = new JFrame("Plotlib Test"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); }}); LineTest t = new LineTest(); t.addPlotObjects(); frame.getContentPane().add(t); frame.pack(); frame.show(); } ///////////////////////////////////////////////////////////////////////////// /** Add objects to the PlotList objects. */ private void addPlotObjects() { // a vertical line LineProperties v0Prop = new LineProperties(); v0Prop.setWidth(Plotlib.WIDE); Lines v0 = new Lines(0.0f,-100.0f,0.0f,100.0f); v0.setProperties(v0Prop); // a horizontal line LineProperties h0Prop = new LineProperties(); Lines h0 = new Lines(-100.0f,0.0f,100.0f,0.0f); h0Prop.setWidth(Plotlib.MEDIUM); // some more vertical lines LineProperties v2Prop = new LineProperties(); v2Prop.setColor(Color.green); Lines v2 = new Lines(2.0f,0.0f,2.0f,10.0f); v2.setProperties(v2Prop); LineProperties v8Prop = new LineProperties(); v8Prop.setColor(Color.red); Lines v8 = new Lines(8.0f,0.0f,8.0f,10.0f); v8.setProperties(v8Prop); // parallel horizontal lines with different stroke Lines h1 = new Lines(0.0f,3.0f,20.0f,3.0f); // default attributes // dotted LineProperties h2Prop = new LineProperties(); h2Prop.setDashType(Plotlib.DOT); Lines h2 = new Lines(0.0f,4.0f,20.0f,4.0f); h2.setProperties(h2Prop); // dashed LineProperties h3Prop = new LineProperties(); h3Prop.setDashType(Plotlib.DASH); Lines h3 = new Lines(0.0f,5.0f,20.0f,5.0f); h3.setProperties(h3Prop); // dash-dot LineProperties h4Prop = new LineProperties(); h4Prop.setDashType(Plotlib.DASHDOT); Lines h4 = new Lines(0.0f,6.0f,20.0f,6.0f); h4.setProperties(h4Prop); // dash-dot-dot LineProperties h5Prop = new LineProperties(); h5Prop.setDashType(Plotlib.DASHDOTDOT); Lines h5 = new Lines(0.0f,7.0f,20.0f,7.0f); h5.setProperties(h5Prop); // a diagonal line LineProperties d1Prop = new LineProperties(); d1Prop.setDashType(Plotlib.DOT); Lines d1 = new Lines(2.0f,3.0f,10.0f,15.0f); d1.setProperties(d1Prop); // a diagonal line using a Line-object LineProperties d2Prop = new LineProperties(); d2Prop.setDashType(Plotlib.DASH); d2Prop.setWidth(Plotlib.MEDIUM); Line d2 = new Line(2.0f,4.0f,10.0f,16.0f); d2.setProperties(d2Prop); // add objects to hashtable iTable.put("v0",v0); iTable.put("h0",h0); iTable.put("v2",v2); iTable.put("v8",v8); iTable.put("h1",h1); iTable.put("h2",h2); iTable.put("h3",h3); iTable.put("h4",h4); iTable.put("h5",h5); iTable.put("d1",d1); iTable.put("d2",d2); } ///////////////////////////////////////////////////////////////////////////// /** Return preferred size. */ public Dimension getPreferredSize() { return getMinimumSize(); } ///////////////////////////////////////////////////////////////////////////// /** Return minimal size. */ public Dimension getMinimumSize() { return new Dimension(200,100); } ///////////////////////////////////////////////////////////////////////////// /** Paint all objects. */ public void paint(Graphics g) { iPlottingContext.setSize(getSize()); // use full size of graphics-area iPlottingContext.setG2((Graphics2D) g); iPlottingContext.setDefaults(); iTable.plot(iPlottingContext); } }