Search in sources :

Example 96 with GeneralPath

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);
        }
    }
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) ShapeFactory(org.knime.core.data.property.ShapeFactory) Graphics2D(java.awt.Graphics2D)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1