Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Adding Label to PolylineDecoration
Adding Label to PolylineDecoration [message #156535] Tue, 02 November 2004 00:41 Go to next message
Eclipse UserFriend
Originally posted by: bandrews.nospam_bphnx.com

I cannot seem to get this to work. I got this to work with a
PolylineConnection by extending it and using the ConnectorLocator to
relocate the labels, but what I want now is the 2 labels to follow the
decorator around. So in the end, I want one Label above the source
decorator and one Label below. I tried extending the PolylineDecoration
and using an ArrowLocator to relocate the labels, however the relocate()
method expects a RotableDecoration which Label is not. Am I going about
this all wrong? What am I missing? I cannot even get the Label to show on
the screen.

thanks,

B
Re: Adding Label to PolylineDecoration [message #156569 is a reply to message #156535] Tue, 02 November 2004 16:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bandrews.nospam_bphnx.com

Well, I figured out that I should be using the ConnectionEndpointLocator
to relocate the Labels. But I still cannot figure out how to get the Label
to show in the first place. Does anyone know?

many thanks,

B

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionEndpointLocator;
import org.eclipse.draw2d.DelegatingLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PositionConstants;


public class DecorationWithText extends PolygonDecoration
{
private Connection connection;
private ConnectionEndpointLocator sourceLocator;

private Label sourceLabel = new Label("Help");

/**
*
*/
public DecorationWithText(Connection connection)
{
super();
this.connection = connection;
this.setLayoutManager(new DelegatingLayout());
sourceLocator = new ConnectionEndpointLocator(connection,true);

sourceLabel.setBackgroundColor(ColorConstants.blue);
sourceLabel.setToolTip(new Label("Help me okay"));
sourceLabel.setTextAlignment(PositionConstants.CENTER);
sourceLabel.setOpaque(true);
this.add(sourceLabel);
}

/* (non-Javadoc)
* @see org.eclipse.draw2d.IFigure#validate()
*/
public void validate()
{
if(sourceLocator != null)
sourceLocator.relocate(sourceLabel);
super.validate();
}
}



bandrews wrote:

> I cannot seem to get this to work. I got this to work with a
> PolylineConnection by extending it and using the ConnectorLocator to
> relocate the labels, but what I want now is the 2 labels to follow the
> decorator around. So in the end, I want one Label above the source
> decorator and one Label below. I tried extending the PolylineDecoration
> and using an ArrowLocator to relocate the labels, however the relocate()
> method expects a RotableDecoration which Label is not. Am I going about
> this all wrong? What am I missing? I cannot even get the Label to show on
> the screen.

> thanks,

> B
Re: Adding Label to PolylineDecoration [message #156623 is a reply to message #156535] Tue, 02 November 2004 21:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bandrews.nospam_bphnx.com

I now believe there is a bug here. I can add a Label to a
PolylineConnection just fine, but when I add it to the PolygonDecoration
it will not show. It should work the same. I checked out the
paintChildren() method, and it shows that it does have my child Label
attached and it's repaint() gets called. So I am not yet sure where the
problem lies. Can someone else confirm this is a bug, and I will log it.

thanks,

Barry


bandrews wrote:

> I cannot seem to get this to work. I got this to work with a
> PolylineConnection by extending it and using the ConnectorLocator to
> relocate the labels, but what I want now is the 2 labels to follow the
> decorator around. So in the end, I want one Label above the source
> decorator and one Label below. I tried extending the PolylineDecoration
> and using an ArrowLocator to relocate the labels, however the relocate()
> method expects a RotableDecoration which Label is not. Am I going about
> this all wrong? What am I missing? I cannot even get the Label to show on
> the screen.

> thanks,

> B
Re: Adding Label to PolylineDecoration [message #156695 is a reply to message #156623] Thu, 04 November 2004 00:50 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
I don't think children were meant to be added to PolygonDecoration. Why do
you want to add the children to the PolygonDecoration anyway? Can't you get
the same effect by using the ConnectionEndPointLocator's setUDistance() and
setVDistance() methods?

"bandrews" <bandrews@nospam_bphnx.com> wrote in message
news:cm8ukb$ovi$1@eclipse.org...
> I now believe there is a bug here. I can add a Label to a
> PolylineConnection just fine, but when I add it to the PolygonDecoration
> it will not show. It should work the same. I checked out the
> paintChildren() method, and it shows that it does have my child Label
> attached and it's repaint() gets called. So I am not yet sure where the
> problem lies. Can someone else confirm this is a bug, and I will log it.
>
> thanks,
>
> Barry
>
>
> bandrews wrote:
>
> > I cannot seem to get this to work. I got this to work with a
> > PolylineConnection by extending it and using the ConnectorLocator to
> > relocate the labels, but what I want now is the 2 labels to follow the
> > decorator around. So in the end, I want one Label above the source
> > decorator and one Label below. I tried extending the PolylineDecoration
> > and using an ArrowLocator to relocate the labels, however the relocate()
> > method expects a RotableDecoration which Label is not. Am I going about
> > this all wrong? What am I missing? I cannot even get the Label to show
on
> > the screen.
>
> > thanks,
>
> > B
>
>
Re: Adding Label to PolylineDecoration [message #156766 is a reply to message #156695] Thu, 04 November 2004 14:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bandrews.nospam_bphnx.com

If children were not meant to be added, why is there add() methods?
Anyway, I did figure out to use the ConnectionEndPointLocator to get the
same effect like you said.

But now, I have run into another problem. It seems that my labels are
always one step behind the connectors current position. So for example, if
I move an object (that has a connector attached) from the top of the
screen to the bottom, when relocate() is called from my validate() method,
the labels will still be at the top of the screen. If I resize the object,
the the labels will fall into the correct position. So it's like the
labels are always a step behind.

How do I get the labels to always stay exactly with the connector? I tried
calling super.validate() before I call relocate() and that gives the
behavior I want, but then I get weird things happening like the labels
disappear.

Thanks a lot for your reply!!

Here is my code:

import org.eclipse.draw2d.ConnectionEndpointLocator;
import org.eclipse.draw2d.DelegatingLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PolylineConnection;


public class ConnectorMultipleText extends PolylineConnection
{
private Label sourceUpperLabel,sourceLowerLabel;
private Label targetUpperLabel,targetLowerLabel;

private ConnectionEndpointLocator
sourceUpperLocator,sourceLowerLocator;
private ConnectionEndpointLocator
targetUpperLocator,targetLowerLocator;

private static final short
UPPER_SOURCE = 0,
LOWER_SOURCE = 1,
UPPER_TARGET = 2,
LOWER_TARGET = 3;

/**
*
*/
public ConnectorMultipleText()
{
super();
setLayoutManager(new DelegatingLayout());
}

protected ConnectionEndpointLocator createLocator(short type)
{
assert(type == LOWER_TARGET ||
type == LOWER_SOURCE ||
type == UPPER_TARGET ||
type == UPPER_SOURCE);

ConnectionEndpointLocator locator = null;
if(type == UPPER_TARGET || type == LOWER_TARGET)
locator = new ConnectionEndpointLocator(this,true);
else
locator = new ConnectionEndpointLocator(this,false);

locator.setUDistance(10);
if(type == LOWER_TARGET || type == LOWER_SOURCE)
locator.setVDistance(10);
else
locator.setVDistance(-10);

return locator;
}

public void validate()
{
if(sourceLowerLocator != null)
sourceLowerLocator.relocate(sourceLowerLabel);
if(sourceUpperLocator != null)
sourceUpperLocator.relocate(sourceUpperLabel);
if(targetUpperLocator != null)
targetUpperLocator.relocate(targetUpperLabel);
if(targetLowerLocator != null)
targetLowerLocator.relocate(targetLowerLabel);

super.validate();
}

/**
* @return the sourceLowerLabel.
*/
public Label getSourceLowerLabel()
{
return sourceLowerLabel;
}

/**
* @param sourceLowerLabel
*/
public void setSourceLowerLabel(Label sourceLowerLabel)
{
this.sourceLowerLabel = sourceLowerLabel;
this.add(sourceLowerLabel);
if(sourceLowerLabel != null)
this.sourceLowerLocator = createLocator(LOWER_SOURCE);
}

/**
* @return the sourceUpperLabel.
*/
public Label getSourceUpperLabel()
{
return sourceUpperLabel;
}

/**
* @param sourceUpperLabel
*/
public void setSourceUpperLabel(Label sourceUpperLabel)
{
this.sourceUpperLabel = sourceUpperLabel;
this.add(sourceUpperLabel);
if(sourceUpperLabel != null)
this.sourceUpperLocator = createLocator(UPPER_SOURCE);
}

/**
* @return the targetLowerLabel.
*/
public Label getTargetLowerLabel()
{
return targetLowerLabel;
}

/**
* @param targetLowerLabel
*/
public void setTargetLowerLabel(Label targetLowerLabel)
{
this.targetLowerLabel = targetLowerLabel;
this.add(targetLowerLabel);
if(targetLowerLabel != null)
this.targetLowerLocator = createLocator(LOWER_TARGET);
}

/**
* @return the targetUpperLabel.
*/
public Label getTargetUpperLabel()
{
return targetUpperLabel;
}

/**
* @param targetUpperLabel
*/
public void setTargetUpperLabel(Label targetUpperLabel)
{
this.targetUpperLabel = targetUpperLabel;
this.add(targetUpperLabel);
if(targetUpperLabel != null)
this.targetUpperLocator = createLocator(UPPER_TARGET);
}
}



Pratik Shah wrote:

> I don't think children were meant to be added to PolygonDecoration. Why do
> you want to add the children to the PolygonDecoration anyway? Can't you get
> the same effect by using the ConnectionEndPointLocator's setUDistance() and
> setVDistance() methods?

> "bandrews" <bandrews@nospam_bphnx.com> wrote in message
> news:cm8ukb$ovi$1@eclipse.org...
>> I now believe there is a bug here. I can add a Label to a
>> PolylineConnection just fine, but when I add it to the PolygonDecoration
>> it will not show. It should work the same. I checked out the
>> paintChildren() method, and it shows that it does have my child Label
>> attached and it's repaint() gets called. So I am not yet sure where the
>> problem lies. Can someone else confirm this is a bug, and I will log it.
>>
>> thanks,
>>
>> Barry
>>
>>
>> bandrews wrote:
>>
>> > I cannot seem to get this to work. I got this to work with a
>> > PolylineConnection by extending it and using the ConnectorLocator to
>> > relocate the labels, but what I want now is the 2 labels to follow the
>> > decorator around. So in the end, I want one Label above the source
>> > decorator and one Label below. I tried extending the PolylineDecoration
>> > and using an ArrowLocator to relocate the labels, however the relocate()
>> > method expects a RotableDecoration which Label is not. Am I going about
>> > this all wrong? What am I missing? I cannot even get the Label to show
> on
>> > the screen.
>>
>> > thanks,
>>
>> > B
>>
>>
Re: Adding Label to PolylineDecoration [message #156821 is a reply to message #156766] Thu, 04 November 2004 16:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Please post a snippet which can be executed, and remove anything not
relevant to the problem. Or, post a picture of what you are trying to do.
Re: Adding Label to PolylineDecoration [message #156828 is a reply to message #156821] Thu, 04 November 2004 16:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bandrews.nospam_bphnx.com

It's difficult to post something that will actually run because it takes
so many classes, but here I have made the snippet less complex so that
hopefully I will be more clear.

So with the code below, I can draw this:



------------- -------------
- - Help - -
- objectA ----------------- objectB -
- - - -
------------- -------------


And if I move objectA down the screen so that the connector also moves,
I get this:

-------------
- -
Help -- objectA -
- - -
- -------------
-
-
------------- -
- - -
- objectA -----------
- -
-------------


Then, if I just resize or move something just slightly (enough to cause
a repaint), then the Help label will move down where it's supposed to be.

Notice, in my validate() method I call super.validate() after the
relocate(). I also tried calling it before relocate() and that works
like I want except sometimes the label disappears.


Hopefully this is more clear?


Many thanks,

Barry



public class ConnectorMultipleText extends PolylineConnection
{
private Label sourceUpperLabel;

private ConnectionEndpointLocator sourceUpperLocator;

public ConnectorMultipleText()
{
super();
setLayoutManager(new DelegatingLayout());
sourceUpperLabel = new Label("Help");
sourceUpperLocator = createLocator();
}

protected ConnectionEndpointLocator createLocator()
{
ConnectionEndpointLocator locator = new
ConnectionEndpointLocator(this,false);
locator.setUDistance(10);
locator.setVDistance(-10);
return locator;
}

public void validate()
{
if(sourceUpperLocator != null)
sourceUpperLocator.relocate(sourceUpperLabel);

super.validate();
}


Randy Hudson wrote:
> Please post a snippet which can be executed, and remove anything not
> relevant to the problem. Or, post a picture of what you are trying to do.
>
>
Re: Adding Label to PolylineDecoration [message #156874 is a reply to message #156828] Thu, 04 November 2004 23:58 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
Hmm, looking at your code, I can clearly see that you've not come across
this article:
http://eclipse.org/articles/Article-GEF-Draw2d/GEF-Draw2d.ht ml

When you add the labels as children of the PolylineConnection, you need to
provide the endpoint locators as constraints. Then you don't need to
overridate validate() and invoke relocate() on those endpoint locators.

"Barry Andrews" <bandrews@nospam_bphnx.com> wrote in message
news:cmdn01$7p3$1@eclipse.org...
> It's difficult to post something that will actually run because it takes
> so many classes, but here I have made the snippet less complex so that
> hopefully I will be more clear.
>
> So with the code below, I can draw this:
>
>
>
> ------------- -------------
> - - Help - -
> - objectA ----------------- objectB -
> - - - -
> ------------- -------------
>
>
> And if I move objectA down the screen so that the connector also moves,
> I get this:
>
> -------------
> - -
> Help -- objectA -
> - - -
> - -------------
> -
> -
> ------------- -
> - - -
> - objectA -----------
> - -
> -------------
>
>
> Then, if I just resize or move something just slightly (enough to cause
> a repaint), then the Help label will move down where it's supposed to be.
>
> Notice, in my validate() method I call super.validate() after the
> relocate(). I also tried calling it before relocate() and that works
> like I want except sometimes the label disappears.
>
>
> Hopefully this is more clear?
>
>
> Many thanks,
>
> Barry
>
>
>
> public class ConnectorMultipleText extends PolylineConnection
> {
> private Label sourceUpperLabel;
>
> private ConnectionEndpointLocator sourceUpperLocator;
>
> public ConnectorMultipleText()
> {
> super();
> setLayoutManager(new DelegatingLayout());
> sourceUpperLabel = new Label("Help");
> sourceUpperLocator = createLocator();
> }
>
> protected ConnectionEndpointLocator createLocator()
> {
> ConnectionEndpointLocator locator = new
> ConnectionEndpointLocator(this,false);
> locator.setUDistance(10);
> locator.setVDistance(-10);
> return locator;
> }
>
> public void validate()
> {
> if(sourceUpperLocator != null)
> sourceUpperLocator.relocate(sourceUpperLabel);
>
> super.validate();
> }
>
>
> Randy Hudson wrote:
> > Please post a snippet which can be executed, and remove anything not
> > relevant to the problem. Or, post a picture of what you are trying to
do.
> >
> >
Re: Adding Label to PolylineDecoration [message #157009 is a reply to message #156874] Fri, 05 November 2004 14:45 Go to previous message
Eclipse UserFriend
Originally posted by: bandrews.nospam_bphnx.com

Ahhh! Wonderful! Not as complicated as I was trying to make it. Thanks
for the article.





Pratik Shah wrote:

> Hmm, looking at your code, I can clearly see that you've not come across
> this article:
> http://eclipse.org/articles/Article-GEF-Draw2d/GEF-Draw2d.ht ml
>
> When you add the labels as children of the PolylineConnection, you need to
> provide the endpoint locators as constraints. Then you don't need to
> overridate validate() and invoke relocate() on those endpoint locators.
>
> "Barry Andrews" <bandrews@nospam_bphnx.com> wrote in message
> news:cmdn01$7p3$1@eclipse.org...
>
>>It's difficult to post something that will actually run because it takes
>> so many classes, but here I have made the snippet less complex so that
>>hopefully I will be more clear.
>>
>>So with the code below, I can draw this:
>>
>>
>>
>>------------- -------------
>>- - Help - -
>>- objectA ----------------- objectB -
>>- - - -
>>------------- -------------
>>
>>
>>And if I move objectA down the screen so that the connector also moves,
>>I get this:
>>
>> -------------
>> - -
>> Help -- objectA -
>> - - -
>> - -------------
>> -
>> -
>>------------- -
>>- - -
>>- objectA -----------
>>- -
>>-------------
>>
>>
>>Then, if I just resize or move something just slightly (enough to cause
>>a repaint), then the Help label will move down where it's supposed to be.
>>
>>Notice, in my validate() method I call super.validate() after the
>>relocate(). I also tried calling it before relocate() and that works
>>like I want except sometimes the label disappears.
>>
>>
>>Hopefully this is more clear?
>>
>>
>>Many thanks,
>>
>>Barry
>>
>>
>>
>>public class ConnectorMultipleText extends PolylineConnection
>>{
>> private Label sourceUpperLabel;
>>
>> private ConnectionEndpointLocator sourceUpperLocator;
>>
>> public ConnectorMultipleText()
>> {
>> super();
>> setLayoutManager(new DelegatingLayout());
>> sourceUpperLabel = new Label("Help");
>> sourceUpperLocator = createLocator();
>> }
>>
>> protected ConnectionEndpointLocator createLocator()
>> {
>> ConnectionEndpointLocator locator = new
>> ConnectionEndpointLocator(this,false);
>> locator.setUDistance(10);
>> locator.setVDistance(-10);
>> return locator;
>> }
>>
>> public void validate()
>> {
>> if(sourceUpperLocator != null)
>> sourceUpperLocator.relocate(sourceUpperLabel);
>>
>> super.validate();
>> }
>>
>>
>>Randy Hudson wrote:
>>
>>>Please post a snippet which can be executed, and remove anything not
>>>relevant to the problem. Or, post a picture of what you are trying to
>
> do.
>
>>>
>
>
Previous Topic:org.eclipse.draw2d.examples?
Next Topic:Displaying some text on empty palette.
Goto Forum:
  


Current Time: Tue Jan 14 07:46:45 GMT 2025

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

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

Back to the top