Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » [GMF] Custom Figure - Label Positioning
[GMF] Custom Figure - Label Positioning [message #761447] Tue, 06 December 2011 13:45 Go to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Hello.

I created the following CustomNode.

package gsnModel.diagram.figures;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;

import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;


public class StrategyFigure extends Figure {
	
	 @Override
	  public void paint(Graphics graphics) {
	    
	    Rectangle r = getBounds();
	    
	    // Define the points of a trapez
	    Point p1 = new Point(r.x + r.width/5, r.y);
	    Point p2 = new Point(r.x  + r.width, r.y);
	    Point p3 = new Point (r.x -r.width/5 +r.width, r.y + r.height);  
	    Point p4 = new Point (r.x,  r.y + r.height);
	    
	    
	    PointList pointList = new PointList();
	    pointList.addPoint(p1);
	    pointList.addPoint(p2);
	    pointList.addPoint(p3);
	    pointList.addPoint(p4);
	    
	    // Fill the shape
	    graphics.fillPolygon(pointList);
	    
	    // Draw the outline
	    graphics.drawLine(p1, p2);
	    graphics.drawLine(p2, p3);
	    graphics.drawLine(p3, p4);
	    graphics.drawLine(p4, p1);
	    
	    // Move the label to the centre of the diamond
	    WrappingLabel label = (WrappingLabel) this.getChildren().get(0);
	    //System.out.println(this.getChildren().get(0).toString());
	    
	    label.setAlignment(PositionConstants.BOTTOM | PositionConstants.RIGHT );
	    label.paint(graphics);
	    
	 }
	
}


This figure has 2 Labels.
Now i want to arrange them in my Node.
One should appear always in the top left of the figure.
The other one should appear in the center.
The problem is when i use :

label.setAlignment(PositionConstants.TOP | PositionConstants.LEFT );


the text gets out of the figure.
So i got two question. How i can set the text that it starts in the Figure ?

Is there no other way to set the labels in the Figure ?
the setAlignment() method is really bad...i want for example give specific points relative to my figure.
Or use a specific Layout.

Greetings
Re: [GMF] Custom Figure - Label Positioning [message #761459 is a reply to message #761447] Tue, 06 December 2011 13:58 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hi,

You should avoid defining figures using paint() commands and so on. The
easiest and more rigourous way to achieve that is to .add(IFigure) in a
createContents method called in your constructor.
Then, you'll have the ability to tweak your figures using the standard
layouting mechanism.
I advise you to have a look at the code generated by GMF Tooling
..gmfgraph files when creating a figure. It follows the most efficient
pattern to create Draw2d figures.

HTH
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #761463 is a reply to message #761459] Tue, 06 December 2011 14:06 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
But where i can find the generated code, in particular for my StrategyFigure ?
Can you give me an example ?

I 'm not sure what you mean...
Re: [GMF] Custom Figure - Label Positioning [message #761467 is a reply to message #761463] Tue, 06 December 2011 14:09 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

1. Create a .gmfgraph file
2. Create your figures
3. Right-click, Generate figure plugin
4. look at generated figure classes, and take them as examples.

--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #761546 is a reply to message #761467] Tue, 06 December 2011 16:20 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Ok i think i found the respective code.

Now i want to create a trapeze in draw2d.

How i have to do that ? using Polygon ?

Re: [GMF] Custom Figure - Label Positioning [message #761552 is a reply to message #761546] Tue, 06 December 2011 16:38 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

> How i have to do that ? using Polygon ?


Yes, I think that's the easiest way to do it.
You can follow and comment this bug to get news about a feature that
will hopefully be part of 2.4.1.
And use this for quick preview of figures:
http://marketplace.eclipse.org/content/draw2d-preview

Regards,
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #761569 is a reply to message #761552] Tue, 06 December 2011 17:09 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Im really not good in graphical programming.

For now im doing it like this :

public class StrategyFigure extends Polygon {
	 
	public StrategyFigure() {
	    
	    Rectangle r = getBounds();
	    
	    // Define the points of a trapeze
	    Point p1 = new Point(r.x + r.width/5, r.y);
	    Point p2 = new Point(r.x  + r.width, r.y);
	    Point p3 = new Point (r.x -r.width/5 +r.width, r.y + r.height);  
	    Point p4 = new Point (r.x,  r.y + r.height);
	    
	    
	    PointList pointList = new PointList();
	    pointList.addPoint(p1);
	    pointList.addPoint(p2);
	    pointList.addPoint(p3);
	    pointList.addPoint(p4);
	    
	    this.setPoints(pointList);
    }
}


What i have to do further now ?

My StrategyFigure in EditPart extends this class and looks like this :

public class StrategyFigure extends gsnModel.diagram.figures.StrategyFigure {

		/**
		 * @generated
		 */
		private WrappingLabel fFigureStrategyLabelFigure;

		/**
		 * @generated
		 */
		public StrategyFigure() {
			this.setForegroundColor(THIS_FORE);
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(130),
					getMapMode().DPtoLP(50)));
			this.setBorder(new MarginBorder(getMapMode().DPtoLP(5),
					getMapMode().DPtoLP(5), getMapMode().DPtoLP(5),
					getMapMode().DPtoLP(5)));
			createContents();
		}

		/**
		 * @generated
		 */
		private void createContents() {

			fFigureStrategyLabelFigure = new WrappingLabel();
			fFigureStrategyLabelFigure.setText("Strategy");
			
			this.add(fFigureStrategyLabelFigure);

		}

		/**
		 * @generated
		 */
		public WrappingLabel getFigureStrategyLabelFigure() {
			return fFigureStrategyLabelFigure;
		}

	}



But when i try to add a node now...i see nothing !.
What im doing wrong ?

Is my Polygon not complete ?

Do i have to draw it in any way ?

[Updated on: Tue, 06 December 2011 17:25]

Report message to a moderator

Re: [GMF] Custom Figure - Label Positioning [message #761584 is a reply to message #761569] Tue, 06 December 2011 17:32 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

On 06/12/2011 18:09, Snakebyte wrote:
> Im really not good in graphical programming.
Keep on trying, once you get it, it is very cool to be able to draw
everything and nothing without too much difficulty!

>
> For now im doing it like this :
>
> public class StrategyFigure extends Polygon {
> public StrategyFigure() {
> Rectangle r = getBounds();
> // Define the points of a trapeze
> Point p1 = new Point(r.x + r.width/5, r.y);
> Point p2 = new Point(r.x + r.width, r.y);
> Point p3 = new Point (r.x -r.width/5 +r.width, r.y + r.height); Point p4
> = new Point (r.x, r.y + r.height);
> PointList pointList = new PointList();
> pointList.addPoint(p1);
> pointList.addPoint(p2);
> pointList.addPoint(p3);
> pointList.addPoint(p4);
> this.setPoints(pointList);
> }
> }
>
> What i have to do further now ?

Some tips:
* Prefer using PolygonShape, or ScalablePolygonShape.
* "getBounds" does not make sense at this time.
* You should put constant values in the Point. let's say (10, 0), (40,
0), (50, 20), (0, 20); and also set a preferredSize, let's try (50, 20).

This will probably lay out the figure correctly.
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #761589 is a reply to message #761584] Tue, 06 December 2011 17:44 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Ah great, that helps me a lot.
At first big thanks to you.

I can use the ScalablePolygon as i need it.

But know lets come back to the question in the beginning.

How i can set this WrappingLabel to a specific position now ?

Should i use Layouts here ? Can i even use them in this ScalablePolygonShape ?

It seems like the canvas use a rectangular shape for aligment of the wrappinglabel.


I tried it like this in my EditPart constructor :

                        LayoutManager layout = new BorderLayout();
			this.setLayoutManager(layout);
			
			fFigureStrategyLabelFigure = new WrappingLabel();
			fFigureStrategyLabelFigure.setText("Strategy");

			this.add(fFigureStrategyLabelFigure,BorderLayout.CENTER);




But the label is still at the top left.

Then i tried to add a new label like this.

                        LayoutManager layout = new BorderLayout();
			this.setLayoutManager(layout);
			
			fFigureStrategyLabelFigure = new WrappingLabel();
			fFigureStrategyLabelFigure.setText("Strategy");
			
			Label lbl = new Label(fFigureStrategyLabelFigure.toString());
			this.add(lbl,BorderLayout.CENTER);
			this.add(fFigureStrategyLabelFigure,BorderLayout.CENTER);
			




But this lbl-Label is not even rendered.

Just to let you understand why i want to do this. Of course, its annoying and looks pretty bad when the Label is not completly inside the figure.
And later on, i want to add some new labels.

When im doing it like this:

public StrategyFigure() {

			this.setForegroundColor(THIS_FORE);
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(130),
					getMapMode().DPtoLP(50)));
			
			LayoutManager layout = new BorderLayout();
			this.setLayoutManager(layout);
			
			fFigureStrategyLabelFigure = new WrappingLabel();
			fFigureStrategyLabelFigure.setText("Strategy");
			
			Label lbl = new Label("Test");
			this.add(lbl,BorderLayout.CENTER);	
			
		}



