lightgraph.GraphLine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of light-weight-graphing Show documentation
Show all versions of light-weight-graphing Show documentation
Library for creating graphs in a swing environment. Can produce png or svg.
The newest version!
package lightgraph;
import lightgraph.painters.GraphPainter;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
/**
* For drawing lines.
*
* User: mbs207
* Date: May 20, 2010
* Time: 6:48:46 AM
*/
public abstract class GraphLine {
double WIDTH = 1;
abstract public void drawLine(ArrayList pts, GraphPainter painter);
public double getLineWidth(){
return WIDTH;
}
public void setLineWidth(double w){
WIDTH = w;
}
/**
* Default line implementation.
*
* @return solid line.
*/
public static GraphLine solidLine(){
return new GraphLine(){
public void drawLine(ArrayList pts, GraphPainter painter){
painter.setLineWidth(WIDTH);
Path2D path = new Path2D.Double();
if(pts.size()>0){
Point2D pt = pts.get(0);
path.moveTo(pt.getX(), pt.getY());
for(int i = 1; i pts, GraphPainter painter){
painter.setLineWidth(WIDTH);
painter.setDashes(dashes);
Path2D path = new Path2D.Double();
if(pts.size()>0){
Point2D pt = pts.get(0);
path.moveTo(pt.getX(), pt.getY());
for(int i = 1; i getLines(){
ArrayList lines = new ArrayList();
lines.add(solidLine());
lines.add(shortDashes());
lines.add(longDashes());
lines.add(longShortDashes());
lines.add(longShortShortDashes());
return lines;
}
}