Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Painting a figure of a connection
Painting a figure of a connection [message #208751] Wed, 08 February 2006 11:46 Go to next message
Jens Bartelheimer is currently offline Jens BartelheimerFriend
Messages: 44
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------030404020701040306020002
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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);
}




--------------030404020701040306020002
Content-Type: image/gif;
name="connection.GIF"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="connection.GIF"

R0lGODlhJABiAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgMDAwP8AAAD/ AP//AAAA//8A
/wD//////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMwAAZgAAmQAAzAAA/wAz AAAzMwAzZgA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UtVLtC+eOeardt2sE+4gPcK1kt4ceLG f8EGjpxWo93H
h/lKVvyPbmaBnode3gw59NLRlSmu9WtaLWq2oA2LLsz4M2XYt1nLPq05dcfX umvPji2cN3HM
w3NPbm25N27mqoEv3+2aNvKlI0c6Nen7bPea332GIx86Hvv28+irlle7Pr37 9/Djy59Pv779
+/jz69/Pv79//wEBADs=
--------------030404020701040306020002--
Re: Painting a figure of a connection [message #208917 is a reply to message #208751] Thu, 09 February 2006 20:14 Go to previous messageGo to next message
Steven R. Shaw is currently offline Steven R. ShawFriend
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 Go to previous messageGo to next message
Jens Bartelheimer is currently offline Jens BartelheimerFriend
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 Go to previous message
Eclipse UserFriend
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);
>>> }
>>>
>>>
>>>
>>>
>>
>>
>> ------------------------------------------------------------ ----------------
>> ----
>>
>>
>>
>>
Previous Topic:Composite edit parts and figure hierarchy
Next Topic:Re: Will antialiasing API appear on IFigure?
Goto Forum:
  


Current Time: Fri Jan 17 09:15:14 GMT 2025

Powered by FUDForum. Page generated in 0.07212 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top