下面列出了怎么用java.awt.GradientPaint的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Serialize an instance, restore it, and check for equality.
*/
@Test
public void testSerialization() {
// test a default instance
DialCap c1 = new DialCap();
DialCap c2 = (DialCap) TestUtilities.serialised(c1);
assertEquals(c1, c2);
// test a custom instance
c1 = new DialCap();
c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue,
3.0f, 4.0f, Color.green));
c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.white,
3.0f, 4.0f, Color.gray));
c1.setOutlineStroke(new BasicStroke(2.0f));
c2 = (DialCap) TestUtilities.serialised(c1);
assertEquals(c1, c2);
}
/**
* A test for the equals() method.
*/
@Test
public void testEquals() {
LookupPaintScale g1 = new LookupPaintScale();
LookupPaintScale g2 = new LookupPaintScale();
assertTrue(g1.equals(g2));
assertTrue(g2.equals(g1));
g1 = new LookupPaintScale(1.0, 2.0, Color.red);
assertFalse(g1.equals(g2));
g2 = new LookupPaintScale(1.0, 2.0, Color.red);
assertTrue(g1.equals(g2));
g1.add(1.5, new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.blue));
assertFalse(g1.equals(g2));
g2.add(1.5, new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.blue));
assertTrue(g1.equals(g2));
}
/**
* Confirm that cloning works.
*/
@Test
public void testCloning() throws CloneNotSupportedException {
XYPlot plot = new XYPlot();
Rectangle2D bounds1 = new Rectangle2D.Double(10.0, 20.0, 30.0, 40.0);
LegendTitle t1 = new LegendTitle(plot);
t1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
4.0f, Color.yellow));
t1.setBounds(bounds1);
LegendTitle t2 = (LegendTitle) t1.clone();
assertTrue(t1 != t2);
assertTrue(t1.getClass() == t2.getClass());
assertTrue(t1.equals(t2));
// check independence
bounds1.setFrame(40.0, 30.0, 20.0, 10.0);
assertFalse(t1.equals(t2));
t2.setBounds(new Rectangle2D.Double(40.0, 30.0, 20.0, 10.0));
assertTrue(t1.equals(t2));
}
/**
*
*/
public void paintComponent(Graphics g)
{
if (gradientColor == null)
{
super.paintComponent(g);
}
else
{
Rectangle rect = getVisibleRect();
if (g.getClipBounds() != null)
{
rect = rect.intersection(g.getClipBounds());
}
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(new GradientPaint(0, 0, getBackground(), getWidth(), 0,
gradientColor));
g2.fill(rect);
}
}
/**
* Serialize an instance, restore it, and check for equality.
*/
@Test
public void testSerialization1() {
MeterPlot p1 = new MeterPlot(null);
p1.setDialBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
p1.setDialOutlinePaint(new GradientPaint(4.0f, 3.0f, Color.red,
2.0f, 1.0f, Color.blue));
p1.setNeedlePaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
p1.setTickLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
p1.setTickPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
MeterPlot p2 = (MeterPlot) TestUtilities.serialised(p1);
assertEquals(p1, p2);
}
/**
* Check that the equals() method distinguishes all fields.
*/
@Test
public void testEquals() {
MinMaxCategoryRenderer r1 = new MinMaxCategoryRenderer();
MinMaxCategoryRenderer r2 = new MinMaxCategoryRenderer();
assertEquals(r1, r2);
r1.setDrawLines(true);
assertFalse(r1.equals(r2));
r2.setDrawLines(true);
assertTrue(r1.equals(r2));
r1.setGroupPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.yellow));
assertFalse(r1.equals(r2));
r2.setGroupPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.yellow));
assertTrue(r1.equals(r2));
r1.setGroupStroke(new BasicStroke(1.2f));
assertFalse(r1.equals(r2));
r2.setGroupStroke(new BasicStroke(1.2f));
assertTrue(r1.equals(r2));
}
@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 );
}
/**
* Test that the equals() method distinguishes all fields.
*/
@Test
public void testEquals() {
StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
StackedXYAreaRenderer r2 = new StackedXYAreaRenderer();
assertEquals(r1, r2);
assertEquals(r2, r1);
r1.setShapePaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
3.0f, 4.0f, Color.green));
assertFalse(r1.equals(r2));
r2.setShapePaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
3.0f, 4.0f, Color.green));
assertTrue(r1.equals(r2));
Stroke s = new BasicStroke(1.23f);
r1.setShapeStroke(s);
assertFalse(r1.equals(r2));
r2.setShapeStroke(s);
assertTrue(r1.equals(r2));
}
/**
* Basic checks for cloning.
*/
@Test
public void testCloning() throws CloneNotSupportedException {
CrosshairOverlay o1 = new CrosshairOverlay();
o1.addDomainCrosshair(new Crosshair(99.9));
o1.addRangeCrosshair(new Crosshair(1.23, new GradientPaint(1.0f, 2.0f,
Color.red, 3.0f, 4.0f, Color.blue), new BasicStroke(1.1f)));
CrosshairOverlay o2 = (CrosshairOverlay) o1.clone();
assertTrue(o1 != o2);
assertTrue(o1.getClass() == o2.getClass());
assertTrue(o1.equals(o2));
o1.addDomainCrosshair(new Crosshair(3.21));
o1.addRangeCrosshair(new Crosshair(4.32));
assertFalse(o1.equals(o2));
}
/**
* Serialize an instance, restore it, and check for equality.
*/
@Test
public void testSerialization() {
// test a default instance
DialTextAnnotation a1 = new DialTextAnnotation("A1");
DialTextAnnotation a2 = (DialTextAnnotation) TestUtilities.serialised(a1);
assertEquals(a1, a2);
// test a custom instance
a1 = new DialTextAnnotation("A1");
a1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.blue));
a2 = (DialTextAnnotation) TestUtilities.serialised(a1);
assertEquals(a1, a2);
}
/**
* Sets the Paint in the current graphics state.
* @param paint The Paint object to be used to generate color in
* the rendering process.
* @see java.awt.Graphics#setColor
* @see GradientPaint
* @see TexturePaint
*/
public void setPaint(Paint paint) {
if (paint instanceof Color) {
setColor((Color) paint);
return;
}
if (paint == null || this.paint == paint) {
return;
}
this.paint = paint;
if (imageComp == CompositeType.SrcOverNoEa) {
// special case where compState depends on opacity of paint
if (paint.getTransparency() == Transparency.OPAQUE) {
if (compositeState != COMP_ISCOPY) {
compositeState = COMP_ISCOPY;
}
} else {
if (compositeState == COMP_ISCOPY) {
compositeState = COMP_ALPHA;
}
}
}
Class<? extends Paint> paintClass = paint.getClass();
if (paintClass == GradientPaint.class) {
paintState = PAINT_GRADIENT;
} else if (paintClass == LinearGradientPaint.class) {
paintState = PAINT_LIN_GRADIENT;
} else if (paintClass == RadialGradientPaint.class) {
paintState = PAINT_RAD_GRADIENT;
} else if (paintClass == TexturePaint.class) {
paintState = PAINT_TEXTURE;
} else {
paintState = PAINT_CUSTOM;
}
validFontInfo = false;
invalidatePipe();
}
/**
* Serialize an instance, restore it, and check for equality.
*/
@Test
public void testSerialization() {
CompassPlot p1 = new CompassPlot(null);
p1.setRosePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.blue));
p1.setRoseCenterPaint(new GradientPaint(4.0f, 3.0f, Color.red, 2.0f,
1.0f, Color.green));
p1.setRoseHighlightPaint(new GradientPaint(4.0f, 3.0f, Color.red, 2.0f,
1.0f, Color.green));
CompassPlot p2 = (CompassPlot) TestUtilities.serialised(p1);
assertEquals(p1, p2);
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Rectangle clip = g2.getClipBounds();
Paint paint = g2.getPaint();
g2.setPaint(new GradientPaint(0.0f, getHeight() * 0.22f,
new Color(0x202737),
0.0f, getHeight() * 0.7f,
Color.BLACK));
g2.fillRect(clip.x, clip.y, clip.width, clip.height);
g2.setPaint(paint);
}
/**
* Tests the equals() method when the list contains a GradientPaint
* instance.
*/
public void testEquals3() {
// check two separate (but equal) colors
PaintList l1 = new PaintList();
Paint p1 = new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue);
l1.setPaint(0, p1);
PaintList l2 = new PaintList();
Paint p2 = new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue);
l2.setPaint(0, p2);
assertEquals(l1, l2);
}
/**
* 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)));
}
/**
* Serialises a <code>Paint</code> object.
*
* @param paint the paint object (<code>null</code> permitted).
* @param stream the output stream (<code>null</code> not permitted).
*
* @throws IOException if there is an I/O error.
*/
public static void writePaint(final Paint paint,
final ObjectOutputStream stream)
throws IOException {
if (stream == null) {
throw new IllegalArgumentException("Null 'stream' argument.");
}
if (paint != null) {
stream.writeBoolean(false);
stream.writeObject(paint.getClass());
if (paint instanceof Serializable) {
stream.writeObject(paint);
}
else if (paint instanceof GradientPaint) {
final GradientPaint gp = (GradientPaint) paint;
stream.writeFloat((float) gp.getPoint1().getX());
stream.writeFloat((float) gp.getPoint1().getY());
stream.writeObject(gp.getColor1());
stream.writeFloat((float) gp.getPoint2().getX());
stream.writeFloat((float) gp.getPoint2().getY());
stream.writeObject(gp.getColor2());
stream.writeBoolean(gp.isCyclic());
}
}
else {
stream.writeBoolean(true);
}
}
/**
* Check that the equals() method distinguishes all fields.
*/
@Test
public void testEquals() {
XYErrorRenderer r1 = new XYErrorRenderer();
XYErrorRenderer r2 = new XYErrorRenderer();
assertEquals(r1, r2);
// drawXError
r1.setDrawXError(false);
assertFalse(r1.equals(r2));
r2.setDrawXError(false);
assertTrue(r1.equals(r2));
// drawYError
r1.setDrawYError(false);
assertFalse(r1.equals(r2));
r2.setDrawYError(false);
assertTrue(r1.equals(r2));
// capLength
r1.setCapLength(9.0);
assertFalse(r1.equals(r2));
r2.setCapLength(9.0);
assertTrue(r1.equals(r2));
// errorPaint
r1.setErrorPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertFalse(r1.equals(r2));
r2.setErrorPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
assertTrue(r1.equals(r2));
// errorStroke
r1.setErrorStroke(new BasicStroke(1.5f));
assertFalse(r1.equals(r2));
r2.setErrorStroke(new BasicStroke(1.5f));
assertTrue(r1.equals(r2));
}
protected void PaintGradiente(Graphics2D g, boolean round) {
int dist = 0;
int w = getWidth() - dist;
int h = getHeight() - dist;
int L = getLeft();
int T = getTop();
boolean dv = getGDirecao() == VERTICAL;
//Composite originalComposite = g.getComposite();
//g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, alfa));
GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true);
//g.setPaint(GP);
g.setPaint(getForeColor());
if (round) {
g.drawRoundRect(L, T, w - 1, h - 1, roundRectSize, roundRectSize);
g.setPaint(GP);
g.fillRoundRect(L + 1, T + 1, w - 2, h - 2, roundRectSize, roundRectSize);
g.setPaint(isDisablePainted()? disabledColor : Color.WHITE);
g.drawRoundRect(L + 1, T + 1, w - 3, h - 3, roundRectSize, roundRectSize);
} else {
g.drawRect(L, T, w - 1, h - 1);
g.setPaint(GP);
g.fillRect(L + 1, T + 1, w - 2, h - 2);
g.setPaint(isDisablePainted()? disabledColor : Color.WHITE);
g.drawRect(L + 1, T + 1, w - 3, h - 3);
}
if (isGradientePinteDetalhe()) {
g.setPaint(getGradienteCorDetalhe());
GeneralPath path = new GeneralPath();
path.moveTo(L + 2, T + 2);
path.quadTo(L + w / 2 + 1, T + h / 2 + 1, L + w - 1, T + 2);
path.closePath();
g.fill(path);
}
//g.setComposite(originalComposite);
}
public void paintComponent(Graphics g) {
BufferedImage cache = new BufferedImage(2, getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = cache.createGraphics();
GradientPaint paint = new GradientPaint(0, 0, new Color(241, 245, 250), 0, getHeight(), new Color(244, 250, 255), true);
g2d.setPaint(paint);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.dispose();
g.drawImage(cache, 0, 0, getWidth(), getHeight(), null);
}
/**
* Create a new (if possible, darker) <code>Paint</code> of the same Type.
* If the Type is not supported, the original <code>Paint</code> is returned.
* <p>
* @param paint a <code>Paint</code> implementation
* (e.g. {@link Color}, {@link GradientPaint}, {@link TexturePaint},..)
* <p>
* @return a (usually new, see above) <code>Paint</code>
*/
public static Paint darker(Paint paint) {
if (paint instanceof Color) {
return darker((Color) paint);
}
if (legacyAlpha == true) {
/*
* Legacy? Just return the original Paint.
* (this corresponds EXACTLY to how Paints used to be darkened)
*/
return paint;
}
if (paint instanceof GradientPaint) {
return darker((GradientPaint) paint);
}
if (paint instanceof LinearGradientPaint) {
return darkerLinearGradientPaint((LinearGradientPaint) paint);
}
if (paint instanceof RadialGradientPaint) {
return darkerRadialGradientPaint((RadialGradientPaint) paint);
}
if (paint instanceof TexturePaint) {
try {
return darkerTexturePaint((TexturePaint) paint);
}
catch (Exception e) {
/*
* Lots can go wrong while fiddling with Images, Color Models
* & such! If anything at all goes awry, just return the original
* TexturePaint. (TexturePaint's are immutable anyway, so no harm
* done)
*/
return paint;
}
}
return paint;
}
/**
* Confirm that cloning works.
*/
@Test
public void testCloning() throws CloneNotSupportedException {
// test default instance
DialBackground b1 = new DialBackground();
DialBackground b2 = (DialBackground) b1.clone();
assertTrue(b1 != b2);
assertTrue(b1.getClass() == b2.getClass());
assertTrue(b1.equals(b2));
// test a customised instance
b1 = new DialBackground();
b1.setPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.green));
b1.setGradientPaintTransformer(new StandardGradientPaintTransformer(
GradientPaintTransformType.CENTER_VERTICAL));
b2 = (DialBackground) b1.clone();
assertTrue(b1 != b2);
assertTrue(b1.getClass() == b2.getClass());
assertTrue(b1.equals(b2));
// check that the listener lists are independent
MyDialLayerChangeListener l1 = new MyDialLayerChangeListener();
b1.addChangeListener(l1);
assertTrue(b1.hasListener(l1));
assertFalse(b2.hasListener(l1));
}
@Override
public void drawIcon(Graphics2D g2, int width, int height, int percentage) {
g2.setColor(Color.WHITE);
g2.setPaint(new GradientPaint(0, 0, Color.WHITE.darker(), 0, (float) (height * 0.5), Color.WHITE, true));
g2.fillRect(0, 0, width, height);
g2.setColor(Color.GREEN);
g2.setPaint(new GradientPaint(0, 0, Color.GREEN.darker(), percentage, (float) (height * 0.5), Color.GREEN
.darker().darker(), false));
g2.fillRect(0, 0, (int) (percentage * 200d / 100d), height);
g2.setColor(Color.BLACK);
g2.drawRect(0, 0, width - 1, height - 1);
g2.dispose();
}
/**
* Returns an SVG color string based on the current paint. To handle
* {@code GradientPaint} we rely on the {@code setPaint()} method
* having set the {@code gradientPaintRef} attribute.
*
* @return An SVG color string.
*/
private String svgColorStr() {
String result = "black;";
if (this.paint instanceof Color) {
return rgbColorStr((Color) this.paint);
} else if (this.paint instanceof GradientPaint
|| this.paint instanceof LinearGradientPaint
|| this.paint instanceof RadialGradientPaint) {
return "url(#" + this.gradientPaintRef + ")";
}
return result;
}
/**
* Create a new (if possible, darker) <code>Paint</code> of the same Type.
* If the Type is not supported, the original <code>Paint</code> is returned.
* <p>
* @param paint a <code>Paint</code> implementation
* (e.g. {@link Color}, {@link GradientPaint}, {@link TexturePaint},..)
* <p>
* @return a (usually new, see above) <code>Paint</code>
*/
public static Paint darker(Paint paint) {
if (paint instanceof Color) {
return darker((Color) paint);
}
if (legacyAlpha == true) {
/*
* Legacy? Just return the original Paint.
* (this corresponds EXACTLY to how Paints used to be darkened)
*/
return paint;
}
if (paint instanceof GradientPaint) {
return darker((GradientPaint) paint);
}
if (paint instanceof LinearGradientPaint) {
return darkerLinearGradientPaint((LinearGradientPaint) paint);
}
if (paint instanceof RadialGradientPaint) {
return darkerRadialGradientPaint((RadialGradientPaint) paint);
}
if (paint instanceof TexturePaint) {
try {
return darkerTexturePaint((TexturePaint) paint);
}
catch (Exception e) {
/*
* Lots can go wrong while fiddling with Images, Color Models
* & such! If anything at all goes awry, just return the original
* TexturePaint. (TexturePaint's are immutable anyway, so no harm
* done)
*/
return paint;
}
}
return paint;
}
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);
}
/**
* Draws indicator in case the annotation text overflows on the y axis.
*
* @param g
* the graphics context to draw upon
* @param loc
* the location of the annotation
* @param printing
* if we are currently printing
*/
private void drawOverflowIndicator(final Graphics2D g, final Rectangle2D loc, final boolean printing) {
if (printing) {
// never draw them for printing
return;
}
Graphics2D g2 = (Graphics2D) g.create();
int size = 20;
int xOffset = 10;
int yOffset = 10;
int stepSize = size / 4;
int dotSize = 3;
int x = (int) loc.getMaxX() - size - xOffset;
int y = (int) loc.getMaxY() - size - yOffset;
GradientPaint gp = new GradientPaint(x, y, Color.WHITE, x, y + size * 1.5f, Color.LIGHT_GRAY);
g2.setPaint(gp);
g2.fillRect(x, y, size, size);
g2.setColor(Color.BLACK);
g2.drawRect(x, y, size, size);
g2.fillOval(x + stepSize, y + stepSize * 2, dotSize, dotSize);
g2.fillOval(x + stepSize * 2, y + stepSize * 2, dotSize, dotSize);
g2.fillOval(x + stepSize * 3, y + stepSize * 2, dotSize, dotSize);
g2.dispose();
}
/**
* Serialize an instance, restore it, and check for equality.
*/
@Test
public void testSerialization() {
XYErrorRenderer r1 = new XYErrorRenderer();
r1.setErrorPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
Color.white));
XYErrorRenderer r2 = (XYErrorRenderer) TestUtilities.serialised(r1);
assertEquals(r1, r2);
}
/**
* A check for serialization.
*/
@Test
public void testSerialization2() {
PaintMap m1 = new PaintMap();
m1.put("K1", Color.red);
m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f,
Color.yellow));
PaintMap m2 = (PaintMap) TestUtilities.serialised(m1);
assertEquals(m1, m2);
}
private static void setGradientPaint(RenderQueue rq,
SunGraphics2D sg2d,
GradientPaint paint,
boolean useMask)
{
setGradientPaint(rq, (AffineTransform)sg2d.transform.clone(),
paint.getColor1(), paint.getColor2(),
paint.getPoint1(), paint.getPoint2(),
paint.isCyclic(), useMask);
}
/**
* At the end of parsing the element, the gradient paint is constructed.
*
* @throws XmlReaderException if there is a parsing error.
*/
protected void doneParsing() throws XmlReaderException {
if (this.point1Handler == null || this.point2Handler == null
|| this.color1Handler == null || this.color2Handler == null) {
throw new XmlReaderException("Not all required subelements are defined.");
}
this.gradient = new GradientPaint
((Point2D) this.point1Handler.getObject(),
(Color) this.color1Handler.getObject(),
(Point2D) this.point2Handler.getObject(),
(Color) this.color2Handler.getObject());
}