it works.
But then i have a completly independant label.

It seems like when i'm using any kind of Layout, like a BorderLayout for example, the WrappingLabel disappears from Canvas.
How can i change the Position of the WrappingLabel ?

I append a picture for a better understanding.
All i want is this WrappingLabel inside of the Figure and not only inside of Bounds.








  • Attachment: default.png
    (Size: 1.84KB, Downloaded 246 times)

[Updated on: Tue, 06 December 2011 19:27]

Report message to a moderator

Re: [GMF] Custom Figure - Label Positioning [message #761949 is a reply to message #761589] Wed, 07 December 2011 10:31 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

On 06/12/2011 18:44, Snakebyte wrote:
> Ah great, that helps me a lot.
> At first big thanks to you.
>
> I can use the ScalablePolygon as i need it.
>
> But know lets come back to the question in the beginning.
>
> How i can set this WrappingLabel to a specific position now ?
>
> Should i use Layouts here ?

Yes, you should:
1. Put a layout one your Polygon (an XYLayout is probably the easier one
to manipulate)
2. Create a layout constrain for your child wrapping label. XYLayout
accepts Rectangle as constraints.
3. Add your childLabel to the figure with the constraint:
this.add(childLabel, new Rectangle(x, y, width, height));


--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #762716 is a reply to message #761447] Thu, 08 December 2011 14:42 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Hey thanks, works too.

I do it like this.

                        this.setForegroundColor(THIS_FORE);
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(130),
					getMapMode().DPtoLP(50)));
			//createContents();
			LayoutManager layout = new XYLayout();
			this.setLayoutManager(layout);
			fFigureStrategyLabelFigure = new WrappingLabel();
			fFigureStrategyLabelFigure.setText("Strategy");
			fFigureStrategyLabelFigure.setFont(FFIGURESTRATEGYLABELFIGURE_FONT);
