/************************************************************************** /* This class is part of the Java Plotlib Toolkit. /* /* Copyright (c) 1999-2004 by Bernhard Bablok (mail@bablokb.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.*; /** Define symbol-forms. Symbol constants are defined in class Plotlib. Subclasses of Form implement the actual drawing necessary to plot the symbol defined by the corresponding symbol type. To add a new symbol, you must subclass Form, add a type constant to the Plotlib class and change the mapping array of type constants in Plotlib.FORM_TABLE. @see de.bablokb.plotlib.core.Plotlib @version $Revision: 1.3 $ @author $Author: bablokb $ */ abstract class Form { /** Size of the form. */ protected float iSize; /** Graphics2D object to draw to. */ protected Graphics2D iG2 = null; ///////////////////////////////////////////////////////////////////////////// /** Set the Graphics2D object. */ public void setG2(Graphics2D g2) { iG2 = g2; } ///////////////////////////////////////////////////////////////////////////// /** Set size of the form. */ public void setSize(float size) { iSize = size; } ///////////////////////////////////////////////////////////////////////////// /** Plot the form. This method must be implemented by subclasses. */ public abstract void plot(Point2D p); ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws a circle. */ static class Circle extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form.

FIXME: Use Ellipse2D instead of Arc2D and take the aspect ratio into account to make the circle a circle. */ public void plot(Point2D p) { Arc2D a = Toolkit.getDefaultToolkit().getArc2D(); a.setArcByCenter(p.getX(),p.getY(),iSize/2,0,360,Arc2D.OPEN); iG2.draw(a); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws a minus sign. */ static class Minus extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x-iSize/2,y); gp.lineTo(x+iSize/2,y); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws a plus sign. */ static class Plus extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x-iSize/2,y); gp.lineTo(x+iSize/2,y); gp.moveTo(x,y-iSize/2); gp.lineTo(x,y+iSize/2); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws a star. */ static class Star extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x-iSize/2,y); gp.lineTo(x+iSize/2,y); gp.moveTo(x,y-iSize/2); gp.lineTo(x,y+iSize/2); gp.moveTo(x-iSize/2,y-iSize/2); gp.lineTo(x+iSize/2,y+iSize/2); gp.moveTo(x-iSize/2,y+iSize/2); gp.lineTo(x+iSize/2,y-iSize/2); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws a square. */ static class Square extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x-iSize/2,y+iSize/2); gp.lineTo(x+iSize/2,y+iSize/2); gp.lineTo(x+iSize/2,y-iSize/2); gp.lineTo(x-iSize/2,y-iSize/2); gp.lineTo(x-iSize/2,y+iSize/2); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws a vertical bar. */ static class Vert extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x,y-iSize/2); gp.lineTo(x,y+iSize/2); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws an arrow pointing south. The GeneralPath takes the standard orientation of y-coordinates into account (top to bottom). */ static class SArrow extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x-iSize/4,y-iSize/2); gp.lineTo(x,y); gp.lineTo(x+iSize/4,y-iSize/2); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws an arrow pointing east. */ static class EArrow extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x-iSize/2,y-iSize/4); gp.lineTo(x,y); gp.lineTo(x-iSize/2,y+iSize/4); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws an arrow pointing north. The GeneralPath takes the standard orientation of y-coordinates into account (top to bottom). */ static class NArrow extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x-iSize/4,y+iSize/2); gp.lineTo(x,y); gp.lineTo(x+iSize/4,y+iSize/2); iG2.draw(gp); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /** Draws an arrow pointing west. */ static class WArrow extends Form { /////////////////////////////////////////////////////////////////////////// /** Plot the form. */ public void plot(Point2D p) { GeneralPath gp = new GeneralPath(); float x = (float) p.getX(), y = (float) p.getY(); gp.moveTo(x+iSize/2,y-iSize/4); gp.lineTo(x,y); gp.lineTo(x+iSize/2,y+iSize/4); iG2.draw(gp); } } }