/************************************************************************** /* 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 a single line. This class is not really necessary, since you could also use the Lines-class, but it could make your program more readable. @version $Revision: 1.2 $ @author $Author: bablokb $ */ public class Line extends AbstractPlottable { ///////////////////////////////////////////////////////////////////////////// /** The implementing Line2D-object. */ private Line2D iLine; ///////////////////////////////////////////////////////////////////////////// /** Construct a Line from (0,0) to (0,0) with default color, width and type. */ public Line() { iLine = Toolkit.getDefaultToolkit().getLine2D(); } ///////////////////////////////////////////////////////////////////////////// /** Construct a Line with specified Point2D coordinates and with default color, width and type. */ public Line(Point2D p1, Point2D p2) { this(); iLine.setLine(p1,p2); } ///////////////////////////////////////////////////////////////////////////// /** Construct a Line with specified double coordinates and with default color, width and type. */ public Line(double x1, double y1, double x2, double y2) { this(); iLine.setLine(x1,y1,x2,y2); } ///////////////////////////////////////////////////////////////////////////// /** Create and initialize a Line object with the given Line2D object. */ public Line(Line2D line) { iLine = line; } ///////////////////////////////////////////////////////////////////////////// /** Sets properties-object. */ public void setProperties(LineProperties lp) { iProperties = lp; } ///////////////////////////////////////////////////////////////////////////// /** Set the Line-object from given double coordinates. */ public void setLine(double x1, double y1, double x2, double y2) { iLine.setLine(x1,y1,x2,y2); } ///////////////////////////////////////////////////////////////////////////// /** Set the Line-object from given point coordinates. */ public void setLine(Point2D p1, Point2D p2) { iLine.setLine(p1,p2); } ///////////////////////////////////////////////////////////////////////////// /** Plot the line. */ public void plotObjects(PlottingContext pc) { Graphics2D g2 = pc.getG2(); if (iLine != null) g2.draw(pc.transform(iLine)); } }