Home » Modeling » Graphiti » How to achieve floating/attached labels?
|
Re: How to achieve floating/attached labels? [message #1395943 is a reply to message #1395139] |
Mon, 07 July 2014 16:36 |
Martin Hanysz Messages: 30 Registered: November 2013 |
Member |
|
|
Hello Homer,
there are actually multiple ways to achieve this.
What I did in my project is to create an invisible container shape that holds the shape you want to label and the label itself. This way you have them grouped together very nicely, but the downside is that you will be able to select the invisible shape and manipulate it. This will most likely confuse your users. To overcome this, I decided to makt the invisible container shape inactive, but that in turn requires special treatment in some places, e.g. the children of inactive shapes are not automatically updated and the coordinate system of the active children is not relative to the inactive parent but to the next active parent up the hierarchy. But these limitations can be handled at a few places in your code if you design your classes right.
Another way you may consider is to simply have two separate shapes, the one you want to label and the label itself, that have a reference to each other. For that reference you can use the property mechanism to give the labeled shape a "label" property and vice versa. Once you manipulate the position of the labeled shape, you need to remember to move the label, too.
I hope these two ideas give you a starting point.
Best regards,
Martin
|
|
|
Re: How to achieve floating/attached labels? [message #1396635 is a reply to message #1395943] |
Tue, 08 July 2014 15:26 |
Homer S Messages: 13 Registered: June 2014 |
Junior Member |
|
|
Hi Martin,
thanks for this detailed answer!
Martin Hanysz wrote on Mon, 07 July 2014 16:36What I did in my project is to create an invisible container shape that holds the shape you want to label and the label itself. This way you have them grouped together very nicely, but the downside is that you will be able to select the invisible shape and manipulate it. This will most likely confuse your users. To overcome this, I decided to makt the invisible container shape inactive, but that in turn requires special treatment in some places, e.g. the children of inactive shapes are not automatically updated and the coordinate system of the active children is not relative to the inactive parent but to the next active parent up the hierarchy. But these limitations can be handled at a few places in your code if you design your classes right.
Before the project started I, too, thought I could use this approach. But:
The labeled shape is inside a container shape and the label should be outside the frame of the container. Since shapes clip any of their children when they go beyond their frame.
Martin Hanysz wrote on Mon, 07 July 2014 16:36Another way you may consider is to simply have two separate shapes, the one you want to label and the label itself, that have a reference to each other. For that reference you can use the property mechanism to give the labeled shape a "label" property and vice versa. Once you manipulate the position of the labeled shape, you need to remember to move the label, too.
Well, I guess I've missed something on the docs.
Thanks for the hint. I suspect you meant this entry: Using User-Defined Properties
I'll go and dig through it then.
But feel free to respond in more detail regarding the property approach
Best regards,
Homer
|
|
| |
Re: How to achieve floating/attached labels? [message #1398018 is a reply to message #1397865] |
Thu, 10 July 2014 13:44 |
Homer S Messages: 13 Registered: June 2014 |
Junior Member |
|
|
Martin Hanysz wrote on Thu, 10 July 2014 09:09By nesting both, the label and the labelled shape, in the invisible container, you can place the label outside of the bounds of the shape you want to label e.g. below it. As far as I know, inactive shapes do not clip their children at their own borders. That means the size of the invisible and inactive container does not matter at all.
My problem is, that the label needs to outside the bounds of my visible container. Maybe a visual is better to explain my problem:
The big solid rectangle is my visible container. The red lines are the shapes/GAs to be labeled. The texts are the labels, obvious And the dashed rectangles are the invisible containers.
So my visible container will clip the labels inside the invisible containers. The invisible container to group label and labeled shape can't be inactive, cause the user has to be able to move them horizontally, so he can define his own spacing, but that's a whole other story.
Martin Hanysz wrote on Thu, 10 July 2014 09:09Regarding the property approach: you got the right link. User defined Properties are really just a string to string map that each property container (a superclass of all shapes) has. So you just need to find a way to map shapes to strings somehow.
So, I'd need to implement some kind of search function, right? Isn't this already accomplished via the IdPattern?
Has anybody done this before and could help explain this to me?
Thanks!
|
|
| | |
Re: How to achieve floating/attached labels? [message #1401315 is a reply to message #1401275] |
Tue, 15 July 2014 12:44 |
Marek Jagielski Messages: 97 Registered: April 2012 |
Member |
|
|
For my project I took from bpmn2-modeler only the idea how to make labels. I see now that it was a little bit refactored since the time I was looking at that. It seems cleaner than what I have in my project:
+ Here you have all features concerning label. https://github.com/eclipse/bpmn2-modeler/tree/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/label
+ I think here is the code that has inspired me: https://github.com/eclipse/bpmn2-modeler/blob/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/label/AbstractAddLabelFeature.java
There you have lines that links label and shape with business object:
peService.setPropertyValue(labelShape, GraphitiConstants.LABEL_SHAPE, Boolean.toString(true));
link(labelShape, new Object[] {businessObject, labelOwner});
link(labelOwner, new Object[] {labelShape});
In bpmn2-modeler they are grouping features in containers: https://github.com/eclipse/bpmn2-modeler/blob/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/label/LabelFeatureContainer.java
+ A lot of utils related to labels you can find here: https://github.com/eclipse/bpmn2-modeler/blob/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/FeatureSupport.java
The most aptly called method is:
public static boolean isLabelShape(PictogramElement shape) {
if (shape==null)
return false;
return Graphiti.getPeService().getPropertyValue(shape, GraphitiConstants.LABEL_SHAPE) != null;
}
I don't know how in this project but in my project I have some amount of small bugs concerning this solution to be still treated. For example, if I select more objects shapes and labels and I move them with arrays on keyboard, the labels are "moved twice". You have to think about these things.
Marek
[Updated on: Tue, 15 July 2014 12:47] Report message to a moderator
|
|
| | | |
Goto Forum:
Current Time: Fri Apr 26 13:33:16 GMT 2024
Powered by FUDForum. Page generated in 0.03993 seconds
|