/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2006, by :
* Corporate:
* EADS Astrium SAS
* Individual:
* Mathias Choquet
*
*
* $$Id$$
*
*/
package simtools.shapes;
import java.awt.BasicStroke;
import java.awt.Stroke;
import java.io.Serializable;
/**
* Class StrokeParameters
* Summary:
* This class is the data model to build and handle
* easily strokes and more particularly java.awt.Stroke
* objects
*/
public class StrokeParameters implements Serializable {
private static final long serialVersionUID = -924948343084276005L;
public float param1;
public float param2;
//by default, thicknes is set to 1.f
public float thickness;
public StrokeParameters() {
this(-1.f, -1.f);
}
public StrokeParameters(float param1, float param2) {
this(param1,param2,1f);
}
public StrokeParameters(float param1, float param2, float thickness) {
this.param1 = param1;
this.param2 = param2;
this.thickness = thickness;
}
public StrokeParameters(StrokeParameters d) {
this.param1 = d.param1;
this.param2 = d.param2;
this.thickness = d.thickness;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj instanceof StrokeParameters) {
StrokeParameters dobj = (StrokeParameters) obj;
if (dobj.param1 == param1 && dobj.param2 == param2 && dobj.thickness == thickness) {
return true;
}
}
return false;
}
public boolean equalsIgnoreThickness(Object obj) {
if (obj instanceof StrokeParameters) {
StrokeParameters dobj = (StrokeParameters) obj;
if (dobj.param1 == param1 && dobj.param2 == param2) {
return true;
}
}
return false;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return "(" + param1 + "," + param2 + "," + thickness + ")";
}
public void setThickness(float thickness){
this.thickness = thickness;
}
public Stroke createStroke() {
return createStroke(param1,param2,thickness);
}
/**
* A hook to fill this Abstract2D shape
* @param f1 : the param1 for the creation of a stroke
* @param f2 : the param2 for the creation of a stroke
* @return java.awt.Stroke :
* the stroke created, if parameters are corrupted
* return a not dashed stroke
*/
public static Stroke createStroke(float f1, float f2) {
return createStroke(f1, f2, 1f);
}
/**
* A hook to fill this Abstract2D shape
* @param f1 : the param1 for the creation of a stroke
* @param f2 : the param2 for the creation of a stroke
* @param width : the width for the creation of a stroke
* @return java.awt.Stroke :
* the stroke created, if parameters are corrupted
* return a not dashed stroke
*/
public static Stroke createStroke(float f1, float f2,float width) {
if (f1 < 0 || f2 < 0) {
return (new BasicStroke(width));
}
float[] fd = { f1, f2 };
return new BasicStroke(width, BasicStroke.CAP_SQUARE,
BasicStroke.JOIN_MITER, 1.f, fd, 0.f);
}
}