/************************************************************************** /* 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.util.*; import java.awt.*; import java.awt.geom.*; /** Plot symbols. Symbols are defined by there location (Point2D) and various attributes (see SymbolProperties). The actual graphical form of the symbol is implemented by a private class, which implements a plot() method. @version $Revision: 1.2 $ @author $Author: bablokb $ */ public class Symbols extends AbstractPlottable { ///////////////////////////////////////////////////////////////////////////// /** List of points (instances of Point2D). */ private java.util.List iPoints = new java.util.ArrayList(); ///////////////////////////////////////////////////////////////////////////// /** Default constructor: create and initialize a Symbols object. */ public Symbols() { } ///////////////////////////////////////////////////////////////////////////// /** Create and initialize a Symbols object with a given point. */ public Symbols(Point2D p) { iPoints.add(p); } ///////////////////////////////////////////////////////////////////////////// /** Create and initialize a Symbols object with the given list. */ public Symbols(java.util.List l) { iPoints = l; } ///////////////////////////////////////////////////////////////////////////// /** Sets properties-object. */ public void setProperties(SymbolProperties sp) { iProperties = sp; } ///////////////////////////////////////////////////////////////////////////// /** Set list of points. Note that the elements of the list should be objects of the Point2D class, but this is not verified. Removed if null is passed as argument. */ public void setPoints(java.util.List l) { iPoints = l; } ///////////////////////////////////////////////////////////////////////////// /** Add a point to the list of points. This is a convinience wrapper to the add()-method of java.util.List. If no list exists, an ArrayList is created. */ public void add(Point2D p) { if (iPoints == null) iPoints = new ArrayList(); iPoints.add(p); } ///////////////////////////////////////////////////////////////////////////// /** Query list of points. */ public java.util.List getPoints() { return iPoints; } ///////////////////////////////////////////////////////////////////////////// /** Return first point of list (convenience-method for single symbols). */ public Point2D getPoint() { if (iPoints != null) return (Point2D) iPoints.get(0); else return null; } ///////////////////////////////////////////////////////////////////////////// /** Plot the symbols.

FIXME: Should I use a buffer to create the symbol and then just copy the buffer to all locations? */ public void plotObjects(PlottingContext pc) { SymbolProperties sp; if (iProperties == null) sp = new SymbolProperties(); else sp = (SymbolProperties) iProperties; int symbolType = sp.getSymbolType(); if (symbolType == Plotlib.NONE) return; Graphics2D g2 = pc.getG2(); Form form = Plotlib.FORM_TABLE[symbolType]; form.setSize(sp.getSize()); form.setG2(g2); if (iPoints != null) { ListIterator lit = iPoints.listIterator(); // iterate all points while (lit.hasNext()) form.plot(pc.transform((Point2D) lit.next())); } } }