Draw2D, layouts and preferred sizes [message #221803] |
Sun, 20 August 2006 10:37 |
Eclipse User |
|
|
|
Originally posted by: dc.schneid.googlemail.com
Hi,
trying to write a simple Graph editor with Draw2D I came across the
following strange behaviour which is not referred to in the examples or
tutorials I read. Can you help me figure out whats wrong or what I don't
understand?
I have a most simple custom figure (extending Figure) with the following
constructor:
public MyFigure() {
ToolbarLayout layout = new ToolbarLayout();
setLayoutManager(layout);
setBorder(new LineBorder(ColorConstants.black,1));
setBackgroundColor(ColorConstants.white);
setOpaque(true);
Label labelA = new Label("A label");
add(labelA);
Label labelB = new Label("Yet another label");
add(labelB);
}
When I add it to my FreeformLayer I see nothing, unless I add a line in the
constructor setting the size of the figure manually, which is, of course,
not exactly best practise when a layout manager is used.
Moreover, when I call getPreferredSize() in the constructor, a
NullPointerException is thrown.
The only workaround I figured out is to call
figure.setSize(figure.getPreferredSize()) from outside, that is after adding
the figure to the layer. Strangely, however, looking at the tutorials I seem
to be the only person who has to call setSize manually in order to see a
figure.
What is this all about? Is it maybe something about the FreeformLayer?
Please help!
Thanks,
David
|
|
|
Re: Draw2D, layouts and preferred sizes [message #221875 is a reply to message #221803] |
Mon, 21 August 2006 14:41 |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
I've just posted about a possibly connected problem. I look in the shape
example and see this code:
protected void refreshVisuals() {
// notify parent container of changed position & location
// if this line is removed, the XYLayoutManager used by the parent
// container
// (the Figure of the ModelsDiagramEditPart), will not know the bounds
// of this figure
// and will not draw it correctly.
Rectangle bounds = new Rectangle(getCastedModel().getLocation(),
getCastedModel().getDimension().union(getFigure().getPreferr edSize().expand(3,0)));//expand to account for the border
((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
}
vlad
On Sun, 20 Aug 2006 12:37:29 +0200, David
Schneider wrote:
> Hi,
>
> trying to write a simple Graph editor with Draw2D I came across the
> following strange behaviour which is not referred to in the examples or
> tutorials I read. Can you help me figure out whats wrong or what I don't
> understand?
>
> I have a most simple custom figure (extending Figure) with the following
> constructor:
>
> public MyFigure() {
> ToolbarLayout layout = new ToolbarLayout();
> setLayoutManager(layout);
> setBorder(new LineBorder(ColorConstants.black,1));
> setBackgroundColor(ColorConstants.white);
> setOpaque(true);
> Label labelA = new Label("A label");
> add(labelA);
> Label labelB = new Label("Yet another label");
> add(labelB);
> }
>
> When I add it to my FreeformLayer I see nothing, unless I add a line in the
> constructor setting the size of the figure manually, which is, of course,
> not exactly best practise when a layout manager is used.
>
> Moreover, when I call getPreferredSize() in the constructor, a
> NullPointerException is thrown.
>
> The only workaround I figured out is to call
> figure.setSize(figure.getPreferredSize()) from outside, that is after adding
> the figure to the layer. Strangely, however, looking at the tutorials I seem
> to be the only person who has to call setSize manually in order to see a
> figure.
>
> What is this all about? Is it maybe something about the FreeformLayer?
> Please help!
>
> Thanks,
> David
|
|
|
Powered by
FUDForum. Page generated in 0.03592 seconds