Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Filling Color in Figure!!!!
Filling Color in Figure!!!! [message #184927] Tue, 21 June 2005 07:54 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Steve Jones is currently offline Steve JonesFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Filling Color in Figure!!!! [message #184965 is a reply to message #184957] Tue, 21 June 2005 10:12 Go to previous message
Steve Jones is currently offline Steve JonesFriend
Messages: 95
Registered: July 2009
Member
Nitin wrote:

>
>
> 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.

I don't understand why you have installed ToolbarLayout and added _nameLabel
as a child and then attempt to move it in your paintFigure() method.

ToolbarLayout will place _nameLabel for you automatically.

You don't say what ComponentFigure is subclassed from. You call
super.paintFigure(g), do you really want to do this?

Add a println() diagnostic to see what values are in bounds during/after the
move.

Also have a look at Figure#paint(Graphics) to see how is calls
paintChildren() and paintFigure() you may get some insights.

Steve.
Previous Topic:GEF and platform undo
Next Topic:Must I use draw2d or swt for my plugin ?
Goto Forum:
  


Current Time: Fri Apr 26 02:29:02 GMT 2024

Powered by FUDForum. Page generated in 0.03214 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top