Search in sources :

Example 76 with Stroke

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

the class HistogramDrawingPane method paintLabel.

/**
 * Draws a the given aggregation value as label inside of the given border
 * rectangle.
 * @param g2 the graphics object
 * @param borderRect the rectangle we wont to label
 * @param aggrVal the label value
 * @param aggrMethod the aggregation method to know how to round the value
 * @param drawingSpace the drawing space itself to avoid drawing outside
 * @param showVertical set to <code>true</code> if the label should be
 * painted vertical otherwise it is drawn horizontal
 */
private static void paintLabel(final Graphics2D g2, final Rectangle2D borderRect, final double aggrVal, final AggregationMethod aggrMethod, final Rectangle2D drawingSpace, final boolean showVertical) {
    if (borderRect == null) {
        return;
    }
    final String label = GUIUtils.createLabel(aggrVal, NO_OF_LABEL_DIGITS, aggrMethod);
    // save the original settings
    final AffineTransform origTransform = g2.getTransform();
    final Font origFont = g2.getFont();
    final Paint origPaint = g2.getPaint();
    final Stroke origStroke = g2.getStroke();
    final AffineTransform verticalTrans = new AffineTransform();
    g2.setFont(BAR_VALUE_FONT);
    final FontMetrics metrics = g2.getFontMetrics();
    int textX = (int) (borderRect.getX() + (borderRect.getWidth() / 2));
    int textWidth = metrics.stringWidth(label);
    // I always divide by 2 because the text is drawn at the specified
    // position and then rotated by the center!!!
    textX -= textWidth / 2;
    // avoid drawing the aggregation value outside of the display
    if (textX < 1) {
        textWidth += Math.abs(textX - 1);
        textX = 1;
    }
    int textY = 0;
    if (aggrVal >= 0) {
        textY = (int) (borderRect.getY() + borderRect.getHeight() - textWidth / 2.0) - AGGR_VAL_LABEL_SPACER;
    } else {
        textY = (int) (borderRect.getY() + textWidth / 2.0) + AGGR_VAL_LABEL_SPACER;
    }
    final double screenHeight = drawingSpace.getHeight();
    // check if the label is outside of the drawing space
    if (textY + textWidth / 2 > screenHeight) {
        textY = (int) (screenHeight - textWidth / 2.0 - AGGR_VAL_LABEL_SPACER);
    } else if (textY < 0) {
        textY = textWidth / 2 + AGGR_VAL_LABEL_SPACER;
    }
    final int textHeight = metrics.getHeight();
    // calculate the text background rectangle
    final int bgX = textX - AGGR_VAL_BG_SPACER;
    final int bgY = textY - textHeight - AGGR_VAL_BG_SPACER;
    final Rectangle textBackGroundRec = new Rectangle(bgX, bgY, textWidth + 2 * AGGR_VAL_BG_SPACER, textHeight + 2 * AGGR_VAL_BG_SPACER);
    if (showVertical) {
        // rotate 90 degree around the center of the text rectangle
        verticalTrans.rotate(Math.toRadians(90), textBackGroundRec.getCenterX(), textBackGroundRec.getCenterY());
        g2.transform(verticalTrans);
    }
    g2.setPaint(LABEL_RECT_BGR_COLOR);
    g2.fill(textBackGroundRec);
    g2.setPaint(LABEL_RECT_STROKE_COLOR);
    g2.setStroke(LABEL_RECT_STROKE);
    g2.draw(textBackGroundRec);
    // g2.setPaint(rectColor);
    g2.drawString(label, textX, textY);
    // set the original settings
    g2.setTransform(origTransform);
    g2.setFont(origFont);
    g2.setPaint(origPaint);
    g2.setStroke(origStroke);
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) AffineTransform(java.awt.geom.AffineTransform) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) Font(java.awt.Font) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint)

Example 77 with Stroke

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

the class AbstractDrawingPane method paintComponent.

/**
 * Calls the {@link #paintContent(Graphics)} method and then draws the
 * selection rectangle. Also the flag for anti-aliasing is evaluated here.
 *
 * {@inheritDoc}
 */
