Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Draw2D, layouts and preferred sizes
Draw2D, layouts and preferred sizes [message #221803] Sun, 20 August 2006 10:37 Go to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Is it possible to print TreeView
Next Topic:How to add the align left, align middle and align right actions to the shapeEditor example
Goto Forum:
  


Current Time: Tue Dec 12 15:53:11 GMT 2017

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

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