Home » Eclipse Projects » GEF » Filling Color in Figure!!!!
Filling Color in Figure!!!! [message #184927] |
Tue, 21 June 2005 07:54 |
Eclipse User |
|
|
|
Originally posted by: gautamn.iitk.ac.in
I have created a component using the following code
public ComponentFigure(EditableLabel name) {
super(name);
ToolbarLayout layout = new ToolbarLayout();
setLayoutManager(layout);
setToolTip(tooltip);
_nameLabel = name;
add(_nameLabel);
}
public void paintFigure(Graphics g){
bounds = getBounds();
x1 = bounds.right() - bounds.width;
y1 = bounds.bottom() - bounds.height;
w = bounds.width;
h = bounds.height;
_nameLabel.setLocation(new Point(x1+w/20,y1));
_nameLabel.setSize(w-w/20,h);
g.drawLine(x1,y1+h/4,x1,y1+3*h/8);
g.drawLine(x1,y1+ 3*h/8, x1+w/10,y1+3*h/8);
g.drawLine(x1+w/10,y1+3*h/8,x1+w/10,y1+h/4);
g.drawLine(x1+w/10,y1+h/4, x1, y1+h/4);
g.drawLine(x1,y1+h/4+h/4,x1,y1+3*h/8+h/4);
g.drawLine(x1,y1+3*h/8+h/4,x1+w/10,y1+3*h/8+h/4);
g.drawLine(x1+w/10,y1+3*h/8+h/4,x1+w/10,y1+h/4+h/4);
g.drawLine(x1+w/10,y1+h/4+h/4,x1,y1+h/4+h/4);
g.drawLine(x1+w/20,y1,x1+w-1, y1);
g.drawLine(x1+w-1,y1,x1+w-1,y1+h-1);
g.drawLine(x1+w-1,y1+h-1, x1+w/20,y1+h-1);
g.drawLine(x1+w/20,y1+h-1,x1+w/20,y1+h/2+h/8 );
g.drawLine(x1+w/20,y1,x1+w/20, y1+h/4);
g.drawLine(x1+w/20,y1+h*3/8, x1+w/20,y1+h/2);
super.paintFigure(g);
}
I want to fill this figure using some color. How can I do that???
setBackgroundColor() function not working in this case.
Regards,
Nitin Gautam.
|
|
|
Re: Filling Color in Figure!!!! [message #184935 is a reply to message #184927] |
Tue, 21 June 2005 08:37 |
Steve Jones Messages: 95 Registered: July 2009 |
Member |
|
|
Nitin Gautam wrote:
>
> I have created a component using the following code
>
> public ComponentFigure(EditableLabel name) {
> super(name);
> ToolbarLayout layout = new ToolbarLayout();
> setLayoutManager(layout);
> setToolTip(tooltip);
> _nameLabel = name;
> add(_nameLabel);
> }
>
>
> public void paintFigure(Graphics g){
> bounds = getBounds();
>
> x1 = bounds.right() - bounds.width;
> y1 = bounds.bottom() - bounds.height;
> w = bounds.width;
> h = bounds.height;
>
> _nameLabel.setLocation(new Point(x1+w/20,y1));
> _nameLabel.setSize(w-w/20,h);
>
> g.drawLine(x1,y1+h/4,x1,y1+3*h/8);
> g.drawLine(x1,y1+ 3*h/8, x1+w/10,y1+3*h/8);
> g.drawLine(x1+w/10,y1+3*h/8,x1+w/10,y1+h/4);
> g.drawLine(x1+w/10,y1+h/4, x1, y1+h/4);
>
> g.drawLine(x1,y1+h/4+h/4,x1,y1+3*h/8+h/4);
> g.drawLine(x1,y1+3*h/8+h/4,x1+w/10,y1+3*h/8+h/4);
> g.drawLine(x1+w/10,y1+3*h/8+h/4,x1+w/10,y1+h/4+h/4);
> g.drawLine(x1+w/10,y1+h/4+h/4,x1,y1+h/4+h/4);
>
> g.drawLine(x1+w/20,y1,x1+w-1, y1);
> g.drawLine(x1+w-1,y1,x1+w-1,y1+h-1);
> g.drawLine(x1+w-1,y1+h-1, x1+w/20,y1+h-1);
> g.drawLine(x1+w/20,y1+h-1,x1+w/20,y1+h/2+h/8 );
> g.drawLine(x1+w/20,y1,x1+w/20, y1+h/4);
> g.drawLine(x1+w/20,y1+h*3/8, x1+w/20,y1+h/2);
>
> super.paintFigure(g);
> }
>
> I want to fill this figure using some color. How can I do that???
> setBackgroundColor() function not working in this case.
> Regards,
> Nitin Gautam.
Hi,
Create your shape using:
org.eclipse.draw2d.geometry#PointList
PointList pl = createFigure(bounds);
In your paintFigure() method you can do things like:
setBackgroundColor(FILL_COLOUR);
graphics.fillPolygon(pl);
graphics.setForegroundColor(ColorConstants.black);
graphics.drawPolygon(pl);
This fills the figure and then draws a black outline.
Cheers, Steve.
|
|
|
Re: Filling Color in Figure!!!! [message #184957 is a reply to message #184935] |
Tue, 21 June 2005 09:48 |
Eclipse User |
|
|
|
Originally posted by: gautamn.iitk.ac.in
Now the problem is when I move the figure the borders are destroyed
....and moreover while refreshing the editor(with taskbar moving it
up/down) the colors disappear and then comes by itself...wht to do??
Regards,
Nitin.
|
|
| |
Goto Forum:
Current Time: Thu Dec 12 20:32:42 GMT 2024
Powered by FUDForum. Page generated in 0.03389 seconds
|