Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Anchor Problem or Router Problem??
Anchor Problem or Router Problem?? [message #176212] Fri, 08 April 2005 15:33 Go to next message
Eclipse UserFriend
Originally posted by: binti.ksu.edu

Hi all,

I am writing an editor that draws sequence diagrams. What I want is the
connections should be created where the user clicks (atleast the the y
coordinate should be that) and I return this location from my own anchor. I
set the request location in this and return it from there.

The code for my anchor is this-

public MyAnchor(IFigure source, Point location)
{
super(source);
this.location = location;
}

public Point getLocation(Point reference)
{
Rectangle r = getOwner().getBounds().getCopy();
getOwner().translateToAbsolute(r);
int off = r.width / 2;
Point p = null;
if(location == null)
{
p = new Point(r.x + r.width/2, reference.y);
}
else
{
p = new Point(r.x + r.width/2, location.y);
}
return p;

}

So when I have created the connection, I assume getSourceConnectionAnchor()
and getTargetConnectionAnchor() have been called and the location is set
with the request location, but it still is null here and it returns the
refernce point. Therefore, the connection all start and end from on center
to another (i.e. reference point's y coordinate).

BUT WHEN I CLOSE THE DIAGRAM AND RE OPEN IT, THE CONNECTIONS LOOK FINE.

This is the code for my NodeEditPart -
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart
connectionEditPart)
{
MyConnectionPart connectionPart = (MyConnectionPart)connectionEditPart;
MyConnection connection= (ActionFlow)connectionPart.getModel();
return new MyAnchor(getFigure(), connection.getLocation());
}

public ConnectionAnchor getSourceConnectionAnchor(Request request)
{
CreateConnectionRequest req = (CreateConnectionRequest) request;
return new MyAnchor(getFigure(), req.getLocation());
}

And I have saved the request location with the connection Model. These
methods are similar for Target as well.

Can someone please explain what is going wrong?

Thanks in Advance,
Binti.
Re: Anchor Problem or Router Problem?? [message #176295 is a reply to message #176212] Fri, 08 April 2005 21:41 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
If the location is not set in the model, obviously the problem's with the
model, and not GEF. My guess is that you're setting the connection's source
and target (which cause it to refresh) before its location. In your
connection creation command, if you set the connection's location before its
source or target, I think it would solve your problem.

BTW, for the sake of performance, you should add a setLocation() method on
your anchor class, and then you can have one anchor per EditPart. All the
get*Anchor() methods should then return this same anchor (with the location
updated, of course).

"Binti Sepaha" <binti@ksu.edu> wrote in message
news:d368hn$672$1@news.eclipse.org...
> Hi all,
>
> I am writing an editor that draws sequence diagrams. What I want is the
> connections should be created where the user clicks (atleast the the y
> coordinate should be that) and I return this location from my own anchor.
I
> set the request location in this and return it from there.
>
> The code for my anchor is this-
>
> public MyAnchor(IFigure source, Point location)
> {
> super(source);
> this.location = location;
> }
>
> public Point getLocation(Point reference)
> {
> Rectangle r = getOwner().getBounds().getCopy();
> getOwner().translateToAbsolute(r);
> int off = r.width / 2;
> Point p = null;
> if(location == null)
> {
> p = new Point(r.x + r.width/2, reference.y);
> }
> else
> {
> p = new Point(r.x + r.width/2, location.y);
> }
> return p;
>
> }
>
> So when I have created the connection, I assume
getSourceConnectionAnchor()
> and getTargetConnectionAnchor() have been called and the location is set
> with the request location, but it still is null here and it returns the
> refernce point. Therefore, the connection all start and end from on center
> to another (i.e. reference point's y coordinate).
>
> BUT WHEN I CLOSE THE DIAGRAM AND RE OPEN IT, THE CONNECTIONS LOOK FINE.
>
> This is the code for my NodeEditPart -
> public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart
> connectionEditPart)
> {
> MyConnectionPart connectionPart = (MyConnectionPart)connectionEditPart;
> MyConnection connection= (ActionFlow)connectionPart.getModel();
> return new MyAnchor(getFigure(), connection.getLocation());
> }
>
> public ConnectionAnchor getSourceConnectionAnchor(Request request)
> {
> CreateConnectionRequest req = (CreateConnectionRequest) request;
> return new MyAnchor(getFigure(), req.getLocation());
> }
>
> And I have saved the request location with the connection Model. These
> methods are similar for Target as well.
>
> Can someone please explain what is going wrong?
>
> Thanks in Advance,
> Binti.
>
>
Re: Anchor Problem or Router Problem?? [message #176591 is a reply to message #176295] Mon, 11 April 2005 02:30 Go to previous message
Eclipse UserFriend
Originally posted by: binti.ksu.edu

Hey this worked too. Gr8.

Thanks a lot for your help.

Binti.


"Pratik Shah" <ppshah@us.ibm.com> wrote in message
news:d36u2s$4qo$1@news.eclipse.org...
> If the location is not set in the model, obviously the problem's with the
> model, and not GEF. My guess is that you're setting the connection's
> source
> and target (which cause it to refresh) before its location. In your
> connection creation command, if you set the connection's location before
> its
> source or target, I think it would solve your problem.
>
> BTW, for the sake of performance, you should add a setLocation() method on
> your anchor class, and then you can have one anchor per EditPart. All the
> get*Anchor() methods should then return this same anchor (with the
> location
> updated, of course).
>
> "Binti Sepaha" <binti@ksu.edu> wrote in message
> news:d368hn$672$1@news.eclipse.org...
>> Hi all,
>>
>> I am writing an editor that draws sequence diagrams. What I want is the
>> connections should be created where the user clicks (atleast the the y
>> coordinate should be that) and I return this location from my own anchor.
> I
>> set the request location in this and return it from there.
>>
>> The code for my anchor is this-
>>
>> public MyAnchor(IFigure source, Point location)
>> {
>> super(source);
>> this.location = location;
>> }
>>
>> public Point getLocation(Point reference)
>> {
>> Rectangle r = getOwner().getBounds().getCopy();
>> getOwner().translateToAbsolute(r);
>> int off = r.width / 2;
>> Point p = null;
>> if(location == null)
>> {
>> p = new Point(r.x + r.width/2, reference.y);
>> }
>> else
>> {
>> p = new Point(r.x + r.width/2, location.y);
>> }
>> return p;
>>
>> }
>>
>> So when I have created the connection, I assume
> getSourceConnectionAnchor()
>> and getTargetConnectionAnchor() have been called and the location is set
>> with the request location, but it still is null here and it returns the
>> refernce point. Therefore, the connection all start and end from on
>> center
>> to another (i.e. reference point's y coordinate).
>>
>> BUT WHEN I CLOSE THE DIAGRAM AND RE OPEN IT, THE CONNECTIONS LOOK FINE.
>>
>> This is the code for my NodeEditPart -
>> public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart
>> connectionEditPart)
>> {
>> MyConnectionPart connectionPart = (MyConnectionPart)connectionEditPart;
>> MyConnection connection= (ActionFlow)connectionPart.getModel();
>> return new MyAnchor(getFigure(), connection.getLocation());
>> }
>>
>> public ConnectionAnchor getSourceConnectionAnchor(Request request)
>> {
>> CreateConnectionRequest req = (CreateConnectionRequest) request;
>> return new MyAnchor(getFigure(), req.getLocation());
>> }
>>
>> And I have saved the request location with the connection Model. These
>> methods are similar for Target as well.
>>
>> Can someone please explain what is going wrong?
>>
>> Thanks in Advance,
>> Binti.
>>
>>
>
>
Previous Topic:expand/collapse the Container EditPart in "flow" example
Next Topic:How to use arrow key to adjust figure's position slightly
Goto Forum:
  


Current Time: Sun Jan 29 20:28:20 GMT 2023

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

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

Back to the top