/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package DisplayProject.controls;
import java.awt.Graphics;
import java.awt.Graphics2D;
import org.apache.log4j.Logger;
import DisplayProject.Array_Of_DataPoint;
import DisplayProject.DataPoint;
import DisplayProject.UIutils;
import Framework.TextData;
/**
* The PolyLine class defines a multi-segment line that can have any number and orientation of vertices.
* Each segment of a poly line is defined as a pair of points, one beginning the segment and one ending the segment.
*
*/
@SuppressWarnings("serial")
public class PolyLine extends Route {
private static Logger _log = Logger.getLogger(PolyLine.class);
public static class qq_Resolver {
public static final int cFILLCOLOR_PENCOLOR = 1;
public static final int cPENCOLOR_FILLCOLOR = 2;
public static final int cNAME = 3;
}
public PolyLine(){
super();
// TF:15/12/2009:DET-141:Set this up to allow inheriting of popup menu
this.setInheritsPopupMenu(true);
}
public PolyLine( int color1, int color2, int resolver )
{
this();
switch (resolver){
case qq_Resolver.cFILLCOLOR_PENCOLOR:
this.setForeground(UIutils.forteToJavaColor(color2));
this.setBackground(UIutils.forteToJavaColor(color1));
break;
case qq_Resolver.cPENCOLOR_FILLCOLOR:
this.setForeground(UIutils.forteToJavaColor(color1));
this.setBackground(UIutils.forteToJavaColor(color2));
break;
}
}
public PolyLine( String name )
{
this(name, qq_Resolver.cNAME);
}
public PolyLine( TextData name, int resolver )
{
this(name.toString(), resolver);
}
public PolyLine( String name, int resolver )
{
this();
switch (resolver){
case qq_Resolver.cNAME:
this.setName(name);
break;
}
}
public void paint(Graphics g) {
g.setColor( this.getForeground() );
Graphics2D g2d = (Graphics2D)g;
g2d.setStroke(UIutils.makeStroke(this.lineWeight, this.lineStyle));
_log.debug("about to draw polyline: " + g.getColor().toString());
g.drawPolyline(xPoints, yPoints, nPoints);
}
public void addPointInMills(int x, int y) {
if (this.pointArray == null){
pointArray = new Array_Of_DataPoint<DataPoint>();
}
pointArray.add(new DataPoint(x, y));
nPoints += 1;
int[] tempX = new int[nPoints];
int[] tempY = new int[nPoints];
System.arraycopy(xPoints, 0, tempX, 0, xPoints.length);
System.arraycopy(yPoints, 0, tempY, 0, yPoints.length);
xPoints = tempX;
yPoints = tempY;
xPoints[nPoints-1] = UIutils.milsToPixels(x);
yPoints[nPoints-1] = UIutils.milsToPixels(y);
sizeToFit();
repaint();
}
public void addPoint(int x, int y) {
if (this.pointArray == null){
pointArray = new Array_Of_DataPoint<DataPoint>();
}
pointArray.add(new DataPoint(UIutils.pixelsToMils(x), UIutils.pixelsToMils(y)));
nPoints += 1;
int[] tempX = new int[nPoints];
int[] tempY = new int[nPoints];
System.arraycopy(xPoints, 0, tempX, 0, xPoints.length);
System.arraycopy(yPoints, 0, tempY, 0, yPoints.length);
xPoints = tempX;
yPoints = tempY;
xPoints[nPoints-1] = x;
yPoints[nPoints-1] = y;
sizeToFit();
repaint();
}
}