Search in sources :

Example 51 with BasicStroke

use of java.awt.BasicStroke in project knime-core by knime.

the class ParallelCoordinateDrawingPane method drawLine.

/**
 * Draws the line between the mapped data points of one
 * {@link org.knime.base.node.viz.plotter.parcoord.LineInfo}.
 *
 * @param g graphics object
 * @param line one line / row
 */
private void drawLine(final Graphics g, final LineInfo line) {
    if (m_fade && !line.isHilite()) {
        if (line.isSelected()) {
            g.setColor(ColorAttr.INACTIVE_SELECTED);
        } else {
            g.setColor(ColorAttr.INACTIVE);
        }
    } else if (!m_hide && !m_fade) {
        g.setColor(line.getColor().getColor(line.isSelected(), line.isHilite()));
    } else {
        // bugfix : 1278
        g.setColor(line.getColor().getColor(line.isSelected(), false));
    }
    int lineSize = getStrokeSize(line.getSize());
    Stroke selectionStroke = new BasicStroke(lineSize, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { DASH }, 0);
    ((Graphics2D) g).setStroke(new BasicStroke(lineSize));
    List<Point> points = line.getPoints();
    for (int i = 0; i < points.size() - 1; i++) {
        Point p1 = points.get(i);
        Point p2 = points.get(i + 1);
        if ((p1.y == ParallelCoordinatesPlotter.MISSING || p2.y == ParallelCoordinatesPlotter.MISSING)) {
            if (m_skipValues) {
                continue;
            }
            if (m_showMissingVals) {
                int pointPos = getHeight() - (2 * g.getFontMetrics().getHeight());
                if (p1.y == ParallelCoordinatesPlotter.MISSING) {
                    p1.y = pointPos;
                }
                if (p2.y == ParallelCoordinatesPlotter.MISSING) {
                    p2.y = pointPos;
                }
            }
        }
        // backup
        Color backupColor = g.getColor();
        if (line.isHilite() && !m_hide && !m_fade) {
            // draw additional "hilite" line#
            Stroke backupStroke = ((Graphics2D) g).getStroke();
            ((Graphics2D) g).setStroke(new BasicStroke(2 * lineSize));
            g.setColor(ColorAttr.HILITE);
            g.drawLine(p1.x, p1.y, p2.x, p2.y);
            g.setColor(backupColor);
            ((Graphics2D) g).setStroke(backupStroke);
        }
        // draw the line
        g.drawLine(p1.x, p1.y, p2.x, p2.y);
        if (line.isSelected()) {
            // draw dotted line
            Stroke backupStroke = ((Graphics2D) g).getStroke();
            ((Graphics2D) g).setStroke(selectionStroke);
            g.setXORMode(Color.white);
            g.drawLine(p1.x, p1.y, p2.x, p2.y);
            ((Graphics2D) g).setStroke(backupStroke);
            g.setPaintMode();
        }
        // draw the point
        if (m_showDots) {
            paintDot(g, p1, line, lineSize);
        }
    }
    if (m_showDots) {
        // draw the points of the last axis
        Point p = line.getPoints().get(line.getPoints().size() - 1);
        paintDot(g, p, line, lineSize);
    }
    ((Graphics2D) g).setStroke(new BasicStroke(1));
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Point(java.awt.Point) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 52 with BasicStroke

use of java.awt.BasicStroke in project knime-core by knime.

the class HierarchicalClusterNodeView method modelChanged.

/**
 * {@inheritDoc}
 */
@Override
public void modelChanged() {
    if (getNodeModel() == null || ((DataProvider) getNodeModel()).getDataArray(0) == null || ((DataProvider) getNodeModel()).getDataArray(0).size() == 0) {
        return;
    }
    NodeModel model = getNodeModel();
    m_dendroPlotter.reset();
    m_distancePlotter.reset();
    m_dendroPlotter.setHiLiteHandler(model.getInHiLiteHandler(0));
    m_dendroPlotter.setAntialiasing(false);
    m_dendroPlotter.setDataProvider((DataProvider) model);
    m_distancePlotter.setDataProvider((DataProvider) model);
    m_distancePlotter.setHiLiteHandler(model.getInHiLiteHandler(0));
    DendrogramNode rootNode = getNodeModel().getRootNode();
    DataArray distanceTable = ((DataProvider) getNodeModel()).getDataArray(0);
    m_dendroPlotter.setRootNode(rootNode);
    m_distancePlotter.createXCoordinate(((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(0).getDomain().getLowerBound()).getDoubleValue(), ((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(0).getDomain().getUpperBound()).getDoubleValue());
    m_distancePlotter.createYCoordinate(((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(1).getDomain().getLowerBound()).getDoubleValue(), ((DoubleValue) distanceTable.getDataTableSpec().getColumnSpec(1).getDomain().getUpperBound()).getDoubleValue());
    ((BasicDrawingPane) m_distancePlotter.getDrawingPane()).clearPlot();
    m_distancePlotter.addLine(distanceTable, 0, 1, Color.BLACK, new BasicStroke(m_thickness));
    // m_distancePlotter.getXAxis().getCoordinate().setPolicy(
    // DescendingNumericTickPolicyStrategy.getInstance());
    m_distancePlotter.updatePaintModel();
    m_dendroPlotter.updatePaintModel();
}
Also used : DataProvider(org.knime.base.node.viz.plotter.DataProvider) BasicStroke(java.awt.BasicStroke) NodeModel(org.knime.core.node.NodeModel) BasicDrawingPane(org.knime.base.node.viz.plotter.basic.BasicDrawingPane) DendrogramNode(org.knime.base.node.viz.plotter.dendrogram.DendrogramNode) DataArray(org.knime.base.node.util.DataArray)

Example 53 with BasicStroke

use of java.awt.BasicStroke in project knime-core by knime.

the class HierarchicalGraphView method paintNode.

/**
 * Draw the node, its background and border to the graphics object.
 */
private void paintNode(final Component c, final DefaultMutableTreeNode node, final Graphics2D g) {
    K k = (K) node.getUserObject();
    NodeWidget<K> widget = getWidgets().get(k);
    widget.setScaleFactor(m_scale);
    Rectangle bounds = getVisible().get(k);
    boolean selected = m_selected == k;
    boolean hilited = m_hilited.contains(k);
    if (selected && hilited) {
        g.setPaint(ColorAttr.SELECTED_HILITE);
        g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 5, 5);
    } else if (selected) {
        g.setPaint(ColorAttr.SELECTED);
    } else if (hilited) {
        g.setPaint(ColorAttr.HILITE);
    } else {
        g.setPaint(ColorAttr.BACKGROUND);
    }
    g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 8, 8);
    widget.paint(c, g, bounds);
    if (selected) {
        g.setStroke(new BasicStroke(2f));
    } else {
        g.setStroke(new BasicStroke(1f));
    }
    g.setPaint(ColorAttr.BORDER);
    g.drawRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, 8, 8);
    g.setStroke(new BasicStroke(1f));
}
Also used : BasicStroke(java.awt.BasicStroke) Rectangle(java.awt.Rectangle)

Example 54 with BasicStroke

use of java.awt.BasicStroke in project knime-core by knime.

the class DrawingUtils method paintHorizontalLine.

/**
 * Draws a horizontal line starting at the given x/y offset with
 * the given length.
 * @param g2 the graphics object to use
 * @param xOffset the x offset of the line
 * @param yOffset the y offset of the line
 * @param lineWidth the width of the line
 * @param color the drawing color
 * @param stroke the stroke to use
 */
public static void paintHorizontalLine(final Graphics2D g2, final int xOffset, final int yOffset, final int lineWidth, final Color color, final BasicStroke stroke) {
    // save the original settings
    final Stroke origStroke = g2.getStroke();
    final Color origColor = g2.getColor();
    g2.setColor(color);
    g2.setStroke(stroke);
    g2.drawLine(xOffset, yOffset, lineWidth, yOffset);
    // set the original settings
    g2.setStroke(origStroke);
    g2.setColor(origColor);
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color)

Example 55 with BasicStroke

use of java.awt.BasicStroke in project knime-core by knime.

the class DrawingUtils method drawArc.

/**
 * Draws the outline of the given arc.
 * @param g2 the graphic object
 * @param arc the arc to draw
 * @param paint the filling color or TexturePaint
 * @param stroke the {@link Stroke} to use
 */
public static void drawArc(final Graphics2D g2, final Arc2D arc, final Paint paint, final BasicStroke stroke) {
    if (arc == null) {
        return;
    }
    final Arc2D outlineArc = calculateBorderArc(arc, stroke);
    // save the original settings
    final Paint origPaint = g2.getPaint();
    final Stroke origStroke = g2.getStroke();
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(outlineArc);
    // set the old settings
    g2.setPaint(origPaint);
    g2.setStroke(origStroke);
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Paint(java.awt.Paint) Arc2D(java.awt.geom.Arc2D)

Aggregations

BasicStroke (java.awt.BasicStroke)571 Graphics2D (java.awt.Graphics2D)179 Color (java.awt.Color)164 Stroke (java.awt.Stroke)141 GradientPaint (java.awt.GradientPaint)96 Test (org.junit.Test)93 Rectangle2D (java.awt.geom.Rectangle2D)71 Paint (java.awt.Paint)64 Font (java.awt.Font)61 Point (java.awt.Point)47 Line2D (java.awt.geom.Line2D)47 BufferedImage (java.awt.image.BufferedImage)43 Shape (java.awt.Shape)39 Point2D (java.awt.geom.Point2D)38 AffineTransform (java.awt.geom.AffineTransform)34 JFreeChart (org.jfree.chart.JFreeChart)34 Rectangle (java.awt.Rectangle)27 Ellipse2D (java.awt.geom.Ellipse2D)27 RectangleInsets (org.jfree.ui.RectangleInsets)27 NumberAxis (org.jfree.chart.axis.NumberAxis)25