Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Refresh Label of a Shape (Extended ShapeExample)
Refresh Label of a Shape (Extended ShapeExample) [message #222420] Mon, 04 September 2006 16:54 Go to next message
Eclipse User
Originally posted by: tobias.brueggendick.prostep.com

Hello,

i'm extending the ShapeExample ATM. Now i want to have a label which
includes the text of a shape. The Text must be in the middle of the shape
and here's the problem. At the creation it is no problem. When the Shape is
moved it is too no problem, but when the shape is only resize there the
label isn't anymore in the middle. My calculations for the lable are:

private void setLabelbounds() {
Label temp = (Label) getFigure().getChildren().get (0);
Rectangle bounds = this.getFigure().getBounds();
int y = bounds.y + (bounds.height - 25) / 2;
temp.setLocation(new Point(bounds.x, y));
temp.setSize(bounds.width, 25);
temp.revalidate();
}

I call this method in refreshVisuals().

As anybody an idea or can help me?

Best Regards
Tobias
Re: Refresh Label of a Shape (Extended ShapeExample) [message #222427 is a reply to message #222420] Tue, 05 September 2006 13:27 Go to previous messageGo to next message
Nhu Le is currently offline Nhu Le
Messages: 47
Registered: July 2009
Member
If the text has to be in the middle of the shape, why don't you use some
supplied layout to position it?

If you want to call the set location manually, you can try to put the
code in the "handleBoundsEvent" method (that should get called whenever
the model changes the bounds and fire a "BOUNDS" event). Note that the
event stuffs I am talking about here is in relation with the example
SchemaEditor, not something done automatically in GEF.

Nhu Le.

Tobias Br├╝ggendick wrote:
> Hello,
>
> i'm extending the ShapeExample ATM. Now i want to have a label which
> includes the text of a shape. The Text must be in the middle of the shape
> and here's the problem. At the creation it is no problem. When the Shape is
> moved it is too no problem, but when the shape is only resize there the
> label isn't anymore in the middle. My calculations for the lable are:
>
> private void setLabelbounds() {
> Label temp = (Label) getFigure().getChildren().get (0);
> Rectangle bounds = this.getFigure().getBounds();
> int y = bounds.y + (bounds.height - 25) / 2;
> temp.setLocation(new Point(bounds.x, y));
> temp.setSize(bounds.width, 25);
> temp.revalidate();
> }
>
> I call this method in refreshVisuals().
>
> As anybody an idea or can help me?
>
> Best Regards
> Tobias
>
>
Re: Refresh Label of a Shape (Extended ShapeExample) [message #222442 is a reply to message #222427] Tue, 05 September 2006 13:51 Go to previous message
Eclipse User
Originally posted by: tobias.brueggendick.prostep.com

I found a other solution but i had the tip of using some other Layout in
back of my mind. My Solution is relative simple. For every Figure i use i
create a label in the Figure itself. Every Figuer i want to have a label
in the middle of it, has a variable of the Type Label (Draw2d). Then the
label is initialized in the Method fillShape, there i set the bounds by
getbounds() of the figure.
At least there was one Problem. When i resize the figure a new Label is
created. The solution again was simple. I initialise the label only once
by requesting if the variable is null or not. If it is initialized it can
never be null. Voila now every Shape Display his name in the middle of its
figure. I even don't need to change my functions for DirectEdit which i
created before.
Previous Topic:Copy Location
Next Topic:how can I use a dynamic EMF model as components in PaletteDrawer?
Goto Forum:
  


Current Time: Thu Oct 23 08:42:54 GMT 2014

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

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