| Style attributes were not considered [message #869331] |
Thu, 03 May 2012 04:38  |
Steffen K. Messages: 1 Registered: May 2012 |
Junior Member |
|
|
Hi,
we from the Spray project have a problem with the usage of styles in Graphiti.
It's our plan to set all relevant style attributes (e.g. line widht, line style) for a shape on one style.
But we faced a problem with the usage of styles. If we e.g. want to set the line width for an ellipse within a style, this has no effect in Graphiti.
Below the source code for a better illustration of our issue (AddFeature - creation of an ellipse and usage of style for the attribute line width).
public class AddUseCaseFeature extends AbstractAddShapeFeature {
public AddUseCaseFeature(IFeatureProvider fp) {
super(fp);
}
public PictogramElement add(IAddContext context) {
Diagram targetDiagram = (Diagram) context.getTargetContainer();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
ContainerShape containerShape =
peCreateService.createContainerShape(targetDiagram, true);
int width = context.getWidth() < 100 ? 100 : context.getWidth();
int height = context.getHeight() < 40 ? 40 : context.getHeight();
IGaService gaService = Graphiti.getGaService();
// create ellipse
GraphicsAlgorithm e = gaService.createEllipse(containerShape);
e.setWidth(width);
e.setHeight(height);
// create style and set attributes
Style style = gaService.createStyle(getDiagram(), "Test1");
style.setBackground(manageColor(IColorConstant.WHITE));
style.setLineVisible(true);
// set line width to 10
style.setLineWidth(10);
// set style on ellipse
e.setStyle(style);
gaService.setLocationAndSize(e, context.getX(), context.getY(),
width, height);
layoutPictogramElement(containerShape);
return containerShape;
}
The result of this source code is an ellipse with a line width of 1 and not as declared in the style with a width of 10 (see image below).

We tried a lot and the only possibility we found, is to set the line width on the ellipse first to "null" and after that the value set in the style is considered. With the procedure we override the values which were set initially by graphiti on the creation of a new shape element.
So if we add the source code snippet below to our implementation the line width of the style is used by Graphiti.
...
// set line width to 10
style.setLineWidth(10);
// [b]overwrite standard line width of ellipse[/b]
e.setLineWidth(null);
// set style on ellipse
e.setStyle(style);
...
If we do so, we get the expected result (see attachment below).

For us it's important to know, if there is a better solution to handle our requirement. We designed our application in a way, were we want to set all values for the style of a shape on a seperate style object and not directly on the shape element (e.g. the ellipse).
Is there maybe a way to disable the setting of default style attributes by Graphiti on the instantiation of a new shape element? Is there a possibility to change the hierarchy in which way the valid style attributes are determine?
We will be gratefull for any suggestion or solution.
|
|
|