use of java.awt.GradientPaint in project openblocks by mikaelhg.
the class CBorderlessButton method paint.
/**
* re paints this
*/
@Override
public void paint(Graphics g) {
// Set up graphics and buffer
//super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set up first layer
int buttonHeight = this.getHeight() - (INSET * 2);
int buttonWidth = this.getWidth() - (INSET * 2);
if (this.focus) {
int arc = buttonHeight / 3;
Color topColoring;
Color bottomColoring;
if (this.pressed || this.selected) {
topColoring = this.selectedColor.darker();
bottomColoring = CGraphite.blue;
} else {
topColoring = this.buttonColor;
bottomColoring = this.buttonColor;
}
// Paint the first layer
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
g2.setColor(Color.darkGray);
g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
// set up paint data fields for second layer
int highlightHeight = buttonHeight / 2 - HIGHLIGHT_INSET;
int highlightWidth = buttonWidth - (HIGHLIGHT_INSET * 2) + 1;
if (this.pressed || this.selected) {
topColoring = Color.white;
bottomColoring = this.selectedColor;
} else {
topColoring = Color.white;
bottomColoring = Color.darkGray;
}
// Paint the second layer
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRoundRect(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET + 1, highlightWidth, highlightHeight, arc, arc);
}
// Draw the text (if any)
if (this.getText() != null) {
g2.setColor(Color.white);
Font font = g2.getFont().deriveFont((float) (((float) buttonHeight) * .5));
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.GradientPaint 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.GradientPaint in project openblocks by mikaelhg.
the class CGraphiteButton method paint.
/**
* re paints this
*/
@Override
public void paint(Graphics g) {
// Set up graphics and buffer
//super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.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 / 3;
Color topColoring;
Color bottomColoring;
if (this.pressed || this.selected) {
if (this.focus) {
topColoring = this.selectedColor.darker().darker().darker();
bottomColoring = CGraphite.blue;
} else {
topColoring = CGraphite.blue.darker().darker().darker();
bottomColoring = CGraphite.blue;
}
} else {
if (this.focus) {
topColoring = this.buttonColor;
bottomColoring = Color.darkGray;
} else {
topColoring = this.buttonColor;
bottomColoring = this.buttonColor;
}
}
// Paint the first layer
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
g2.setColor(Color.darkGray);
g2.drawRoundRect(INSET, INSET, buttonWidth, buttonHeight, arc, arc);
// set up paint data fields for second layer
int highlightHeight = buttonHeight / 2 - HIGHLIGHT_INSET;
int highlightWidth = buttonWidth - (HIGHLIGHT_INSET * 2) + 1;
if (this.pressed || this.selected) {
if (this.focus) {
topColoring = Color.white;
bottomColoring = this.selectedColor;
} else {
topColoring = Color.white;
bottomColoring = this.selectedColor;
}
} else {
if (this.focus) {
topColoring = Color.white;
bottomColoring = Color.darkGray;
} else {
topColoring = Color.gray;
bottomColoring = Color.darkGray;
}
}
// Paint the second layer
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRoundRect(INSET + HIGHLIGHT_INSET, INSET + HIGHLIGHT_INSET + 1, highlightWidth, highlightHeight, arc, arc);
// Draw the text (if any)
if (this.getText() != null) {
if (this.focus) {
g2.setColor(Color.white);
} else {
g2.setColor(Color.white);
}
Font font = g2.getFont().deriveFont((float) (((float) buttonHeight) * .4));
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.GradientPaint in project openblocks by mikaelhg.
the class CGraphiteSquareButton method paint.
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set up first layer
int buttonHeight = this.getHeight();
int buttonWidth = this.getWidth();
Color topColoring;
Color bottomColoring;
if (this.pressed || this.selected) {
if (this.focus) {
topColoring = this.selectedColor.darker().darker().darker();
bottomColoring = this.selectedColor;
} else {
topColoring = this.selectedColor.darker().darker().darker();
bottomColoring = this.selectedColor;
}
} else {
if (this.focus) {
topColoring = this.buttonColor;
bottomColoring = Color.darkGray;
} else {
topColoring = this.buttonColor;
bottomColoring = this.buttonColor;
}
}
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRect(0, 0, buttonWidth, buttonHeight);
// set up paint data fields for second layer
int highlightHeight = buttonHeight / 2 - HIGHLIGHT_INSET;
int highlightWidth = buttonWidth;
if (this.pressed || this.selected) {
if (this.focus) {
topColoring = Color.white;
bottomColoring = this.selectedColor;
} else {
topColoring = Color.white;
bottomColoring = this.selectedColor;
}
} else {
if (this.focus) {
topColoring = Color.white;
bottomColoring = Color.darkGray;
} else {
topColoring = Color.gray;
bottomColoring = Color.darkGray;
}
}
g2.setPaint(new GradientPaint(0, 0, topColoring, 0, buttonHeight, bottomColoring, false));
g2.fillRect(0, 0, highlightWidth, highlightHeight);
//set border
g2.setColor(Color.DARK_GRAY);
g2.setStroke(new BasicStroke(2));
g2.drawRect(0, 0, buttonWidth - 1, buttonHeight - 1);
// Draw the text (if any)
if (this.getText() != null) {
g2.setColor(Color.white);
Font font = g2.getFont().deriveFont((float) (((float) buttonHeight) * .3));
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.GradientPaint 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));
}
}
Aggregations