|
Re: Painting a figure of a connection [message #208917 is a reply to message #208751] |
Thu, 09 February 2006 20:14 |
Steven R. Shaw Messages: 128 Registered: July 2009 |
Senior Member |
|
|
Since you are expanding the area you are painting, the clip region is
probably cutting it off. The clip region is set to the bounding box of the
figure before the paint routine.
I'd recommend you reconsider and use the PolylineDecoration instead. To
change the points, there is an api PolylineDecoration#setTemplate. Then it
is a simple matter of setting this decoration on the target or source of
your PolylineConnection class.
i.e. in the createFigure for your editpart:
PointList points = ...
PolylineConnection conn = new PolylineConnection();
PolylineDecoration td= new PolylineDecoration();
td.setTemplate(points);
conn.setTargetDecoration(td);
-Steve
"Jens" <jens.bartelheimer@gmx.de> wrote in message
news:dsclnb$8vb$1@utils.eclipse.org...
> Hi,
>
> in a previous post I ask how I can modify the appearance of a
> polylineconnection.
> (news://news.eclipse.org:119/drtapa$s61$1@utils.eclipse.org)
>
> In my current solution I override the paintFigure() method. Is this ok?
>
> But unfortunately I have a problem. I draw a rectangle with a pointlist
> and I try to fill it. But then it only fills the right/top half of my
> connectionfigure? Why? Is it a problem with the Bounds of my figure?
>
> I also have try to paint my figure with the graphics object and the draw
> methods. But then all painting also appears only in one half of my figure.
>
> Have somebody a hint for a solution?
>
> I have attached a picture of my figure and here my mentioned code:
>
> public void paintFigure(Graphics graphics) {
>
> int width = 10;
> Point start = getStart();
> Point end = getEnd();
>
> PointList points = new PointList();
> points.addPoint(start);
> points.addPoint(start.getTranslated(-width/2,0));
> points.addPoint(start.getTranslated(+width/2,0));
> points.addPoint(end.getTranslated(+width/2,0));
> points.addPoint(end.getTranslated(-width/2,0));
> points.addPoint(start.getTranslated(-width/2,0));
> points.addPoint(end.getTranslated(-width/2,0));
> points.addPoint(end);
> setPoints(points);
>
> graphics.setBackgroundColor(ColorConstants.blue);
> graphics.fillPolygon(points);
>
> super.paintFigure(graphics);
> }
>
>
>
>
------------------------------------------------------------ ----------------
----
|
|
|
Re: some general questions [message #209005 is a reply to message #208917] |
Fri, 10 February 2006 11:04 |
Jens Bartelheimer Messages: 44 Registered: July 2009 |
Member |
|
|
Thanks Steve.
I have solved my problem with a MidpointLocator.
But I have got some general questions.
Is it right to initialize the figure in the constructor and then set the
size, ... in the paintFigure method depending on the getBounds() result?
And am I right that getBounds() returns the area where I can draw figures?
Is it possible to modify this area with the setBounds() method or should
I avoid this way?
public class ActivationBarFigure extends MyIndirectConnectionFigure {
RectangleFigure bar = new RectangleFigure();
final int width = 10;
public ActivationBarFigure() {
add(bar,new MidpointLocator(this,0));
}
public void paintFigure(Graphics graphics) {
//Set the height of the bar
Rectangle r = getBounds().getCopy();
bar.setSize(width,r.height);
super.paintFigure(graphics);
}
}
Jens
Steven Shaw wrote:
> Since you are expanding the area you are painting, the clip region is
> probably cutting it off. The clip region is set to the bounding box of the
> figure before the paint routine.
>
> I'd recommend you reconsider and use the PolylineDecoration instead. To
> change the points, there is an api PolylineDecoration#setTemplate. Then it
> is a simple matter of setting this decoration on the target or source of
> your PolylineConnection class.
>
> i.e. in the createFigure for your editpart:
>
> PointList points = ...
> PolylineConnection conn = new PolylineConnection();
> PolylineDecoration td= new PolylineDecoration();
> td.setTemplate(points);
> conn.setTargetDecoration(td);
>
> -Steve
>
> "Jens" <jens.bartelheimer@gmx.de> wrote in message
> news:dsclnb$8vb$1@utils.eclipse.org...
>> Hi,
>>
>> in a previous post I ask how I can modify the appearance of a
>> polylineconnection.
>> (news://news.eclipse.org:119/drtapa$s61$1@utils.eclipse.org)
>>
>> In my current solution I override the paintFigure() method. Is this ok?
>>
>> But unfortunately I have a problem. I draw a rectangle with a pointlist
>> and I try to fill it. But then it only fills the right/top half of my
>> connectionfigure? Why? Is it a problem with the Bounds of my figure?
>>
>> I also have try to paint my figure with the graphics object and the draw
>> methods. But then all painting also appears only in one half of my figure.
>>
>> Have somebody a hint for a solution?
>>
>> I have attached a picture of my figure and here my mentioned code:
>>
>> public void paintFigure(Graphics graphics) {
>>
>> int width = 10;
>> Point start = getStart();
>> Point end = getEnd();
>>
>> PointList points = new PointList();
>> points.addPoint(start);
>> points.addPoint(start.getTranslated(-width/2,0));
>> points.addPoint(start.getTranslated(+width/2,0));
>> points.addPoint(end.getTranslated(+width/2,0));
>> points.addPoint(end.getTranslated(-width/2,0));
>> points.addPoint(start.getTranslated(-width/2,0));
>> points.addPoint(end.getTranslated(-width/2,0));
>> points.addPoint(end);
>> setPoints(points);
>>
>> graphics.setBackgroundColor(ColorConstants.blue);
>> graphics.fillPolygon(points);
>>
>> super.paintFigure(graphics);
>> }
>>
>>
>>
>>
>
>
> ------------------------------------------------------------ ----------------
> ----
>
>
>
>
>
|
|
|
Re: some general questions [message #209055 is a reply to message #209005] |
Fri, 10 February 2006 15:53 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
draw2d works in two steps. The first step is validation, which lays out
everything, and sets the bounds. The second step is painting. You should not
change the bounds during painting, since that will cause a repaint
(potentially infinite).
"Jens" <jens.bartelheimer@gmx.de> wrote in message
news:dshs0e$3bp$1@utils.eclipse.org...
> Thanks Steve.
>
> I have solved my problem with a MidpointLocator.
>
> But I have got some general questions.
> Is it right to initialize the figure in the constructor and then set the
> size, ... in the paintFigure method depending on the getBounds() result?
>
> And am I right that getBounds() returns the area where I can draw figures?
> Is it possible to modify this area with the setBounds() method or should I
> avoid this way?
>
> public class ActivationBarFigure extends MyIndirectConnectionFigure {
> RectangleFigure bar = new RectangleFigure();
> final int width = 10;
>
> public ActivationBarFigure() {
> add(bar,new MidpointLocator(this,0));
> }
>
> public void paintFigure(Graphics graphics) {
> //Set the height of the bar
> Rectangle r = getBounds().getCopy();
> bar.setSize(width,r.height);
> super.paintFigure(graphics);
> }
>
>
> }
>
> Jens
>
> Steven Shaw wrote:
>> Since you are expanding the area you are painting, the clip region is
>> probably cutting it off. The clip region is set to the bounding box of
>> the
>> figure before the paint routine.
>>
>> I'd recommend you reconsider and use the PolylineDecoration instead. To
>> change the points, there is an api PolylineDecoration#setTemplate. Then
>> it
>> is a simple matter of setting this decoration on the target or source of
>> your PolylineConnection class.
>>
>> i.e. in the createFigure for your editpart:
>>
>> PointList points = ...
>> PolylineConnection conn = new PolylineConnection();
>> PolylineDecoration td= new PolylineDecoration();
>> td.setTemplate(points);
>> conn.setTargetDecoration(td);
>>
>> -Steve
>>
>> "Jens" <jens.bartelheimer@gmx.de> wrote in message
>> news:dsclnb$8vb$1@utils.eclipse.org...
>>> Hi,
>>>
>>> in a previous post I ask how I can modify the appearance of a
>>> polylineconnection.
>>> (news://news.eclipse.org:119/drtapa$s61$1@utils.eclipse.org)
>>>
>>> In my current solution I override the paintFigure() method. Is this ok?
>>>
>>> But unfortunately I have a problem. I draw a rectangle with a pointlist
>>> and I try to fill it. But then it only fills the right/top half of my
>>> connectionfigure? Why? Is it a problem with the Bounds of my figure?
>>>
>>> I also have try to paint my figure with the graphics object and the draw
>>> methods. But then all painting also appears only in one half of my
>>> figure.
>>>
>>> Have somebody a hint for a solution?
>>>
>>> I have attached a picture of my figure and here my mentioned code:
>>>
>>> public void paintFigure(Graphics graphics) {
>>>
>>> int width = 10;
>>> Point start = getStart();
>>> Point end = getEnd();
>>>
>>> PointList points = new PointList();
>>> points.addPoint(start);
>>> points.addPoint(start.getTranslated(-width/2,0));
>>> points.addPoint(start.getTranslated(+width/2,0));
>>> points.addPoint(end.getTranslated(+width/2,0));
>>> points.addPoint(end.getTranslated(-width/2,0));
>>> points.addPoint(start.getTranslated(-width/2,0));
>>> points.addPoint(end.getTranslated(-width/2,0));
>>> points.addPoint(end);
>>> setPoints(points);
>>>
>>> graphics.setBackgroundColor(ColorConstants.blue);
>>> graphics.fillPolygon(points);
>>>
>>> super.paintFigure(graphics);
>>> }
>>>
>>>
>>>
>>>
>>
>>
>> ------------------------------------------------------------ ----------------
>> ----
>>
>>
>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.07212 seconds