this.add(fFigureStrategyLabelFigure, new Rectangle(20,20,130,20));	



But know the position of the label is fixed when the node is constructed.
When i now change the size of the node in my canvas the label still is at the same position.
How can i replace it when the object size is changed ?
I think i always have to set the position relative to the current bounding rectangle.
Right ?
Which method is called when the object size is changed ?


Re: [GMF] Custom Figure - Label Positioning [message #762721 is a reply to message #762716] Thu, 08 December 2011 14:48 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

On 08/12/2011 15:42, Snakebyte wrote:
> But know the position of the label is fixed when the node is constructed.
> When i now change the size of the node in my canvas the label still is
> at the same position.

The XYLayout use fixed positions, There are some more dynamic layouts,
that would probably better fit your use-case.
I let you have a look at Type Hierarchy of
org.eclipse.draw2d.KayoutManager class and read the description of the
concrete layout available.
Then you'll simply have to choose one.
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #762730 is a reply to message #762721] Thu, 08 December 2011 15:01 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
The explanation in the API is really short.
Can you plz tell me which Layout is the right one for my case ?

I want to place the label relative to a specific point.
(Here relative to my parentFigure.pointlist(0)).

Re: [GMF] Custom Figure - Label Positioning [message #762742 is a reply to message #762730] Thu, 08 December 2011 15:06 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

At this given point of your development, I cannot help you a lot. You'll
have to test and try.
Some layouts such as the GridLayout allow good control over the location
of items and relative position.

Regards,
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #762791 is a reply to message #762742] Thu, 08 December 2011 16:18 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
My idea was the following.
In my Base class StrategyFigure i designed a ScalablePolgyonShape

public class StrategyFigure extends ScalablePolygonShape {
	 
	public StrategyFigure() {
	    
	    // Define the points of a trapez
	    Point p1 = new Point(10,0);
	    Point p2 = new Point(70,0);
	    Point p3 = new Point (60,20);  
	    Point p4 = new Point (0,20);
	    
	    PointList pointList = new PointList();
	    pointList.addPoint(p1);
	    pointList.addPoint(p2);
	    pointList.addPoint(p3);
	    pointList.addPoint(p4);
	    
	    this.setPoints(pointList);
  }
}


Now i want to add the inline rectangle to this figure. Im try to do it like this.

public class StrategyFigure extends ScalablePolygonShape {
	 
	public StrategyFigure() {
	    
	    // Define the points of a trapez
	    Point p1 = new Point(10,0);
	    Point p2 = new Point(70,0);
	    Point p3 = new Point (60,20);  
	    Point p4 = new Point (0,20);
	    
	    PointList pointList = new PointList();
	    pointList.addPoint(p1);
	    pointList.addPoint(p2);
	    pointList.addPoint(p3);
	    pointList.addPoint(p4);
	    
	    this.setPoints(pointList);
	    
	    RectangleFigure rect = new RectangleFigure();
	    rect.setBounds(new Rectangle(0,0,50,20));
	 
	    this.add(rect, PositionConstants.CENTER);
  }
}


I can use the PositionConstants.CENTER , because the Rectangle is equals to the size that it must be fit in my trapeze.
With that it can add my label to the child figure.

But i got the following exception:

!ENTRY org.eclipse.core.commands 4 2 2011-12-08 17:16:30.691
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.commands".
!STACK 0
java.lang.IndexOutOfBoundsException: Index does not exist
	at org.eclipse.draw2d.Figure.add(Figure.java:139)
	at org.eclipse.draw2d.Figure.add(Figure.java:184)
	at gsnModel.diagram.figures.StrategyFigure.<init>(StrategyFigure.java:44)
	at gsnModel.diagram.edit.parts.StrategyEditPart$StrategyFigure.<init>(StrategyEditPart.java:378)
	at gsnModel.diagram.edit.parts.StrategyEditPart.createNodeShape(StrategyEditPart.java:129)
	at gsnModel.diagram.edit.parts.StrategyEditPart.createNodeFigure(StrategyEditPart.java:207)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart.createFigure(ShapeNodeEditPart.java:90)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.getFigure(AbstractGraphicalEditPart.java:494)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.isSelectable(GraphicalEditPart.java:1284)
	at org.eclipse.gmf.runtime.diagram.ui.actions.internal.SelectAllAction.getSelectableNodesInside(SelectAllAction.java:135)
	at org.eclipse.gmf.runtime.diagram.ui.actions.internal.SelectAllAction.getSelectableChildrenNodes(SelectAllAction.java:151)
	at org.eclipse.gmf.runtime.diagram.ui.actions.internal.SelectAllAction.getSelectableNodesInside(SelectAllAction.java:117)
	at org.eclipse.gmf.runtime.diagram.ui.actions.internal.SelectAllAction.getSelectableNodes(SelectAllAction.java:103)
	at org.eclipse.gmf.runtime.diagram.ui.actions.internal.SelectAllAction.createOperationSet(SelectAllAction.java:82)
	at org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction.getOperationSet(DiagramAction.java:247)
	at org.eclipse.gmf.runtime.diagram.ui.actions.internal.SelectAllAction.calculateEnabled(SelectAllAction.java:252)
	at org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction.refresh(DiagramAction.java:114)
	at org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler.historyNotification(AbstractActionHandler.java:602)
	at org.eclipse.core.commands.operations.DefaultOperationHistory$2.run(DefaultOperationHistory.java:941)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyListeners(DefaultOperationHistory.java:930)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyNotOK(DefaultOperationHistory.java:1029)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyNotOK(DefaultOperationHistory.java:1013)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:520)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack.execute(DiagramCommandStack.java:206)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack.execute(DiagramCommandStack.java:169)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack.execute(DiagramCommandStack.java:156)
	at org.eclipse.gef.tools.AbstractTool.executeCommand(AbstractTool.java:425)
	at org.eclipse.gef.tools.AbstractTool.executeCurrentCommand(AbstractTool.java:438)
	at org.eclipse.gmf.runtime.diagram.ui.tools.CreationTool.performCreation(CreationTool.java:133)
	at org.eclipse.gef.tools.CreationTool.handleButtonUp(CreationTool.java:189)
	at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java:1200)
	at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:301)
	at org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouseReleased(DomainEventDispatcher.java:380)
	at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(LightweightSystem.java:548)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:219)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)



