Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Centering a label horizontally and vertically
Centering a label horizontally and vertically [message #553202] Mon, 16 August 2010 16:36 Go to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello,

I want to center a label horizontally. I use the BorderLayout layout in
order to put the label in the center area but the label isn't completely
centered. In fact, it lacks the setting of the setAlignment method on
the corresponding WrappingLabel...

fFigureNameLabel = new WrappingLabel();
fFigureNameLabel.setText("");
fFigureNameLabel.setAlignment(PositionConstants.CENTER);

this.add(fFigureNameLabel, BorderLayout.CENTER);

Is it possible to specify something within the graph model in order to
have the setAlignment line generated by GMF? I saw the AlignmentFacet
element under the DiagramLabel but it doesn't seem to achieve that...

Thanks very much in advance for your answers!
Thierry
Re: Centering a label horizontally and vertically [message #553304 is a reply to message #553202] Tue, 17 August 2010 06:03 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hello Thierry,

the best thing to do would be to adapt the gmf generator template that misses to generate the right code for you. There you would have access to the gmfgen model data and could get the generator to add the missing code.

Rob
Re: Centering a label horizontally and vertically [message #554307 is a reply to message #553304] Sat, 21 August 2010 08:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello Rob,

Thanks very much for the hint. I'll do like that...

Thierry

> Hello Thierry,
>
> the best thing to do would be to adapt the gmf generator template that
> misses to generate the right code for you. There you would have access
> to the gmfgen model data and could get the generator to add the missing
> code.
>
> Rob
Re: Centering a label horizontally and vertically [message #718121 is a reply to message #553202] Tue, 23 August 2011 10:14 Go to previous message
vinay  is currently offline vinay Friend
Messages: 4
Registered: August 2011
Junior Member
Hello,

To get the label centered vetically and horizontally you just make the following changes to your code.

In EditPart Constructor write this code

this.setLayoutManager(new StackLayout() {
public void layout(IFigure figure) {
Rectangle r = figure.getClientArea();
List children = figure.getChildren();

IFigure child;
Dimension d;
for (int i = 0; i < children.size(); i++) {
child = (IFigure)children.get(i);
d = child.getPreferredSize(r.width, r.height);
d.width = Math.min(d.width, r.width);
d.height = Math.min(d.height, r.height);
Rectangle childRect = new Rectangle(
r.x + (r.width - d.width)/2,
r.y + (r.height - d.height)/2,
d.width,
d.height);
child.setBounds(childRect);
}
}
});


then

fFigureNameLabel = new WrappingLabel();
fFigureNameLabel.setText("");
fFigureNameLabel.setAlignment(PositionConstants.CENTER);

this.add(fFigureNameLabel);
Previous Topic:Proxy and external dialogs
Next Topic:Custom commands for palette icons
Goto Forum:
  


Current Time: Thu Apr 25 08:13:01 GMT 2024

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

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

Back to the top