Search in sources :

Example 61 with Graphics2D

use of java.awt.Graphics2D in project openblocks by mikaelhg.

the class CMenuItem method paint.

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    if (focus) {
        g2.setColor(background);
    } else {
        g.setColor(highlight);
    }
    g2.fillRect(0, 0, this.getWidth(), this.getHeight());
    String text = this.getText();
    if (text != null) {
        Font font = g2.getFont().deriveFont((float) (((float) this.getHeight()) * .8));
        g2.setFont(font);
        FontMetrics metrics = g2.getFontMetrics();
        Rectangle2D textBounds = metrics.getStringBounds(this.getText(), g2);
        double textHeight = textBounds.getHeight();
        double textWidth = textBounds.getWidth() > this.getWidth() ? this.getWidth() / 2 : textBounds.getWidth();
        float y = (float) ((this.getHeight() / 2) + (textHeight / 2)) - metrics.getDescent();
        float x;
        if (textPosition == Position.LEFT) {
            x = 10;
        } else {
            x = (float) ((this.getWidth() / 2) - (textWidth / 2));
        }
        g2.setColor(Color.black);
        g2.drawString(text, x, y);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 62 with Graphics2D

use of java.awt.Graphics2D in project openblocks by mikaelhg.

the class CRadioactiveButton method paint.

@Override
public void paint(Graphics g) {
    // Set up graphics and buffer
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    BufferedImage buffer = GraphicsManager.gc.createCompatibleImage(this.getWidth(), this.getHeight(), Transparency.TRANSLUCENT);
    Graphics2D gb = buffer.createGraphics();
    gb.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Set up first layer
    int buttonHeight = this.getHeight() - INSET * 2;
    int buttonWidth = this.getWidth() - INSET * 2;
    int arc = buttonHeight;
    if (this.pressed || this.selected) {
        g2.setPaint(new GradientPaint(0, -buttonHeight, Color.darkGray, 0, buttonHeight, buttonColor, false));
        g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
        g2.setColor(Color.darkGray);
        g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
    } else {
        //paint highlightlayer
        if (this.focus) {
            gb.setColor(Color.yellow);
            gb.setStroke(new BasicStroke(3));
            gb.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
            gb.setStroke(new BasicStroke(1));
        }
        // Paint the first layer
        gb.setColor(buttonColor.darker());
        gb.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
        gb.setColor(Color.darkGray);
        gb.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
        // set up paint data fields for second layer
        int highlightHeight = buttonHeight * 2 / 3;
        int highlightWidth = buttonWidth;
        int highlightArc = highlightHeight;
        // Paint the second layer
        gb.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .8f));
        gb.setColor(buttonColor);
        gb.setClip(new RoundRectangle2D.Float(INSET, INSET, highlightWidth, highlightHeight, highlightArc, highlightArc));
        gb.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
        // Blur
        ConvolveOp blurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
        BufferedImage blurredImage = blurOp.filter(buffer, null);
        // Draw button
        g2.drawImage(blurredImage, 1, 1, null);
    }
    // Draw the text (if any)
    String text = this.getText();
    if (text != null && buttonHeight > 4) {
        //Font font = g2.getFont().deriveFont((float)(((float)this.getHeight()) * .6));
        Font font = g2.getFont().deriveFont((float) (this.getHeight() - INSET * 2 - 2) * .7f);
        g2.setFont(font);
        FontMetrics metrics = g2.getFontMetrics();
        Rectangle2D textBounds = metrics.getStringBounds(this.getText(), g2);
        float x = (float) ((this.getWidth() / 2) - (textBounds.getWidth() / 2));
        float y = (float) ((this.getHeight() / 2) + (textBounds.getHeight() / 2)) - metrics.getDescent();
        g.setColor(Color.black);
        for (int i = 0; i < shadowPositionArray.length; i++) {
            int dx = shadowPositionArray[i][0];
            int dy = shadowPositionArray[i][1];
            g2.setColor(new Color(0, 0, 0, shadowColorArray[i]));
            g2.drawString(text, x + (int) ((dx) * offsetSize), y + (int) ((dy) * offsetSize));
        }
        g2.setColor(Color.white);
        g2.drawString(text, x, y);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) GradientPaint(java.awt.GradientPaint) BufferedImage(java.awt.image.BufferedImage) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) FontMetrics(java.awt.FontMetrics) ConvolveOp(java.awt.image.ConvolveOp) Kernel(java.awt.image.Kernel)

