Home » Modeling » GMF (Graphical Modeling Framework) » [GMF] Custom Figure - Label Positioning
| | | | | |
Re: [GMF] Custom Figure - Label Positioning [message #761569 is a reply to message #761552] |
Tue, 06 December 2011 17:09 |
Snakebyte Missing name 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 |
|
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 |
Snakebyte Missing name 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 252 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 |
|
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 #762791 is a reply to message #762742] |
Thu, 08 December 2011 16:18 |
Snakebyte Missing name 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 #762972 is a reply to message #762846] |
Thu, 08 December 2011 22:22 |
Snakebyte Missing name 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 |
|
> 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 |
Snakebyte Missing name 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 261 times) -
Attachment: default1.png
(Size: 4.54KB, Downloaded 256 times)
[Updated on: Fri, 09 December 2011 13:44] Report message to a moderator
|
|
| | | |
Goto Forum:
Current Time: Wed Sep 25 05:08:45 GMT 2024
Powered by FUDForum. Page generated in 0.05483 seconds
|