/************************************************************************** /* 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.*; /** This class tests symbols. @version $Revision: 1.5 $ @author $Author: bablokb $ */ public class SymbolTest extends Canvas { private PlottingContext iPlottingContext; private PlotHashtable iTable; ///////////////////////////////////////////////////////////////////////////// /** Constructor. */ public SymbolTest() { 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); }}); SymbolTest t = new SymbolTest(); t.addPlotObjects(); frame.getContentPane().add(t); frame.pack(); frame.show(); } ///////////////////////////////////////////////////////////////////////////// /** Add objects to the PlotHashTable. */ private void addPlotObjects() { // three default symbols, horizontally aligned java.util.ArrayList points1 = new java.util.ArrayList(3); points1.add(0,new Point2D.Float(0,0)); points1.add(1,new Point2D.Float(5,0)); points1.add(2,new Point2D.Float(10,0)); Symbols s1 = new Symbols(); s1.setPoints(points1); // three big star-shaped symbols in red (vertically aligned) SymbolProperties sp2 = new SymbolProperties(); sp2.setSize(Plotlib.BIG); sp2.setSymbolType(Plotlib.STAR); sp2.setColor(Color.red); java.util.ArrayList points2 = new java.util.ArrayList(3); points2.add(0,new Point2D.Float(0,3)); points2.add(1,new Point2D.Float(0,4)); points2.add(2,new Point2D.Float(0,5)); Symbols s2 = new Symbols(); s2.setPoints(points2); s2.setProperties(sp2); // three large plus-shaped symbols in green (on a diagonal) SymbolProperties sp3 = new SymbolProperties(); sp3.setSize(Plotlib.LARGE); sp3.setSymbolType(Plotlib.PLUS); sp3.setColor(Color.green); java.util.ArrayList points3 = new java.util.ArrayList(3); points3.add(0,new Point2D.Float(0,-3)); points3.add(1,new Point2D.Float(5,-4)); points3.add(2,new Point2D.Float(10,-5)); Symbols s3 = new Symbols(); s3.setPoints(points3); s3.setProperties(sp3); // a square-shaped symbol with default color and size SymbolProperties sp4 = new SymbolProperties(); sp4.setSymbolType(Plotlib.SQUARE); Symbols s4 = new Symbols(); s4.add(new Point2D.Float(5,5)); s4.setProperties(sp4); // a large, north-arrow symbol in blue SymbolProperties sp5 = new SymbolProperties(); sp5.setSymbolType(Plotlib.NARROW); sp5.setSize(Plotlib.LARGE); sp5.setColor(Color.blue); Symbol s5 = new Symbol(); s5.setPoint(10,3); s5.setProperties(sp5); // add objects to table iTable.put("s1",s1); iTable.put("s2",s2); iTable.put("s3",s3); iTable.put("s4",s4); iTable.put("s5",s5); } ///////////////////////////////////////////////////////////////////////////// /** 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()); iPlottingContext.setG2((Graphics2D) g); iPlottingContext.setDefaults(); iTable.plot(iPlottingContext); } }