How i can add a rectangle to my ScalablePolygonShape that is in the center of my PolygonShape ?

By the way : It is really hard that it is so complicated to draw a trapeze with its corresponding inline rectangle !

[Updated on: Thu, 08 December 2011 17:31]

Report message to a moderator

Re: [GMF] Custom Figure - Label Positioning [message #762846 is a reply to message #762791] Thu, 08 December 2011 17:45 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
any more suggestions ?
Re: [GMF] Custom Figure - Label Positioning [message #762972 is a reply to message #762846] Thu, 08 December 2011 22:22 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Ok some new thoughts !

Because i cant set the label position relative to the node, i tried to do it with a new layout und some subfigures.
And later on i add the WrappingLabel to a subcontainer.

At the moment im doing it like this :

public StrategyFigure() {

			
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(130),
					getMapMode().DPtoLP(50)));

			
			fFigureStrategyLabelFigure = new WrappingLabel();
			fFigureStrategyLabelFigure.setText("Strategy");

			fFigureStrategyLabelFigure.setFont(FFIGURESTRATEGYLABELFIGURE_FONT);
			LayoutManager layout = new GridLayout(1,false);
			this.setLayoutManager(layout);
			
			RectangleFigure rect1 = new RectangleFigure();
			RectangleFigure rect2 = new RectangleFigure();
			
			GridData gridData1 = new GridData();
			gridData1.widthHint = 150;
			gridData1.heightHint = 30;
			layout.setConstraint(rect1, gridData1);
			
			this.add(rect1);
			
			GridData gridData2 = new GridData();
			gridData2.widthHint = 150;
			gridData2.heightHint = 30;
			layout.setConstraint(rect2, gridData2);
			
			this.add(rect2);
	
			rect1.add(fFigureStrategyLabelFigure);
			
		}




