Search in sources :

Example 1 with Value

use of javax.swing.text.html.CSS.Value in project jdk8u_jdk by JetBrains.

the class CSSBorder method paintBorder.

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (!(g instanceof Graphics2D)) {
        return;
    }
    Graphics2D g2 = (Graphics2D) g.create();
    int[] widths = getWidths();
    // Position and size of the border interior.
    int intX = x + widths[LEFT];
    int intY = y + widths[TOP];
    int intWidth = width - (widths[RIGHT] + widths[LEFT]);
    int intHeight = height - (widths[TOP] + widths[BOTTOM]);
    // Coordinates of the interior corners, from NW clockwise.
    int[][] intCorners = { { intX, intY }, { intX + intWidth, intY }, { intX + intWidth, intY + intHeight }, { intX, intY + intHeight } };
    // Draw the borders for all sides.
    for (int i = 0; i < 4; i++) {
        Value style = getBorderStyle(i);
        Polygon shape = getBorderShape(i);
        if ((style != Value.NONE) && (shape != null)) {
            int sideLength = (i % 2 == 0 ? intWidth : intHeight);
            // "stretch" the border shape by the interior area dimension
            shape.xpoints[2] += sideLength;
            shape.xpoints[3] += sideLength;
            Color color = getBorderColor(i);
            BorderPainter painter = getBorderPainter(i);
            double angle = i * Math.PI / 2;
            // Restore initial clip
            g2.setClip(g.getClip());
            g2.translate(intCorners[i][0], intCorners[i][1]);
            g2.rotate(angle);
            g2.clip(shape);
            painter.paint(shape, g2, color, i);
            g2.rotate(-angle);
            g2.translate(-intCorners[i][0], -intCorners[i][1]);
        }
    }
    g2.dispose();
}
Also used : Color(java.awt.Color) CssValue(javax.swing.text.html.CSS.CssValue) LengthValue(javax.swing.text.html.CSS.LengthValue) BorderWidthValue(javax.swing.text.html.CSS.BorderWidthValue) Value(javax.swing.text.html.CSS.Value) ColorValue(javax.swing.text.html.CSS.ColorValue) Polygon(java.awt.Polygon) Graphics2D(java.awt.Graphics2D)

Aggregations

Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Polygon (java.awt.Polygon)1 BorderWidthValue (javax.swing.text.html.CSS.BorderWidthValue)1 ColorValue (javax.swing.text.html.CSS.ColorValue)1 CssValue (javax.swing.text.html.CSS.CssValue)1 LengthValue (javax.swing.text.html.CSS.LengthValue)1 Value (javax.swing.text.html.CSS.Value)1