本文整理匯總了Java中java.awt.GradientPaint類的典型用法代碼示例。如果您正苦於以下問題:Java GradientPaint類的具體用法?Java GradientPaint怎麽用?Java GradientPaint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GradientPaint類屬於java.awt包,在下文中一共展示了GradientPaint類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: paintComponent
import java.awt.GradientPaint; //導入依賴的package包/類
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
g2d.translate(-getX(), -getY());
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.BLUE);
int[] xs = new int[points.length];
int[] ys = new int[points.length];
for (int i = 0; i < points.length; i++) {
xs[i] = points[i].x;
ys[i] = points[i].y;
}
g2d.setColor(UIHelper.getColor("NodeConnection.border"));
g2d.setStroke(new BasicStroke(3));
g2d.drawPolyline(xs, ys, points.length);
g2d.setPaint(new GradientPaint(points[0], UIHelper.getColor("NodeConnection.color1"), points[points.length - 1], UIHelper.getColor("NodeConnection.color2")));
g2d.setStroke(new BasicStroke(1.5f));
g2d.drawPolyline(xs, ys, points.length);
g2d.dispose();
}
示例2: paintComponent
import java.awt.GradientPaint; //導入依賴的package包/類
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
Composite oldC = g2d.getComposite();
Shape s = getMask( getWidth(), getHeight() );
g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.25f*currentAlpha ) );
g2d.setColor( Color.black );
g2d.fill( getShadowMask(s) );
g2d.setColor( UIManager.getColor( "ToolTip.background" ) ); //NOI18N
g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, currentAlpha ) );
Point2D p1 = s.getBounds().getLocation();
Point2D p2 = new Point2D.Double(p1.getX(), p1.getY()+s.getBounds().getHeight());
if( isMouseOverEffect )
g2d.setPaint( new GradientPaint( p2, getMouseOverGradientStartColor(), p1, getMouseOverGradientFinishColor() ) );
else
g2d.setPaint( new GradientPaint( p2, getDefaultGradientStartColor(), p1, getDefaultGradientFinishColor() ) );
g2d.fill(s);
g2d.setColor( Color.black );
g2d.draw(s);
g2d.setComposite( oldC );
}
示例3: paintComponent
import java.awt.GradientPaint; //導入依賴的package包/類
@Override
protected void paintComponent( Graphics g ) {
Graphics2D g2d = ( Graphics2D ) g;
int width = getWidth();
int height = getHeight();
g2d.setColor( Utils.getBorderColor() );
g2d.drawRect( 0, 0, width, 12 );
if( UIManager.getBoolean( "nb.startpage.defaultbackground" ) ) { //NOI18N
g2d.setColor( UIManager.getColor("Tree.background") ); //NOI18N
} else {
g2d.setPaint( new GradientPaint( 0, 0, COL_GRADIENT_START, 0, 12, COL_GRADIENT_END ) );
}
g2d.fillRect( 1, 0, width-2, 12 );
int imgWidth = IMG_BANNER.getWidth( this );
int imgX = (width - imgWidth)/2;
g2d.drawImage( IMG_BANNER, imgX, 13, imgWidth, height-13, this );
if( imgX > 0 ) {
g2d.setPaint( COL_BANNER_LEFT );
g2d.fillRect( 0, 13, imgX, height-13 );
g2d.setPaint( COL_BANNER_RIGHT );
g2d.fillRect( width-imgX-1, 13, imgX+1, height-13 );
}
}
示例4: paintGridOverlay
import java.awt.GradientPaint; //導入依賴的package包/類
/**
* Paints the grid on top of the ticks.
*/
private void paintGridOverlay(Graphics2D g, int w, int h) {
int numCells = GRID_COLORS.length / 2;
int cellSize = (h - numCells - 1) / numCells;
int c1 = 0xD0CCBC;
int c2 = 0xEAE7D7;
g.setPaint(new GradientPaint(
0, 0, new Color((c1 >> 16) & 0xFF, (c1 >> 8) & 0xFF, c1 & 0xFF, 0x30),
0, h, new Color((c2 >> 16) & 0xFF, (c2 >> 8) & 0xFF, c2 & 0xFF, 0x40)));
for (int x = 0; x < w; x += cellSize + 1) {
g.fillRect(x, 0, 1, h);
}
for (int y = h - cellSize - 1; y >= 0; y -= (cellSize + 1)) {
g.fillRect(0, y, w, 1);
}
}
示例5: paintBackgroundTiles
import java.awt.GradientPaint; //導入依賴的package包/類
private void paintBackgroundTiles(Graphics2D g, int w, int h) {
g.translate(1, 2);
w -= BORDER_W;
h -= BORDER_H;
int numCells = GRID_COLORS.length / 2;
int cellSize = (h - numCells - 1) / numCells;
for (int i = 0; i < numCells; i++) {
int colorIndex = i;
int y = h - cellSize * (i + 1) - i;
int x = 1;
g.setPaint(new GradientPaint(0, y, GRID_COLORS[colorIndex * 2],
0, y + cellSize - 1, GRID_COLORS[colorIndex * 2 + 1]));
while (x < w) {
int endX = Math.min(w, x + cellSize);
g.fillRect(x, y, endX - x, cellSize);
x = endX + 1;
}
y += cellSize + 1;
}
g.translate(-1, -2);
}
示例6: paint
import java.awt.GradientPaint; //導入依賴的package包/類
@Override
public void paint(Graphics g) {
int h = this.getHeight();
int w = this.getWidth();
Graphics2D g2 = (Graphics2D) g;
if (this.isPressed) {
g2.setColor(Colors.TABLE_HEADER_BACKGROUND_PRESSED);
} else {
if (this.rollOver) {
g2.setColor(Colors.TABLE_HEADER_BACKGROUND_FOCUS);
} else {
Paint gp = new GradientPaint(0, 0, Colors.TABLE_HEADER_BACKGROUND_GRADIENT_START, 0, h,
Colors.TABLE_HEADER_BACKGROUND_GRADIENT_END);
g2.setPaint(gp);
}
}
g2.fill(createHeaderShape(0, 0, w, h, isLeftmost, isRightmost));
g2.setColor(Colors.TABLE_HEADER_BORDER);
g2.draw(createHeaderShape(0, 0, w, h, isLeftmost, isRightmost));
super.paint(g);
}
示例7: PaintGradiente
import java.awt.GradientPaint; //導入依賴的package包/類
protected void PaintGradiente(Graphics2D g) { //, boolean round) {
int dist = 0;
DimensioneParaPintura();
W -= dist;
H -= dist;
boolean dv = getGDirecao() == VERTICAL;
int type = AlphaComposite.SRC_OVER;
g.setComposite(AlphaComposite.getInstance(type, alfa));
GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + W, dv ? T + H : T, getGradienteEndColor(), true);
g.setPaint(GP);
if (roundrect > 0 && isPintarBorda()) {
g.fillRoundRect(L + 1, T + 1, W, H, roundrect, roundrect);
} else {
g.fillRect(L + 1, T + 1, W, H);
}
}
示例8: WaterfallBarRenderer
import java.awt.GradientPaint; //導入依賴的package包/類
/**
* Constructs a new renderer with default values for the bar colors.
*/
public WaterfallBarRenderer() {
this(
new GradientPaint(
0.0f, 0.0f, new Color(0x22, 0x22, 0xFF),
0.0f, 0.0f, new Color(0x66, 0x66, 0xFF)
),
new GradientPaint(
0.0f, 0.0f, new Color(0x22, 0xFF, 0x22),
0.0f, 0.0f, new Color(0x66, 0xFF, 0x66)
),
new GradientPaint(
0.0f, 0.0f, new Color(0xFF, 0x22, 0x22),
0.0f, 0.0f, new Color(0xFF, 0x66, 0x66)
),
new GradientPaint(
0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22),
0.0f, 0.0f, new Color(0xFF, 0xFF, 0x66)
)
);
}
示例9: drawTitleBar
import java.awt.GradientPaint; //導入依賴的package包/類
private void drawTitleBar(Graphics2D g) {
Graphics2D g2 = (Graphics2D) g.create();
RoundRectangle2D titleBar = createTitleBarShape();
double h = SF * (TITLE_BAR_HEIGHT + CORNER_RADIUS) + 1;
g2.setPaint(new GradientPaint(0, 0, grayColor(GRAY_TOP),
0, (float) h, grayColor(GRAY_BOTTOM)));
g2.fill(titleBar);
g2.setColor(Color.DARK_GRAY);
g2.draw(titleBar);
g2.setColor(Color.BLACK);
int scaledSize = (int) Math.round(SF * TITLE_FONT_SIZE);
g2.setFont(Font.decode(TITLE_FONT_FAMILY + "-" + scaledSize));
FontMetrics fm = g2.getFontMetrics();
int x = (int) Math.round((sw - fm.stringWidth(title)) / 2);
int y = (int) Math.round(SF * (TITLE_BAR_HEIGHT / 2 + TITLE_DY));
g2.drawString(title, x, y);
drawBall(g2, RED_BALL, 0);
drawBall(g2, AMBER_BALL, 1);
drawBall(g2, GREEN_BALL, 2);
g2.dispose();
}
示例10: paintComponent
import java.awt.GradientPaint; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
protected void paintComponent(Graphics graphics) {
// Surchargée pour dessiner le fond avec gradient
final LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
final String lafName = lookAndFeel != null ? lookAndFeel.getName() : null;
if ("Substance".equals(lafName)) {
super.paintComponent(graphics); // le gradient fonctionne mal en substance ?
}
final Color startColor = getBackground();
final Color endColor = GRADIENT_COLOR;
final int w = getWidth();
final int h = getHeight();
// l'image du gradient pourrait être mise en cache, mais ce n'est pas grave
final Paint paint = new GradientPaint(0, h / 2f, startColor, 1, h, endColor, false);
final Graphics2D graphix = (Graphics2D) graphics.create();
graphix.setPaint(paint);
graphix.fillRect(0, 0, w, h);
graphix.dispose();
}
示例11: drawGlassEffect
import java.awt.GradientPaint; //導入依賴的package包/類
/**
* Draws the glass effect
*/
public static void drawGlassEffect(mxGraphics2DCanvas canvas, mxCellState state) {
double size = 0.4;
canvas.getGraphics()
.setPaint(new GradientPaint((float) state.getX(), (float) state.getY(),
new Color(1, 1, 1, 0.9f), (float) (state.getX()),
(float) (state.getY() + state.getHeight() * size), new Color(1, 1, 1, 0.3f)));
float sw = (float) (mxUtils.getFloat(state.getStyle(), mxConstants.STYLE_STROKEWIDTH, 1)
* canvas.getScale() / 2);
GeneralPath path = new GeneralPath();
path.moveTo((float) state.getX() - sw, (float) state.getY() - sw);
path.lineTo((float) state.getX() - sw, (float) (state.getY() + state.getHeight() * size));
path.quadTo((float) (state.getX() + state.getWidth() * 0.5),
(float) (state.getY() + state.getHeight() * 0.7),
(float) (state.getX() + state.getWidth() + sw),
(float) (state.getY() + state.getHeight() * size));
path.lineTo((float) (state.getX() + state.getWidth() + sw), (float) state.getY() - sw);
path.closePath();
canvas.getGraphics().fill(path);
}
示例12: drawUtilizationMulti
import java.awt.GradientPaint; //導入依賴的package包/類
private void drawUtilizationMulti(double U, Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {
double x = getProcessorXY().x, y = getProcessorXY().y;
try {
occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3
- ELEMS_GAP / 2, PROC_RAD - ELEMS_GAP, (PROC_RAD - ELEMS_GAP) * (1 - U / nCpu));
} catch (Exception e) {
occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3
- ELEMS_GAP / 2, PROC_RAD - ELEMS_GAP, 0);
}
occupiedEll = new Ellipse2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3 - ELEMS_GAP / 2,
PROC_RAD - ELEMS_GAP, PROC_RAD - ELEMS_GAP);
if (gradientFill) {
GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + 2 * PROC_RAD), startC.darker(),
false);
g2d.setPaint(gp);
} else {
g2d.setPaint(startC);
}
occupiedArea = new Area(occupiedEll);
occupiedArea.subtract(new Area(occupiedRect));
g2d.fill(occupiedArea);
g2d.setPaint(Color.BLACK);
g2d.draw(occupiedArea);
}
示例13: paintYPin
import java.awt.GradientPaint; //導入依賴的package包/類
private void paintYPin(Graphics2D g, int number) {
double y = top;
for (int i = 0; i < number; i++) {
y += yBounds[i].getSize().getHeight();
}
g.setColor(Color.black);
double max = 6;
g.setPaint(new GradientPaint(new Point2D.Double(LEFT - max, y - max),
Color.green, new Point2D.Double(LEFT + max, y + max),
Color.black));
GeneralPath path1 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4);
GeneralPath path2 = new GeneralPath(Path2D.WIND_EVEN_ODD, 4);
path1.moveTo(LEFT - 5, y);
path1.lineTo(LEFT - 5 - max, y + max / 2);
path1.lineTo(LEFT - 5 - max, y - max / 2);
path1.lineTo(LEFT - 5, y);
path2.moveTo(5 + LEFT + width, y);
path2.lineTo(5 + LEFT + width + max, y + max / 2);
path2.lineTo(5 + LEFT + width + max, y - max / 2);
path2.lineTo(5 + LEFT + width, y);
g.fill(path1);
g.setPaint(new GradientPaint(new Point2D.Double(LEFT + width - max, y
- max), Color.black, new Point2D.Double(LEFT + max + width, y
+ max), Color.green));
g.fill(path2);
g.setColor(Color.gray);
g.draw(path1);
g.draw(path2);
}
示例14: transform
import java.awt.GradientPaint; //導入依賴的package包/類
public Paint transform( Exit exit ) {
Layout<Room, Exit> layout = vv.getGraphLayout();
Pair<Room> pair = layout.getGraph().getEndpoints( exit );
Room begin = pair.getFirst();
Room end = pair.getSecond();
Point2D beginPoint = transformer.transform( layout.transform( begin ) );
Point2D endPoint = transformer.transform( layout.transform( end ) );
float xFirst = (float) beginPoint.getX();
float yFirst = (float) beginPoint.getY();
float xEnd = (float) endPoint.getX();
float yEnd = (float) endPoint.getY();
if (selfLoop.evaluate( Context.<Graph<Room, Exit>, Exit>getInstance( layout.getGraph(), exit ) )) {
xEnd += 50;
yEnd += 50;
}
return new GradientPaint( xFirst, yFirst, getColorFor( begin ), xEnd, yEnd, getColorFor( end ), true );
}
示例15: paintComponent
import java.awt.GradientPaint; //導入依賴的package包/類
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
int cursorX = valueToPosition(value);
GradientPaint gradient = new GradientPaint(0, 0, colorLimitMin, sliderWidth(), 0, colorLimitMax, true);
// slider
g2.setPaint(gradient);
fillSlider(g2);
g2.setColor(Color.black);
drawSlider(g2);
// cursor
Color fillColor = ColorTools.gradiant(colorLimitMin, colorLimitMax, valueAsCoef(value));
drawCursor(g2, fillColor, Color.black, cursorX);
if (drawValue) {
// final String valueAsString = getValueAsString(); //Float.toString(Math.round(value * 10) / 10f);
printStringOnCursor(g2, getValueAsString(), cursorX, true);
}
}