Im using a GridLayout.
There is the first problem! This Layout doesnt work when resizing the Node. The Elements in the GridLayout always keep the size.

Second Problem. I cant add the Wrapping Label to be contained in rect1.
If i do that, the label is no longer visible in the node.
Why ?

What can i do ?




[Updated on: Thu, 08 December 2011 22:22]

Report message to a moderator

Re: [GMF] Custom Figure - Label Positioning [message #763168 is a reply to message #762972] Fri, 09 December 2011 09:38 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

> Because i cant set the label position relative to the node, i tried to
> do it with a new layout und some subfigures.

That's probably a good idea. You'll get better control on your Figure
that way.

> Im using a GridLayout.
> There is the first problem! This Layout doesnt work when resizing the
> Node. The Elements in the GridLayout always keep the size.

Using GridLayout, you can set GridData constraint on your child figures.
These GridData have a lot of cool stuff to customize the rendering of
children. It includes a "grabHorizontalSpace" and a "grabVerticalSpace"
attributes. These one may be useful for you.

> Second Problem. I cant add the Wrapping Label to be contained in rect1.
> If i do that, the label is no longer visible in the node.

You have to put a layout on rect1. A figure without a layout does not
lay out its children.

--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #763280 is a reply to message #763168] Fri, 09 December 2011 13:44 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Ok im now doing this :

	public StrategyFigure() {

			this.setForegroundColor(THIS_FORE);
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(130),
					getMapMode().DPtoLP(50)));
			fFigureStrategyLabelFigure = new WrappingLabel();
			fFigureStrategyLabelFigure.setText("Strategy");

			fFigureStrategyLabelFigure.setFont(FFIGURESTRATEGYLABELFIGURE_FONT);
			LayoutManager layout = new GridLayout(1,false);
			this.setLayoutManager(layout);
			
			RectangleFigure rect1 = new RectangleFigure();
			RectangleFigure rect2 = new RectangleFigure();
			
			
			GridData gridData1 = new GridData(GridData.FILL_HORIZONTAL);
			gridData1.widthHint = 150;
			gridData1.heightHint = 30;
			gridData1.horizontalIndent = 30;
			layout.setConstraint(rect1, gridData1);
			
			LayoutManager rect1layout = new FlowLayout();
			rect1.setLayoutManager(rect1layout);
			rect1.add(fFigureStrategyLabelFigure);
			this.add(rect1);
			
			GridData gridData2 = new GridData();
			gridData2.widthHint = 150;
			gridData2.heightHint = 30;
			layout.setConstraint(rect2, gridData2);
			
			this.add(rect2);
		}



