use of java.awt.GradientPaint in project AuthMeReloaded by AuthMe.
the class ImageGenerator method generateImage.
/**
* Method generateImage.
*
* @return BufferedImage
*/
public BufferedImage generateImage() {
BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D graphics = image.createGraphics();
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, 200, 40);
GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true);
graphics.setPaint(gradientPaint);
Font font = new Font("Comic Sans MS", Font.BOLD, 30);
graphics.setFont(font);
graphics.drawString(pass, 5, 30);
graphics.dispose();
image.flush();
return image;
}
use of java.awt.GradientPaint in project jdk8u_jdk by JetBrains.
the class TransformedPaintTest method createPaint.
private Paint createPaint(PaintType type, int startx, int starty, int w, int h) {
// make sure that the blue color doesn't show up when filling a
// w by h rect
w++;
h++;
int endx = startx + w;
int endy = starty + h;
Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
switch(type) {
case COLOR:
return Color.red;
case GRADIENT:
return new GradientPaint(startx, starty, Color.red, endx, endy, Color.green);
case LINEAR_GRADIENT:
return new LinearGradientPaint(startx, starty, endx, endy, new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue });
case RADIAL_GRADIENT:
return new RadialGradientPaint(startx, starty, (float) Math.sqrt(w * w + h * h), new float[] { 0.0f, 0.999f, 1.0f }, new Color[] { Color.red, Color.green, Color.blue }, CycleMethod.NO_CYCLE);
case TEXTURE:
{
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
g.fillRect(0, 0, w, h);
return new TexturePaint(bi, r);
}
}
return Color.green;
}
use of java.awt.GradientPaint in project ACS by ACS-Community.
the class LogoPanel method paintComponent.
@Override
protected void paintComponent(Graphics g) {
try {
int w = getWidth();
int h = getHeight();
// optimization: reuse GradientPaint if possible
if (gradientPaint == null || w != oldW || h != oldH) {
gradientPaint = new GradientPaint(0, 0, startcolor, w, h, endcolor, false);
oldW = w;
oldH = h;
}
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(gradientPaint);
g2.fillRect(0, 0, w, h);
} catch (InternalError exc) {
// sometimes (but rarely), there's an error in g2.fillRect():
/* java.lang.InternalError: MaskFill can only fill with colors
* at sun.java2d.loops.MaskFill.makePrimitive(MaskFill.java:120)
*/
}
super.paintComponent(g);
}
use of java.awt.GradientPaint in project adempiere by adempiere.
the class CompiereUtils method paint3Deffect.
// paint3Deffect
/**
* Paint 3D effect in (lighten in upper half, darken in lowerhalf)
* (called from paint methods)
*
* @param g2D Graphics
* @param c Component
* @param round paint round corners
* @param out paint sticking out (not pressed)
*/
public static void paint3Deffect(Graphics2D g2D, JComponent c, boolean round, boolean out) {
// paint upper gradient
GradientPaint topPaint = null;
if (out)
topPaint = new GradientPaint(0, 0, COL_1TOP, 0, c.getHeight() / 2, COL_1END);
else
topPaint = new GradientPaint(0, 0, COL_2END, 0, c.getHeight() / 2, COL_2TOP);
g2D.setPaint(topPaint);
//
RectangularShape topRec = null;
if (round)
topRec = new RoundRectangle2D.Float(0, 0, c.getWidth(), c.getHeight() / 2, 15, 15);
else
topRec = new Rectangle(0, 0, c.getWidth(), c.getHeight() / 2);
g2D.fill(topRec);
// paint lower gradient
GradientPaint endPaint = null;
if (out)
endPaint = new GradientPaint(0, c.getHeight() / 2, COL_2TOP, 0, c.getHeight(), COL_2END);
else
endPaint = new GradientPaint(0, c.getHeight() / 2, COL_1END, 0, c.getHeight(), COL_1TOP);
g2D.setPaint(endPaint);
//
RectangularShape endRec = null;
if (round)
endRec = new RoundRectangle2D.Float(0, c.getHeight() / 2, c.getWidth(), c.getHeight() / 2, 15, 15);
else
endRec = new Rectangle(0, c.getHeight() / 2, c.getWidth(), c.getHeight() / 2);
g2D.fill(endRec);
}
use of java.awt.GradientPaint in project adempiere by adempiere.
the class CompiereUtils method paint3Deffect.
/**
* Paint 3D effect in (lighten in upper half, darken in lowerhalf)
* (called from paint methods)
*
* @param g2D Graphics
* @param r Ractangle
* @param round paint round corners
* @param out paint sticking out (not pressed)
*/
public static void paint3Deffect(Graphics2D g2D, Rectangle r, boolean round, boolean out) {
// paint upper gradient
GradientPaint topPaint = null;
if (out)
topPaint = new GradientPaint(r.x, r.y, COL_1TOP, r.x, r.y + r.height / 2, COL_1END);
else
topPaint = new GradientPaint(r.x, r.y, COL_2END, r.x, r.y + r.height / 2, COL_2TOP);
g2D.setPaint(topPaint);
//
RectangularShape topRec = null;
if (round)
topRec = new RoundRectangle2D.Float(r.x, r.y, r.width, r.height / 2, 15, 15);
else
topRec = new Rectangle(r.x, r.y, r.width, r.height / 2);
g2D.fill(topRec);
// paint lower gradient
// upper left corner to lower left
GradientPaint endPaint = null;
if (out)
endPaint = new GradientPaint(r.x, r.y + r.height / 2, COL_2TOP, r.x, r.y + r.height, COL_2END);
else
endPaint = new GradientPaint(r.x, r.y + r.height / 2, COL_1END, r.x, r.y + r.height, COL_1TOP);
g2D.setPaint(endPaint);
//
RectangularShape endRec = null;
if (round)
endRec = new RoundRectangle2D.Float(r.x, r.y + r.height / 2, r.width, r.height / 2, 15, 15);
else
endRec = new Rectangle(r.x, r.y + r.height / 2, r.width, r.height / 2);
g2D.fill(endRec);
}
Aggregations