Example 63 with Graphics2D

use of java.awt.Graphics2D in project openblocks by mikaelhg.

the class CSignLabel method paintComponent.

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    for (int j = 0; j < charSet.length; j++) {
        String c = charSet[j];
        System.out.println(c);
        int x = 5;
        int y = (j + 1) * (FONT_SIZE + 3);
        g.setColor(Color.black);
        for (int i = 0; i < shadowPositionArray.length; i++) {
            int dx = shadowPositionArray[i][0];
            int dy = shadowPositionArray[i][1];
            g2.setColor(new Color(0, 0, 0, shadowColorArray[i]));
            g2.drawString(c, x + (int) ((dx) * offsetSize), y + (int) ((dy) * offsetSize));
        }
        g2.setColor(Color.white);
        g2.drawString(c, x, y);
    }
}
Also used : Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 64 with Graphics2D

use of java.awt.Graphics2D in project openblocks by mikaelhg.

the class CTextField method paint.

@Override
public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    int w = this.getWidth();
    int h = this.getHeight();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.white);
    g2.fillRoundRect(0, 0, w, h, h, h);
    if (mouseover) {
        if (pressed) {
            g2.setColor(new Color(170, 0, 0));
        } else {
            g2.setColor(Color.red);
        }
    } else {
        g2.setColor(Color.pink);
    }
    g2.fill(this.getXBox(w, h));
    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(2));
    g2.draw(this.getXCross(w, h));
    super.paint(g);
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 65 with Graphics2D

use of java.awt.Graphics2D in project openblocks by mikaelhg.

the class RBHighlightHandler method updateImage.

public void updateImage() {
    if (GraphicsEnvironment.isHeadless()) {
        return;
    }
    // cache the focus so it'll know when it needs to redraw later.
    hasFocus = rb.getBlock().hasFocus();
    Color color = null;
    if (hColor != null) {
        color = hColor;
    } else if (rb.getBlock().hasFocus()) {
        //Color.BLUE);
        color = new Color(200, 200, 255);
    } else if (isSearchResult) {
        //Color.YELLOW);
        color = new Color(255, 255, 120);
    } else if (rb.getBlock().isBad()) {
        //Color.RED);
        color = new Color(255, 100, 100);
    } else {
        GraphicsManager.recycleGCCompatibleImage(hImage);
        hImage = null;
        // if we're not highlighting, destroy the image and just return
        return;
    }
    if (!rb.isVisible()) {
        GraphicsManager.recycleGCCompatibleImage(hImage);
        hImage = null;
        // if we're not highlighting, destroy the image and just return
        return;
    }
    hImage = GraphicsManager.getGCCompatibleImage(rb.getBlockWidth() + HIGHLIGHT_STROKE_WIDTH, rb.getBlockHeight() + HIGHLIGHT_STROKE_WIDTH);
    Graphics2D hg = (Graphics2D) hImage.getGraphics();
    hg.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
    hg.setColor(color);
    hg.translate(HIGHLIGHT_STROKE_WIDTH / 2, HIGHLIGHT_STROKE_WIDTH / 2);
    hg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f));
    for (int i = 0; i < HIGHLIGHT_STROKE_WIDTH; i++) {
        hg.setStroke(new BasicStroke(i));
        hg.draw(rb.getBlockArea());
    }
    hg.setColor(new Color(0, 0, 0, 0));
    hg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1));
    hg.fill(rb.getBlockArea());
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) RenderingHints(java.awt.RenderingHints) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

Graphics2D (java.awt.Graphics2D)777 BufferedImage (java.awt.image.BufferedImage)379 Color (java.awt.Color)180 Font (java.awt.Font)77 BasicStroke (java.awt.BasicStroke)75 Rectangle (java.awt.Rectangle)65 Point (java.awt.Point)63 Rectangle2D (java.awt.geom.Rectangle2D)59 AffineTransform (java.awt.geom.AffineTransform)55 GradientPaint (java.awt.GradientPaint)48 Dimension (java.awt.Dimension)46 Paint (java.awt.Paint)44 FontMetrics (java.awt.FontMetrics)35 IOException (java.io.IOException)33 Graphics (java.awt.Graphics)31 Stroke (java.awt.Stroke)30 Image (java.awt.Image)29 RadialGradientPaint (java.awt.RadialGradientPaint)26 VolatileImage (java.awt.image.VolatileImage)26 File (java.io.File)26