本文整理汇总了Java中java.awt.LinearGradientPaint类的典型用法代码示例。如果您正苦于以下问题:Java LinearGradientPaint类的具体用法?Java LinearGradientPaint怎么用?Java LinearGradientPaint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinearGradientPaint类属于java.awt包,在下文中一共展示了LinearGradientPaint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCustomLcdBackgroundPaint
import java.awt.LinearGradientPaint; //导入依赖的package包/类
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
final Point2D FOREGROUND_START = new Point2D.Double(0.0, LCD.getMinY() + 1.0);
final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, LCD.getMaxY() - 1);
if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
}
final float[] FOREGROUND_FRACTIONS = {
0.0f,
0.03f,
0.49f,
0.5f,
1.0f
};
final Color[] FOREGROUND_COLORS = {
LCD_COLORS[0],
LCD_COLORS[1],
LCD_COLORS[2],
LCD_COLORS[3],
LCD_COLORS[4]
};
return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
示例2: Push
import java.awt.LinearGradientPaint; //导入依赖的package包/类
public Push() {
setUndecorated(true);
setSize(300, 100);
this.setAlwaysOnTop(true);
// size of the screen
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// height of the task bar
final Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(
getGraphicsConfiguration());
final int taskBarSize = scnMax.bottom;
setLocation(screenSize.width - getWidth(), screenSize.height - taskBarSize
- getHeight());
// background paint
lpg = new LinearGradientPaint(0, 0, 0, getHeight() / 2, new float[] { 0f,
0.3f, 1f }, new Color[] { new Color(0.8f, 0.8f, 1f),
new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f) });
// blue background panel
setContentPane(new BackgroundPanel());
}
示例3: paint
import java.awt.LinearGradientPaint; //导入依赖的package包/类
public void paint(Graphics2D g, Rectangle dirtyArea, ChartContext context) {
if (gradient || selection) {
int rowsCount = chart.getRowsCount();
for (int i = 0; i < rowsCount; i++) {
TimelineChart.Row row = chart.getRow(i);
ChartContext rowContext = row.getContext();
int y = Utils.checkedInt(rowContext.getViewportOffsetY());
int h = Utils.checkedInt(rowContext.getViewportHeight() - 1);
if (gradient) {
g.setPaint(new LinearGradientPaint(0, y, 0, y + h, FRACTIONS, COLORS));
g.fillRect(0, y, chart.getWidth(), h);
}
if (selection && chart.isRowSelected(row)) {
g.setColor(SELECTED_FILTER);
g.fillRect(0, y, chart.getWidth(), h);
}
}
}
}
示例4: drawIcon
import java.awt.LinearGradientPaint; //导入依赖的package包/类
@Override
public void drawIcon(Graphics2D g2, int width, int height, int percentage) {
// prepare background
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, width, height);
// 0-50 % is the same color, only the last 50% fade into red
Color startColor = new Color(0f, .5f, 0, 0.7f);
g2.setColor(startColor);
g2.setPaint(new LinearGradientPaint(width / 2, 0f, width, 0f, new float[] { 0f, 0.5f, 1f }, new Color[] {
new Color(0f, .5f, 0, 0.7f), new Color(1f, 1f, 0f, 0.7f), new Color(1f, 0, 0, 0.7f) }));
g2.fillRect(0, 0, (int) (percentage / 100d * width), height);
// draw border
g2.setColor(Color.GRAY);
g2.drawRect(0, 0, width - 1, height - 1);
g2.dispose();
}
示例5: isPaintValid
import java.awt.LinearGradientPaint; //导入依赖的package包/类
@Override
boolean isPaintValid(SunGraphics2D sg2d) {
LinearGradientPaint paint = (LinearGradientPaint)sg2d.paint;
if (paint.getFractions().length == 2 &&
paint.getCycleMethod() != CycleMethod.REPEAT &&
paint.getColorSpace() != ColorSpaceType.LINEAR_RGB)
{
D3DSurfaceData dstData = (D3DSurfaceData)sg2d.surfaceData;
D3DGraphicsDevice gd = (D3DGraphicsDevice)
dstData.getDeviceConfiguration().getDevice();
if (gd.isCapPresent(CAPS_LCD_SHADER)) {
// we can delegate to the optimized two-color gradient
// codepath, which should be faster
return true;
}
}
return super.isPaintValid(sg2d);
}
示例6: createCustomLcdBackgroundPaint
import java.awt.LinearGradientPaint; //导入依赖的package包/类
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
final Point2D FOREGROUND_START = new Point2D.Double(0.0, 1.0);
final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, getHeight() - 1);
if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
}
final float[] FOREGROUND_FRACTIONS = {
0.0f,
0.03f,
0.49f,
0.5f,
1.0f
};
final Color[] FOREGROUND_COLORS = {
LCD_COLORS[0],
LCD_COLORS[1],
LCD_COLORS[2],
LCD_COLORS[3],
LCD_COLORS[4]
};
return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
示例7: createCustomLcdBackgroundPaint
import java.awt.LinearGradientPaint; //导入依赖的package包/类
@Override
public java.awt.Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
final Point2D FOREGROUND_START = new Point2D.Double(0.0, LCD.getMinY() + 1.0);
final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, LCD.getMaxY() - 1);
if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
}
final float[] FOREGROUND_FRACTIONS = {
0.0f,
0.03f,
0.49f,
0.5f,
1.0f
};
final Color[] FOREGROUND_COLORS = {
LCD_COLORS[0],
LCD_COLORS[1],
LCD_COLORS[2],
LCD_COLORS[3],
LCD_COLORS[4]
};
return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
示例8: WoodTexture
import java.awt.LinearGradientPaint; //导入依赖的package包/类
private WoodTexture() {
Color c0 = new Color(231, 190, 106);
Color c1 = new Color(232, 185, 96);
Color c2 = new Color(216, 168, 82);
Point2D start = new Point2D.Float(0, 0);
Point2D end = new Point2D.Float(100, 10);
float[] dist = {0.0f, 0.6f, 1.0f};
Color[] colors = {c0, c1, c2};
LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors);
texture = new BufferedImage(100, 10, BufferedImage.TYPE_INT_RGB);
Graphics2D g = texture.createGraphics();
g.setPaint(p);
g.fill(new Rectangle2D.Double(0, 0, 100, 10));
}
示例9: getFlatGradient
import java.awt.LinearGradientPaint; //导入依赖的package包/类
/**
* Creates a flat version of the current gradient. This is a linear gradient
* from 0.0 to length,0. This gradient is suitable for drawing previews of
* the real gradient.
*
* @param length
* @return a gradient Paint with values between 0.0 and length
*/
private MultipleGradientPaint getFlatGradient(JXGradientChooser chooser, double length) {
MultipleGradientPaint gp = chooser.getGradient();
// set up the data for the gradient
float[] fractions = gp.getFractions();
Color[] colors = gp.getColors();
// fill in the gradient
Point2D start = new Point2D.Float(0, 0);
Point2D end = new Point2D.Float((float) length, 0);
MultipleGradientPaint paint = new LinearGradientPaint(
(float) start.getX(),
(float) start.getY(),
(float) end.getX(),
(float) end.getY(),
fractions, colors);
return paint;
}
示例10: createGradientImage
import java.awt.LinearGradientPaint; //导入依赖的package包/类
private BufferedImage createGradientImage(Color... colors)
{
final float[] fractions = new float[colors.length];
final float step = 1.0F / colors.length;
for (int i = 0; i < colors.length; i++)
{
fractions[i] = i * step;
}
final LinearGradientPaint gradient = new LinearGradientPaint(0, 0, 256, 1, fractions, colors, MultipleGradientPaint.CycleMethod.REPEAT);
final BufferedImage bi = new BufferedImage(256, 1, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = bi.createGraphics();
try
{
g.setPaint(gradient);
g.fillRect(0, 0, 256, 1);
}
finally
{
g.dispose();
}
return bi;
}
示例11: paintComponent
import java.awt.LinearGradientPaint; //导入依赖的package包/类
@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
Graphics2D g2d = (Graphics2D) graphics;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Point2D start = new Point2D.Float(0, 0);
Point2D end = new Point2D.Float(0, getHeight());
float[] dist = { 0.0f, 0.8f, .95f, 1f };
Color bg = getBackground();
Color bgd = getBackground().darker();
Color[] colors = { bgd, bg, bgd, bgd.darker() };
LinearGradientPaint gp1 = new LinearGradientPaint(start, end, dist, colors);
g2d.setPaint(gp1);
g2d.fillRect(0, 0, getWidth(), getHeight());
}
示例12: getGradient
import java.awt.LinearGradientPaint; //导入依赖的package包/类
/**
* Gets the gradient.
*
* @param colors the colors
* @param steps the steps
* @return the gradient
*/
private int[] getGradient(Color[] colors, int steps) {
// Draw the gradient to a buffered image
Point2D start = new Point2D.Float(0, 0);
Point2D end = new Point2D.Float(1, steps);
float[] dist = new float[colors.length];
for (int i = 0; i < dist.length; i++) {
dist[i] = (1.0f / dist.length) * i;
}
LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors);
BufferedImage legend = new BufferedImage(1, steps, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) legend.getGraphics();
g2d.setPaint(p);
g2d.drawRect(0, 0, 1, steps);
g2d.dispose();
// Convert to color array
int[] result = new int[steps];
for (int y = 0; y < steps; y++) {
result[y] = legend.getRGB(0, y);
}
// Return
return result;
}
示例13: getGui
import java.awt.LinearGradientPaint; //导入依赖的package包/类
public Gui getGui() {
return new Gui() {
@Override
public void render(Graphics2D g2d, int width, int height) {
LinearGradientPaint gradient = new LinearGradientPaint(0, 0, 0, 100, new float[]{0,1}, new Color[]{new Color(0x666666),new Color(0x444444)});
g2d.setPaint(gradient);
g2d.fillRect(0, 0, width, 100);
g2d.setColor(new Color(0x666666));
g2d.fillRect(0, 100, width, height - 100);
g2d.setColor(Color.WHITE);
g2d.setFont(Client.instance.translation.font.deriveFont(Font.BOLD, 35F));
g2d.drawString(name, 50, 50);
g2d.setFont(Client.instance.translation.font.deriveFont(Font.BOLD, 18F));
g2d.setColor(Color.GRAY);
g2d.drawString(ip, 50, 75);
if(ping >= 0) {
if(ping == 0)
g2d.setColor(Color.RED.darker());
g2d.drawString(ping == 0 ? Client.instance.translation.translate("protocol.timeout") : ping + "ms", 50, 95);
}
}
};
}
示例14: doPaintBackground
import java.awt.LinearGradientPaint; //导入依赖的package包/类
private void doPaintBackground(Graphics2D graphics2D, int x, int y, int width, int height) {
Color color = Colors.darker(Color.decode("#006699"), 64, 64, 64);
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Paint paint = graphics2D.getPaint();
float startX = x;
float startY = y;
float endX = x;
float endY = y + height - 1;
Color[] colors = new Color[4];
colors[0] = Colors.brighter(color, 32, 32, 32);
colors[1] = Colors.darker(color, 16, 16, 16);
colors[2] = Colors.darker(color, 16, 16, 16);
colors[3] = Colors.darker(color, 16, 16, 16);
graphics2D.setPaint(new LinearGradientPaint(startX, startY, endX, endY, fractions, colors));
graphics2D.fillRoundRect(x, y, width - 1, height - 1, 2, 2);
graphics2D.setColor(Colors.brighter(color, 32, 32, 32));
graphics2D.setStroke(stroke);
graphics2D.drawRoundRect(x, y, width - 1, height - 1, 2, 2);
graphics2D.setPaint(paint);
}
示例15: getAsText
import java.awt.LinearGradientPaint; //导入依赖的package包/类
public String getAsText() {
if (null == getValue()) return null;
LinearGradientPaint p = (LinearGradientPaint) getValue();
return new StringBuilder()
.append(p.getStartPoint().getX())
.append(", ")
.append(p.getStartPoint().getY())
.append(", ")
.append(p.getEndPoint().getX())
.append(", ")
.append(p.getEndPoint().getY())
.append(", ")
.append(formatFractions(p.getFractions()))
.append(", ")
.append(formatColors(p.getColors()))
.append(", ")
.append(p.getCycleMethod().name())
.toString();
}