use of java.awt.geom.GeneralPath in project knime-core by knime.
the class LinePlotterDrawingPane method paintContent.
/**
* Connects the points of one column by a line, which is done by modulo
* calculation, the color information is stored in the
* {@link org.knime.base.node.viz.plotter.scatter.DotInfo}s.
*
* @see org.knime.base.node.viz.plotter.scatter.ScatterPlotterDrawingPane
* #paintContent(java.awt.Graphics)
*/
@Override
public void paintContent(final Graphics g) {
if (getDotInfoArray() == null || getDotInfoArray().getDots().length == 0) {
return;
}
ShapeFactory.Shape shape = ShapeFactory.getShape(ShapeFactory.RECTANGLE);
int dotSize = getDotSize();
DotInfo[] dotInfo = getDotInfoArray().getDots();
GeneralPath path = new GeneralPath();
for (int i = 0; i < dotInfo.length; i++) {
DotInfo dot1 = dotInfo[i];
if (m_showDots && dot1.paintDot()) {
boolean isSelected = getSelectedDots().contains(dotInfo[i].getRowID());
boolean isHilite = dotInfo[i].isHiLit();
Color c = dotInfo[i].getColor().getColor();
int x = dotInfo[i].getXCoord();
int y = dotInfo[i].getYCoord();
shape.paint(g, x, y, dotSize, c, isHilite, isSelected, false);
}
if (i % m_nrOfLines == 0 && path != null) {
// start of one line
path.reset();
// move to start point
path.moveTo(dot1.getXCoord(), dot1.getYCoord());
}
if (dot1.paintDot()) {
// if we had a missing value and !interpolate
if (path == null) {
path = new GeneralPath();
path.moveTo(dot1.getXCoord(), dot1.getYCoord());
} else {
// add line segment to path
path.lineTo(dot1.getXCoord(), dot1.getYCoord());
}
} else if (path != null) {
// if not paint dot (y = -1) => missing value && !interpolate
// we have to close the path and continue a new one
g.setColor(dot1.getColor().getColor());
((Graphics2D) g).setStroke(new BasicStroke(m_thickness));
((Graphics2D) g).draw(path);
path = null;
}
if (i % m_nrOfLines == (m_nrOfLines - 1) && path != null) {
// end of one line -> paint it
g.setColor(dot1.getColor().getColor());
((Graphics2D) g).setStroke(new BasicStroke(m_thickness));
((Graphics2D) g).draw(path);
}
}
}
Aggregations