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);
}
}
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);
}
}
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);
}
}
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);
}
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());
}
Aggregations