Home » Modeling » Graphiti » BorderDecorator
BorderDecorator [message #726887] |
Mon, 19 September 2011 19:26 |
Hernan Gonzalez Messages: 188 Registered: October 2010 Location: Buenos Aires, Argentina |
Senior Member |
|
|
I implemented (for my own needs, as explained/hinted here and here) a BorderDecorator, that displays a filled border, of setteable width and color around a figure. I had to do that inside Graphiti code, of course, but the modifications were few. In case someone is interested, or the Graphiti team likes the idea:
public class BorderDecorator extends AbstractDecorator {
protected int borderWidth;
protected int r,g,b;
public BorderDecorator(int borderwidth,int r,int g,int b) {
this.borderWidth=borderwidth;
this.r=r;
this.g=g;
this.b=b;
}
// setters getters ...
}
public class PictogramElementDelegate implements IPictogramElementDelegate {
private IFigure decorateFigure(final IFigure figure, final IDecorator decorator) {
...
if (decorator instanceof BorderDecorator) {
BorderDecorator hdecorator = ((BorderDecorator) decorator);
if (hdecorator.getBorderWidth() > 0) {
Color color = getConfigurationProvider().getResourceRegistry().getSwtColor(hdecorator.getR(), hdecorator.getG(), hdecorator.getB());
figure.setBorder(new LineBorder(color, hdecorator.getBorderWidth()));
}
}
return decoratorFigure;
}
protected void addDecorators(final GraphicsAlgorithm graphicsAlgorithm, final PictogramElement pe, final IFigure figure,
IToolBehaviorProvider toolBehaviorProvider) {
....
if (decorateFigure != null) decList.add(decorateFigure);
}
|
|
| |
Re: BorderDecorator [message #727030 is a reply to message #726890] |
Tue, 20 September 2011 08:25 |
Michael Wenz Messages: 1931 Registered: July 2009 Location: Walldorf, Germany |
Senior Member |
|
|
Definitely interesting, as I already wrote. Could you file that as a patch
to the enhancement bugzilla?
Thanks,
Michael
"Hernan" schrieb im Newsbeitrag news:j586f5$5s2$1@news.eclipse.org...
A correction: if we intend the decorator to be dynamic (as I do), we need to
add the line
figure.setBorder(null);
to
PictogramElementDelegate.refreshFigureColors(IFigure figure,
GraphicsAlgorithm graphicsAlgorithm)
Further, we can also add some background color with a similar class -or the
same, if we add some isBackground() method.
Just add to decorateFigure() the following:
Color color =
getConfigurationProvider().getResourceRegistry().getSwtColor(hdecorator.getR(),
hdecorator.getG(), hdecorator.getB());
if (hdecorator.isBorder() && hdecorator.getBorderwidth()>0) {
figure.setBorder(new LineBorder(color, hdecorator.getBorderwidth()));
} else { // background
figure.setBackgroundColor(color);
if(figure instanceof Shape)
((Shape)figure).setFill(true);
}
|
|
| |
Goto Forum:
Current Time: Fri Apr 26 13:47:10 GMT 2024
Powered by FUDForum. Page generated in 0.02718 seconds
|