|
Re: How to resize Polygon shapes and How to have a multiline text [message #563633 is a reply to message #563582] |
Fri, 20 August 2010 09:28 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
I'll try...
to Q1)
Yes, you are right. The framework does not support it out-of the-box. What
you would need to do is scale the points of your Polygon according to the
size change. This can be done in the Resize feature of course, but for a
more general usage it would be good to place it inside the layout feature
(if you have other operations that affect the size of a shape but do not
trigger a resize).
You could do something like this in the resize feature (quite into the
blue - there's probable better implementations...):
@Override
public void resizeShape(IResizeShapeContext context) {
super.resizeShape(context);
// Get new sizes
int width = context.getWidth();
int height = context.getHeight();
// Get old sizes. They are defined by the max values for x and y on all
// points
PictogramElement pictogramElement = context.getPictogramElement();
Polygon polygon = (Polygon) pictogramElement.getGraphicsAlgorithm();
EList<Point> points = polygon.getPoints();
int maxX = 0;
int maxY = 0;
for (Iterator<Point> iterator = points.iterator(); iterator.hasNext();) {
Point point = iterator.next();
if (point.getX() > maxX) {
maxX = point.getX();
}
if (point.getY() > maxY) {
maxY = point.getY();
}
}
// Compute scale factor
float scaleX = width / maxX;
float scaleY = height / maxY;
if (scaleX != 1 || scaleY != 1) {
for (Iterator<Point> iterator = points.iterator(); iterator.hasNext();) {
Point point = iterator.next();
int newX = Math.round(point.getX() * scaleX);
point.setX(newX);
int newY = Math.round(point.getY() * scaleY);
point.setY(newY);
}
}
}
to Q2)
The line to create the MultiText looks ok. Basically the MultiText is quite
similar to the Text, the main difference is that it allows setting the
number of lines to show and it supports line breaks. I changed the the
TutorialAddEClassFeature to come up with a MultiText instead of a text.
Here's the part of the add method I applied changes:
// SHAPE WITH LINE
{
// create shape for line
final Shape shape = peCreateService.createShape(containerShape, false);
// create and set graphics algorithm
final Polyline polyline = gaService.createPolyline(shape, new int[] { 0, 40,
width, 40 });
polyline.setStyle(StyleUtil.getStyleForEClass(getDiagram())) ;
}
// SHAPE WITH TEXT
{
// create shape for text
final Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
final MultiText text = gaService.createMultiText(shape, addedClass.getName()
+ "\n" + addedClass.getOperationCount());
text.setStyle(StyleUtil.getStyleForEClassText(getDiagram())) ;
gaService.createFont(text, "Arial", 8);
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.getFont().setBold(true);
text.setHeight(2);
gaService.setLocationAndSize(text, 0, 0, width, 40);
Of course you would also need to adapt the layout, direct editing and others
features dealing with the Text object.
I hope this helps...
-Michael
"Daniele" <barone.daniele@gmail.com> wrote in message
news:i4kr2u$vq$1@build.eclipse.org...
> Hi there,
> I am using Graphiti to develop an editor for a model in which business
> objects are associated with different shapes. I have two questions and I
> really hope that you guys will be able to help me:
>
> Q1) For some of these shapes I am using Polygons. Therefore, is the
> resize functionality already provided by the framework for Polygons(in a
> way similar to Rectangle, Ellipse, etc.)?
> I am not an expert of eclipse or java but it seems that the answer is NO.
> Am I wrong?
>
> If I am not should I implement the resizeShape method to resize Ploygon
> shapes? if YES can you provide me with an example :)
>
>
> Q2) For all the shapes I need a multiline text similar to the notes shape
> in the UML editor. Should I use something such as:
>
> "MultiText text = gaService.createDefaultMultiText(shape,
> addedClass.getName());"
>
> ?
> Do you have an example for the EClass Shape in which instead of having a
> line for the name of the class I can have a multiline description?
>
> Thank you in advance for any suggestions or help.
> Daniele
>
|
|
|
Powered by
FUDForum. Page generated in 0.04312 seconds