Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problem with draw2d layout
Problem with draw2d layout [message #164248] Tue, 18 January 2005 09:12 Go to next message
Eclipse UserFriend
Originally posted by: pengfai81.mail.yahoo.com

hi...all
I intend to create a custom layout which can display the figure based on
the calculation. Can anyone direct me?
I try to println the rect value. The location is generated but i wonder i
can't display the figure.

public void layout(IFigure parent)
{ Rectangle area = parent.getClientArea();
List children = parent.getChildren();
IFigure child;

for (int i=0;i<children.size();i++)
{ child = (IFigure)children.get(i);
Rectangle rect = new Rectangle();

rect.x = (int)(center.getBounds().x + radius*(Math.cos
(i*getAngle())));
rect.y = (int)(center.getBounds().y + radius*(Math.sin
(i*getAngle())));
}
child.setBounds(rect);
}
}

thanks in advance .....
Re: Problem with draw2d layout [message #164279 is a reply to message #164248] Tue, 18 January 2005 11:56 Go to previous messageGo to next message
Steve Jones is currently offline Steve JonesFriend
Messages: 95
Registered: July 2009
Member
Hi,

In the parent figure:

1. use XYLayout, you can set this in the figures constructor:

...
setLayoutManager(new XYLayout());
...

2. In the parent figure implement:

public void validate() {
LayoutManager layout = getLayoutManager();
for each child figure ...
layout.setConstraint(child, new Rectangle(childs_bounds));
}

3. Use -1 as the width and height if you only want to place the
child figure and leave it's size unconstrained.

Hope this helps.

Steve.
Re: Problem with draw2d layout [message #164361 is a reply to message #164248] Tue, 18 January 2005 18:13 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
You create a new Rectangle (height, width == 0), but never set its height or
width. If either one is zero, the figure is not going to appear.

"Jack" <pengfai81@mail.yahoo.com> wrote in message
news:csijte$331$1@www.eclipse.org...
> hi...all
> I intend to create a custom layout which can display the figure based on
> the calculation. Can anyone direct me?
> I try to println the rect value. The location is generated but i wonder i
> can't display the figure.
>
> public void layout(IFigure parent)
> { Rectangle area = parent.getClientArea();
> List children = parent.getChildren();
> IFigure child;
>
> for (int i=0;i<children.size();i++)
> { child = (IFigure)children.get(i);
> Rectangle rect = new Rectangle();
>
> rect.x = (int)(center.getBounds().x + radius*(Math.cos
> (i*getAngle())));
> rect.y = (int)(center.getBounds().y + radius*(Math.sin
> (i*getAngle())));
> }
> child.setBounds(rect);
> }
> }
>
> thanks in advance .....
>
Re: Problem with draw2d layout [message #164542 is a reply to message #164361] Wed, 19 January 2005 07:25 Go to previous message
Eclipse UserFriend
Originally posted by: pengfai81.mail.yahoo.com

node1 node1
| /
| /
| but /
center node3 ----center
/ \ \
/ \ \
/ \ \
node3 node2 node2

figure 1 figure 2

Hi...yes.
I have came up with the custom layout.
But the nodes are displayed like the figure2 diagram.
How i set the node1 location always on par with the central node?
I noticed that the last node alwyas will be the same location regardless
the number of the nodes i added in. Thinks it runs based on anti-clockwise.

public void layout(IFigure parent)
{ Rectangle area = parent.getClientArea();
List children = parent.getChildren();
IFigure child;

for (int i=0;i<children.size();i++)
{ child = (IFigure)children.get(i);
Rectangle rect = new Rectangle();
if (child.equals(center)){continue;}

rect.x = (int)(center.getBounds().x + radius*(Math.cos
(i*getAngle())));
rect.y = (int)(center.getBounds().y + radius*(Math.sin
(i*getAngle())));
}
area.x = rect.x;
area.y = rect.y;
child.setBounds(area);
}
}

Thanks .....
Previous Topic:Installing SnapFeedbackPolicy on an EditPart
Next Topic:paletteviewer
Goto Forum:
  


Current Time: Thu Apr 25 14:07:53 GMT 2024

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

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

Back to the top