/************************************************************************** /* 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 lines. The lines share a common set of attributes (LineProperties). @version $Revision: 1.2 $ @author $Author: bablokb $ */ public class Lines extends AbstractPlottable { ///////////////////////////////////////////////////////////////////////////// /** List of lines (instances of Line2D). */ private java.util.List iLines = new java.util.ArrayList(); ///////////////////////////////////////////////////////////////////////////// /** Construct a Line from (0,0) to (0,0) with default color, width and type. */ public Lines() { iLines.add(Toolkit.getDefaultToolkit().getLine2D()); } ///////////////////////////////////////////////////////////////////////////// /** Construct a Line with specified Point2D coordinates and with default color, width and type. */ public Lines(Point2D p1, Point2D p2) { Line2D line = Toolkit.getDefaultToolkit().getLine2D(); line.setLine(p1,p2); iLines.add(line); } ///////////////////////////////////////////////////////////////////////////// /** Construct a Line with specified double coordinates and with default color, width and type. */ public Lines(double x1, double y1, double x2, double y2) { Line2D line = Toolkit.getDefaultToolkit().getLine2D(); line.setLine(x1,y1,x2,y2); iLines.add(line); } ///////////////////////////////////////////////////////////////////////////// /** Create and initialize a Lines object with the given Lines2D object. */ public Lines(Line2D line) { iLines.add(line); } ///////////////////////////////////////////////////////////////////////////// /** Create and initialize a Lines object with the given list of Lines2D. */ public Lines(java.util.List l) { iLines = l; } ///////////////////////////////////////////////////////////////////////////// /** Sets properties-object. */ public void setProperties(LineProperties lp) { iProperties = lp; } ///////////////////////////////////////////////////////////////////////////// /** Sets the list of lines to the given list. */ public void setLines(java.util.List l) { iLines = l; } ///////////////////////////////////////////////////////////////////////////// /** Add a line to the list of lines. This is a convinience wrapper to the add()-method of java.util.List. If no list exists, an ArrayList is created. */ public void add(Line2D l) { if (iLines == null) iLines = new ArrayList(); iLines.add(l); } ///////////////////////////////////////////////////////////////////////////// /** Plot the line and/or lines. */ public void plotObjects(PlottingContext pc) { Graphics2D g2 = pc.getG2(); if (iLines != null) { ListIterator lit = iLines.listIterator(); // iterate all lines while (lit.hasNext()) g2.draw(pc.transform((Line2D) lit.next())); } } }