use of java.awt.image.Kernel in project openblocks by mikaelhg.
the class CButton method paint.
/**
* re paints this
*/
@Override
public void paint(Graphics g) {
//super.paint(g);
//selected color
Color backgroundColor;
if (this.pressed || this.selected) {
backgroundColor = this.selectedColor;
} else {
backgroundColor = this.buttonColor;
}
// 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;
Color topColoring = backgroundColor.darker();
Color bottomColoring = backgroundColor.darker();
gb.setPaint(new GradientPaint(0, INSET, topColoring, 0, buttonHeight, bottomColoring, false));
// Paint the first layer
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 - (HIGHLIGHT_INSET * 2);
int highlightWidth = buttonWidth - (HIGHLIGHT_INSET * 2);
int highlightArc = highlightHeight;
topColoring = backgroundColor.brighter().brighter().brighter().brighter();
bottomColoring = backgroundColor.brighter().brighter().brighter().brighter();
// Paint the second layer
gb.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .8f));
gb.setPaint(new GradientPaint(0, INSET + HIGHLIGHT_INSET, topColoring, 0, INSET + HIGHLIGHT_INSET + (highlightHeight / 2), backgroundColor.brighter(), false));
gb.setClip(new RoundRectangle2D.Float(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET, highlightWidth, highlightHeight / 2, highlightHeight / 3, highlightHeight / 3));
gb.fillRoundRect(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET, highlightWidth, highlightHeight, highlightArc, highlightArc);
// Blur
ConvolveOp blurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
BufferedImage blurredImage = blurOp.filter(buffer, null);
// Draw button
g2.drawImage(blurredImage, 0, 0, null);
// Draw the text (if any)
if (this.getText() != null) {
if (this.focus) {
g2.setColor(hoveredColor);
} else {
g2.setColor(foregroundColor);
}
Font font = g2.getFont().deriveFont((float) (((float) buttonHeight) * .6));
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();
g2.drawString(this.getText(), x, y);
}
}
use of java.awt.image.Kernel in project openblocks by mikaelhg.
the class CIconButton method paint.
/** Paints this */
@Override
public void paint(Graphics g) {
//selected color
Color backgroundColor;
if (this.pressed) {
backgroundColor = this.selectedColor;
} else {
backgroundColor = this.buttonColor;
}
// 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);
Color topColoring = backgroundColor.darker().darker().darker();
Color bottomColoring = backgroundColor.brighter().brighter().brighter();
gb.setPaint(new GradientPaint(0, INSET, topColoring, 0, buttonHeight, bottomColoring, false));
// Paint the first layer
gb.fillOval(INSET, INSET, buttonWidth, buttonHeight);
// set up paint data fields for second layer
int highlightHeight = buttonHeight - (HIGHLIGHT_INSET * 2);
int highlightWidth = buttonWidth - (HIGHLIGHT_INSET * 2);
topColoring = Color.WHITE;
bottomColoring = backgroundColor.brighter();
// Paint the second layer
gb.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .8f));
gb.setPaint(new GradientPaint(0, INSET + HIGHLIGHT_INSET, topColoring, 0, INSET + HIGHLIGHT_INSET + (highlightHeight / 2), backgroundColor.brighter(), false));
gb.setClip(new Ellipse2D.Float(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET, highlightWidth, highlightHeight / 2));
gb.fillOval(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET, highlightWidth, highlightHeight);
// Blur
ConvolveOp blurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
BufferedImage blurredImage = blurOp.filter(buffer, null);
// Draw button
g2.drawImage(blurredImage, 0, 0, null);
//draw icon
if (this.icon != null) {
if (this.focus) {
g2.setColor(Color.white);
} else {
g2.setColor(Color.gray);
}
g2.fill(this.getIconShape(this.icon));
}
}
use of java.awt.image.Kernel 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.image.Kernel in project jdk8u_jdk by JetBrains.
the class SamePackingTypeTest method createTestOp.
private static BufferedImageOp createTestOp() {
final int size = 1;
final float v = 1f / (size * size);
final float[] k_data = new float[size * size];
Arrays.fill(k_data, v);
Kernel k = new Kernel(size, size, k_data);
return new ConvolveOp(k);
}
use of java.awt.image.Kernel in project jdk8u_jdk by JetBrains.
the class EdgeNoOpCrash method createConvolveOp.
private static ConvolveOp createConvolveOp(int edgeHint) {
final int kw = 3;
final int kh = 3;
float[] kdata = new float[kw * kh];
float v = 1f / kdata.length;
Arrays.fill(kdata, v);
Kernel k = new Kernel(kw, kh, kdata);
ConvolveOp op = new ConvolveOp(k, edgeHint, null);
return op;
}
Aggregations