本文整理汇总了Java中java.awt.MultipleGradientPaint.CycleMethod类的典型用法代码示例。如果您正苦于以下问题:Java CycleMethod类的具体用法?Java CycleMethod怎么用?Java CycleMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CycleMethod类属于java.awt.MultipleGradientPaint包,在下文中一共展示了CycleMethod类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPaint
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
/**
* Creates paint for a vertex with given bounds and (inner) colour.
*/
static public Paint createPaint(Rectangle b, Color c) {
// only bother with special paint if the vertex is not too small to notice
if (!GRADIENT_PAINT || b.width < 10 && b.height < 10) {
return c;
} else {
int cx = b.x + b.width / 2;
int cy = b.y + b.height / 2;
int fx = b.x + b.width / 3;
int fy = b.y + 2 * b.height / 3;
int rx = b.width - fx;
int ry = b.height - fy;
float r = (float) Math.sqrt(rx * rx + ry * ry);
Paint newPaint = new RadialGradientPaint(cx, cy, r, fx, fy, new float[] {0f, 1f},
getGradient(c), CycleMethod.NO_CYCLE);
return newPaint;
}
}
示例2: isPaintValid
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的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);
}
示例3: renderAt
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
/**
* The snowflakes are drawn as squares with a circular gradient in the middle.
* That's why they look circular and fuzzy. This is also pretty cheap since it doesn't require blurring and drawing
* squares is fast.
*
* @param x top right corner of snowflake x coordinate
* @param y top right corner of snowflake y coordinate
* @param diameter diameter of snowflake
* @param alpha calculated transparency
*/
@Override
protected void renderAt(double x, double y, double diameter, double alpha) {
Color snowflakeColor = new Color(1.0f, 1.0f, 1.0f, (float) alpha);
if (diameter > 7) {
// Center of snowflake is white with opacity according to the value provided in alpha
float radius = (float) (diameter / 2.0);
Point2D.Float center = new Point2D.Float((float) (x + radius), (float) (y + radius));
Paint paint = new RadialGradientPaint(center, radius, center, GRADIENT_POSITIONS,
new Color[]{snowflakeColor, snowflakeColor, TRANSPARENT_WHITE},
CycleMethod.NO_CYCLE);
g2d.setPaint(paint);
g2d.fillRect((int) x, (int) y, (int) diameter, (int) diameter);
} else if (diameter > 3) {
// for small snowflakes an oval works just fine
g2d.setColor(snowflakeColor);
g2d.fillOval((int) x, (int) y, (int) diameter, (int) diameter);
} else {
// just a rectangle would work for these
g2d.setColor(snowflakeColor);
g2d.fillRect((int) x, (int) y, (int) diameter, (int) diameter);
}
}
示例4: actionPerformed
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == cmbPaint) {
paintType = (PaintType)cmbPaint.getSelectedItem();
} else if (source == cmbCycle) {
cycleMethod = (CycleMethod)cmbCycle.getSelectedItem();
} else if (source == cmbSpace) {
colorSpace = (ColorSpaceType)cmbSpace.getSelectedItem();
} else if (source == cmbShape) {
shapeType = (ShapeType)cmbShape.getSelectedItem();
} else if (source == cmbXform) {
xformType = (XformType)cmbXform.getSelectedItem();
} else if (source == cbAntialias) {
antialiasHint = cbAntialias.isSelected() ?
RenderingHints.VALUE_ANTIALIAS_ON :
RenderingHints.VALUE_ANTIALIAS_OFF;
} else if (source == cbRender) {
renderHint = cbRender.isSelected() ?
RenderingHints.VALUE_RENDER_QUALITY :
RenderingHints.VALUE_RENDER_SPEED;
}
gradientPanel.updatePaint();
}
示例5: paintHighlight
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
@Override
public void paintHighlight(Graphics2D graphics, Component comp, int width,
int height, SubstanceColorScheme colorScheme) {
Graphics2D g2d = (Graphics2D) graphics.create();
Color[] fillColors = new Color[this.fractions.length];
for (int i = 0; i < this.fractions.length; i++) {
fillColors[i] = this.colorQueries[i].query(colorScheme);
}
MultipleGradientPaint gradient = new LinearGradientPaint(0, 0, 0,
height, this.fractions, fillColors, CycleMethod.REPEAT);
g2d.setPaint(gradient);
g2d.fillRect(0, 0, width, height);
g2d.dispose();
}
示例6: paintContourBackground
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
@Override
public void paintContourBackground(Graphics g, Component comp, int width,
int height, Shape contour, boolean isFocused,
SubstanceColorScheme fillScheme, boolean hasShine) {
Graphics2D graphics = (Graphics2D) g.create();
Color[] fillColors = new Color[this.fractions.length];
for (int i = 0; i < this.fractions.length; i++) {
ColorSchemeSingleColorQuery colorQuery = this.colorQueries[i];
fillColors[i] = colorQuery.query(fillScheme);
}
MultipleGradientPaint gradient = new LinearGradientPaint(0, 0, 0,
height, this.fractions, fillColors, CycleMethod.REPEAT);
graphics.setPaint(gradient);
graphics.fill(contour);
graphics.dispose();
}
示例7: calculateGradientPreview
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
private void calculateGradientPreview() {
Color startColor = (Color) gradientStartColorComboBox.getSelectedItem();
Color endColor = (Color) gradientEndColorComboBox.getSelectedItem();
if (startColor != null && endColor != null) {
int width = preview.getWidth() - 1;
ContinuousColorProvider colorProvider = new ContinuousColorProvider(1, width, startColor, endColor, 255, false);
// create paint
float fractions[] = new float[width];
Color colors[] = new Color[width];
for (int i = 0; i < width; ++i) {
float fraction = i / (width - 1.0f);
double fractionValue = 1 + fraction * (width - 1);
colors[i] = colorProvider.getColorForValue(fractionValue);
fractions[i] = fraction;
}
Point leftPoint = new Point(0, 0);
Point rightPoint = new Point(width, 0);
LinearGradientPaint gradient = new LinearGradientPaint(leftPoint, rightPoint, fractions, colors,
CycleMethod.REFLECT);
preview.setGradientPaint(gradient);
preview.repaint();
}
}
示例8: makeLinear
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
private LinearGradientPaint makeLinear(int numColors, boolean alpha) {
float interval = 1.0f / (numColors - 1);
float[] fractions = new float[numColors];
for (int i = 0; i < fractions.length; i++) {
fractions[i] = i * interval;
}
Color[] colors = makeGradientColors(numColors, alpha);
return new LinearGradientPaint(0.0f, 0.0f,
10.0f, 10.0f,
fractions, colors,
CycleMethod.REFLECT);
}
示例9: makeRadial
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
private RadialGradientPaint makeRadial(int numColors, boolean alpha) {
float interval = 1.0f / (numColors - 1);
float[] fractions = new float[numColors];
for (int i = 0; i < fractions.length; i++) {
fractions[i] = i * interval;
}
Color[] colors = makeGradientColors(numColors, alpha);
return new RadialGradientPaint(0.0f, 0.0f, 10.0f,
fractions, colors,
CycleMethod.REFLECT);
}
示例10: isPaintValid
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的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)
{
// we can delegate to the optimized two-color gradient
// codepath, which does not require fragment shader support
return true;
}
return super.isPaintValid(sg2d);
}
示例11: createPaint
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
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;
}
示例12: testOne
import java.awt.MultipleGradientPaint.CycleMethod; //导入依赖的package包/类
private void testOne(BufferedImage refImg, VolatileImage testImg) {
Graphics2D gref = refImg.createGraphics();
Graphics2D gtest = testImg.createGraphics();
Paint paint =
makePaint(PaintType.RADIAL, CycleMethod.REPEAT,
ColorSpaceType.SRGB, XformType.IDENTITY, 7);
Object aahint = hints[0];
renderTest(gref, paint, aahint);
renderTest(gtest, paint, aahint);
Toolkit.getDefaultToolkit().sync();
compareImages(refImg, testImg.getSnapshot(),
TOLERANCE, 0, "");
gref.dispose();
gtest.dispose();
}