[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.gef] Re: Gradient fill for ovals

Thanks, but I'm working on WSAD 5.1.2 so Path is not available here.

However I've been able to use Java2D following this tutorial http://www-128.ibm.com/developerworks/java/library/j-2dswt and using its piece of code.

However,it seemed like the awtImage wasn't large enough so I got IndexOutOfBounsException in the awtImage.getRGB method.

I changed the prepareRendering method to include the X and Y position in the checkOffScreenImages like this:

checkOffScreenImages(clipW+clipX, clipH+clipY);

Maybe not the best solution, but it worked. This is my code:

###################
..
protected void fillShape(Graphics graphics) {
Graphics2DRenderer renderer = new Graphics2DRenderer();
Dimension controlSize = getSize();

// prepares the Graphics2D renderer
renderer.prepareRendering(graphics);
// gets the Graphics2D context
Graphics2D g2d = renderer.getGraphics2D();

// does the Java 2D painting
// paints the background with a color gradient
g2d.setRenderingHint(
	RenderingHints.KEY_ANTIALIASING,
	RenderingHints.VALUE_ANTIALIAS_ON);

GradientPaint gp =
	new GradientPaint(
		(float) getBounds().x,
		(float) getBounds().y,
		java.awt.Color.yellow,
(float) getBounds().x+(float) controlSize.width,
(float) getBounds().y+(float) controlSize.height,
		java.awt.Color.white);
g2d.setPaint(gp);

g2d.fillOval(
	getBounds().x,
	getBounds().y,
	controlSize.width,
	controlSize.height);

// now that we are done with Java 2D, renders Graphics2D operation
// on the Draw2D graphics context
renderer.render(graphics);
}
############################