And i looks like default.png.

But when i resize it, it still looks like default1.png.

The Problem is, how i can set the gridData1.horizontalIndent dynamically when the figure is resized ?

  • Attachment: default.png
    (Size: 2.05KB, Downloaded 253 times)
  • Attachment: default1.png
    (Size: 4.54KB, Downloaded 250 times)

[Updated on: Fri, 09 December 2011 13:44]

Report message to a moderator

Re: [GMF] Custom Figure - Label Positioning [message #763291 is a reply to message #763280] Fri, 09 December 2011 14:09 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Either you split your trapeze into 1 triange, 1 rectangle, 1 triangle to
have control over the "pieces" of your figure and put content in the
rectangle only.
Or you write your own LayoutManager that will compute location of
children according to your own logic.
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: [GMF] Custom Figure - Label Positioning [message #763295 is a reply to message #763291] Fri, 09 December 2011 14:22 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Ok i already created my own layout.

But one more issue.

I created a rectangle containing my WrappingLabel.

LayoutManager rect2Middlelayout = new FlowLayout();
rectMiddle2.setLayoutManager(rect2Middlelayout);
rectMiddle2.add(fFigureStrategyLabelFigureContent);


In the end, it looks like default2.png.

This is really what i want.
But the Wrapping label has no line breaks.
This text can be sometimes a little bit longer and i want to display it with line breaks inside of figure "rectMiddle2".
Is there a special Layout to use to get these line breaks ?
Or how can i make that ?
  • Attachment: default2.png
    (Size: 3.85KB, Downloaded 256 times)

[Updated on: Fri, 09 December 2011 15:17]

Report message to a moderator

Re: [GMF] Custom Figure - Label Positioning [message #764558 is a reply to message #763295] Mon, 12 December 2011 12:31 Go to previous message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
any suggestions ?
Previous Topic:How to skip node in object graph
Next Topic:How to link GMF Diagrams to Dawn Explorer or CDO Sessions window
Goto Forum:
  


Current Time: Thu Mar 28 10:44:30 GMT 2024

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

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

Back to the top