@Override
protected synchronized void paintComponent(final Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    if (m_antialiasing) {
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    Color backupColor = g2.getColor();
    Stroke backupStroke = g2.getStroke();
    paintContent(g2);
    // restore the original color
    g2.setColor(backupColor);
    // and the original stroke
    g2.setStroke(backupStroke);
    // paint selection rectangle if mouse is down
    if (m_isMouseDown) {
        paintSelectionRectangle(g2);
    }
}
Also used : Stroke(java.awt.Stroke) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 78 with Stroke

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

the class BasicLine method paint.

/**
 * Paints the line by connecting all points.
 *
 * @see org.knime.base.node.viz.plotter.basic.BasicDrawingElement
 * #paint(java.awt.Graphics2D)
 */
@Override
public void paint(final Graphics2D g) {
    Color backupColor = g.getColor();
    Stroke backupStroke = g.getStroke();
    g.setColor(getColor());
    g.setStroke(new BasicStroke(m_lineWidth));
    int[] x = new int[getPoints().size()];
    int[] y = new int[getPoints().size()];
    for (int i = 0; i < getPoints().size(); i++) {
        x[i] = getPoints().get(i).x;
        y[i] = getPoints().get(i).y;
    }
    g.drawPolyline(x, y, getPoints().size());
    g.setColor(backupColor);
    g.setStroke(backupStroke);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Point(java.awt.Point)

Example 79 with Stroke

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

the class ParallelCoordinateDrawingPane method paintContent.

/**
 * {@inheritDoc}
 */
@Override
public void paintContent(final Graphics g) {
    super.paintContent(g);
    Color backupColor = g.getColor();
    Stroke backupStroke = ((Graphics2D) g).getStroke();
    drawAxes(g);
    drawLines(g, m_lines);
    g.setColor(Color.BLACK);
    drawLabels(g);
    ((Graphics2D) g).setStroke(backupStroke);
    g.setColor(backupColor);
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 80 with Stroke

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

the class BasicRectangle method paint.

/**
 * Paints a rectangle defined by two points, the upper-left and lower-right
 * corner.
 *
 * @see org.knime.base.node.viz.plotter.basic.BasicDrawingElement#paint(
 * java.awt.Graphics2D)
 */
@Override
public void paint(final Graphics2D g2) {
    if (getPoints() == null || getPoints().size() < 2) {
        return;
    }
    Color backupColor = g2.getColor();
    Stroke backupStroke = g2.getStroke();
    g2.setColor(getColor());
    g2.setStroke(getStroke());
    Point p1 = getPoints().get(0);
    Point p2 = getPoints().get(1);
    int width = p2.x - p1.x;
    int height = p1.y - p2.y;
    if (isFilled()) {
        g2.fillRect(p1.x, p1.y, width, height);
    } else {
        g2.drawRect(p1.x, p1.y, width, height);
    }
    g2.setColor(backupColor);
    g2.setStroke(backupStroke);
}
Also used : Stroke(java.awt.Stroke) Color(java.awt.Color) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

Stroke (java.awt.Stroke)83 BasicStroke (java.awt.BasicStroke)74 Paint (java.awt.Paint)36 Color (java.awt.Color)34 Graphics2D (java.awt.Graphics2D)30 Point (java.awt.Point)23 GradientPaint (java.awt.GradientPaint)11 Shape (java.awt.Shape)11 Line2D (java.awt.geom.Line2D)11 Point2D (java.awt.geom.Point2D)11 Ellipse2D (java.awt.geom.Ellipse2D)9 Rectangle (java.awt.Rectangle)8 RoundRectangle2D (java.awt.geom.RoundRectangle2D)7 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 Font (java.awt.Font)6 RadialGradientPaint (java.awt.RadialGradientPaint)6 AffineTransform (java.awt.geom.AffineTransform)6 Arc2D (java.awt.geom.Arc2D)5 Rectangle2D (java.awt.geom.Rectangle2D)5 GeneralPath (java.awt.geom.GeneralPath)4