Home » Modeling » Graphiti » Move diagram along with text
Move diagram along with text [message #1721403] |
Wed, 27 January 2016 07:51  |
Kailas Patil Messages: 5 Registered: January 2016 |
Junior Member |
|
|
i am try to draw diagram with name on bottom ,but when i move my diagram ,name not movie along with it.
my Code :
{
final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height);
ellipse = gaService.createPlainEllipse(invisibleRectangle);
ellipse.setStyle(StyleUtil.getStyleForStartClass(featureSupport.getCustomDiagram()));
gaService.setLocationAndSize(ellipse, 0, 0, width, height);
final Text text = gaService.createPlainText(containerDecorator, "Script");
text.setStyle(StyleUtil.getStyleForEClassText(featureSupport.getCustomDiagram()));
text.setFont(gaService.manageDefaultFont(featureSupport.getCustomDiagram(), false, true));
gaService.setLocationAndSize(text, context.getX()-15, context.getY()+30, decoratorWidth, decoratorHeight);
featureSupport.customLink(containerShape, addedClass);
featureSupport.customLink(containerDecorator, addedClass);
}
|
|
| |
Re: Move diagram along with text [message #1721550 is a reply to message #1721472] |
Thu, 28 January 2016 09:22   |
Kailas Patil Messages: 5 Registered: January 2016 |
Junior Member |
|
|
Hi Michael
i am try using shape which contain text graphic algorithms but it underlapped with ellipse.
Ellipse ellipse;
{
final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height);
ellipse = gaService.createPlainEllipse(invisibleRectangle);
ellipse.setStyle(StyleUtil.getStyleForStartClass(featureSupport.getCustomDiagram()));
gaService.setLocationAndSize(ellipse, 0, 0, width, height);
if (addedClass.eResource() == null) {
featureSupport.getCustomDiagram().eResource().getContents().add(addedClass);
}
featureSupport.customLink(containerShape, addedClass);
}
{
final Shape shape = peCreateService.createShape(containerShape, true);
final Text text = gaService.createPlainText(shape, addedClass.getName());
text.setStyle(StyleUtil.getStyleForEClassText(featureSupport.getCustomDiagram()));
text.setFont(gaService.manageDefaultFont(featureSupport.getCustomDiagram(), false, true));
gaService.setLocationAndSize(text, context.getX() - 22, context.getY() + 33, decoratorWidth,
decoratorHeight);
featureSupport.customLink(shape, addedClass);
}
thats why i make another container with name containerDecorator. for just simplify i want diagram with name , but invisible rectangle of diagram not contain a name ,name should be independent from invisible rectangle
|
|
| | |
Re: Move diagram along with text [message #1721764 is a reply to message #1721718] |
Fri, 29 January 2016 22:52   |
Marek Jagielski Messages: 97 Registered: April 2012 |
Member |
|
|
You can look at my code for inspiration:
public class MoveElementFeature extends DefaultMoveShapeFeature {
public MoveElementFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canMoveShape(IMoveShapeContext context) {
if(context.getSourceContainer() == null) return false;
if(context.getSourceContainer().equals(context.getTargetContainer())) return true;
Shape shape = context.getShape();
ContainerShape targetShape = null;
// can move on label place
for(EObject o : shape.getLink().getBusinessObjects())
if(o instanceof Shape && Graphiti.getPeService().getPropertyValue((Shape) o, SicConstants.LABEL_PROPERTY) != null)
targetShape = (ContainerShape) o;
if(targetShape != null && targetShape.equals(context.getTargetContainer())) return true;
return false;
}
@Override
protected void preMoveShape(IMoveShapeContext context) {
super.preMoveShape(context);
}
@Override
public void moveShape(IMoveShapeContext context) {
Shape shape = context.getTargetContainer();
if(Graphiti.getPeService().getPropertyValue(shape, SicConstants.LABEL_PROPERTY) != null) {
MoveShapeContext c = (MoveShapeContext) context;
c.setTargetContainer(shape.getContainer());
c.setDeltaX(c.getDeltaX() + shape.getGraphicsAlgorithm().getX());
c.setDeltaY(c.getDeltaY() + shape.getGraphicsAlgorithm().getY());
c.setX(c.getX() + shape.getGraphicsAlgorithm().getX());
c.setY(c.getY() + shape.getGraphicsAlgorithm().getY());
}
super.moveShape(context);
}
@Override
protected void postMoveShape(final IMoveShapeContext context) {
Shape shape = context.getShape();
// move also label
for (EObject o : shape.getLink().getBusinessObjects()) {
if (o instanceof Shape && Graphiti.getPeService().getPropertyValue((Shape)o, SicConstants.LABEL_PROPERTY) != null) {
ContainerShape textContainerShape = (ContainerShape)o;
int dx = context.getDeltaX();
int dy = context.getDeltaY();
textContainerShape.getGraphicsAlgorithm().setX(textContainerShape.getGraphicsAlgorithm().getX() + dx);
textContainerShape.getGraphicsAlgorithm().setY(textContainerShape.getGraphicsAlgorithm().getY() + dy);
}
}
super.postMoveShape(context);
}
}
1. MoveElementFeature handle all object with label.
2. In canMoveShape I enable to put shape where the label is as label will move from its place.
3. In moveShape I handle above situation.
4. In postMoveShape I move linked label.
Marek
[Updated on: Fri, 29 January 2016 22:53] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Thu Jun 01 21:54:20 GMT 2023
Powered by FUDForum. Page generated in 0.01871 seconds
|