java-org.hwo.ui/src/org/hwo/ui/diagram/LinePlotPainter.java

59 lines
1.0 KiB
Java

package org.hwo.ui.diagram;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
public class LinePlotPainter implements PlotPainter {
int lx,ly;
float width;
Stroke stroke,
selectedStroke;
Color color;
public LinePlotPainter() {
setWidth(1.0f);
}
@Override
public void reset() {
lx = -1;
ly = -1;
}
@Override
public void paintPoint(Graphics2D g, Color color, int x, int y,boolean isSelected) {
if (lx != -1){
g.setColor(this.color != null ? this.color : color);
Stroke s = isSelected ? this.selectedStroke : g.getStroke();
g.setStroke(stroke);
g.drawLine(lx, ly, x, y);
g.setStroke(s);
}
lx = x;
ly = y;
}
public void setWidth(float width) {
this.width = width;
this.stroke = new BasicStroke(width);
this.selectedStroke = new BasicStroke(width * 2);
}
public float getWidth() {
return width;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
}