Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » BorderDecorator
BorderDecorator [message #726887] Mon, 19 September 2011 15:26 Go to next message
Hernan Gonzalez is currently offline Hernan Gonzalez
Messages: 158
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 #726890 is a reply to message #726887] Mon, 19 September 2011 16:02 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan Gonzalez
Messages: 158
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
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);
}

Re: BorderDecorator [message #727030 is a reply to message #726890] Tue, 20 September 2011 04:25 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1527
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);
}
Re: BorderDecorator [message #727163 is a reply to message #727030] Tue, 20 September 2011 10:46 Go to previous message
Hernan Gonzalez is currently offline Hernan Gonzalez
Messages: 158
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
Michael Wenz wrote on Tue, 20 September 2011 05:25
Definitely interesting, as I already wrote. Could you file that as a patch
to the enhancement bugzilla?


Done

https://bugs.eclipse.org/bugs/show_bug.cgi?id=358255

(now that I think of it: I hope "the enhancement bugzilla" is just the standard bugzilla...)

[Updated on: Tue, 20 September 2011 10:48]

Report message to a moderator

Previous Topic:Beginner Quest.: Animation, Zoom, Create, UI controls
Next Topic:SelectionBorder and Clickarea for polygon
Goto Forum:
  


Current Time: Mon Apr 21 00:43:08 EDT 2014

Powered by FUDForum. Page generated in 0.02339 seconds