Home » Eclipse Projects » GEF » What layout should I use ?
What layout should I use ? [message #98725] |
Sat, 11 October 2003 15:39  |
Eclipse User |
|
|
|
Originally posted by: brianv.phreaker.net
When I was new to GEF (okay, newer than I am now), I had solved this problem
using a pretty badly hacked FlowLayout and now it's getting back at me. I'm
now rewriting it; but I'm having problems here.
I have containers A and B and C.
A has an XYLayout
B and C have ToolbarLayouts
Now B can only exist within A. And C can only exist within B or within
another C.
I expect the following of B and C:
B and C have children in rows only - one below the other and centered about
the vertical axis.
Both B and C start out with a given Minimum size. That means they are at
least a given size and they can only grow larger.
I don't want the children of B or C to be shrunk.If I'm adding a child to
B.. (adding a new row) and B is not large enough; then B should expand to so
that the new child can be accomodated.
My first question is: Should I be using the ToolbarLayout for B and C ? I
think it fulfills my requirements; but I'm not sure because I faced the
following problems.
Even though I was setting the minimum size for both B and C; it seemed to be
getting ignored. The figures were much smaller than the minimumSize that I
had specified.
If I set the preferredSize for the figures; then they would start off at the
right size, but they would not grow when I added more children.
I suspect the problem is with my refreshVisuals method.
Since B is in A, which has an XYLayout; I have the following code in
refreshVisuals for B's editpart.
protected void refreshVisuals() {
Point loc = getModel().getLocation();
Dimension size= new Dimension(-1,-1);
Rectangle r = new Rectangle(loc ,size);
((GraphicalEditPart) getParent()).setLayoutConstraint(
this,
getFigure(),
r);
}
I'm not sure about whether setting the size to (-1,-1) when B has a
ToolbarLayout and A has a XYLayout will cause some preferredSizes to be
used. In any case, I don't intend to set the preferredSize because then the
Containers don't grow larger than the preferredSize. What should I be
setting the size to ?
The refresh Visuals for C does nothing.. it looks like this. I assume the
ToolbarLayout is supposed to set the postion and the bounds.
protected void refreshVisuals() {
}
The crux of the problem is, my figures aren't starting out at the right
sizes. If I don't set the preferredSize, then the figures initially appear
really small (20, 20) I think; but they expand correctly when objects are
added to them.
Where am I going wrong ?
Thanks in advance,
Brian.
|
|
|
Re: What layout should I use ? [message #99024 is a reply to message #98725] |
Sun, 12 October 2003 22:11   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
Try writing a standalone draw2d snippet showing how you are composing
figures and layout managers. It sounds like you are doing a class diagram.
Have you seen the draw2d article by Daniel Lee on how to create a UML class
figure from the different pieces in draw2d? See the websites
"Brian Fernandes" <brianv@phreaker.net> wrote in message
news:bm9kro$d1p$1@eclipse.org...
> When I was new to GEF (okay, newer than I am now), I had solved this
problem
> using a pretty badly hacked FlowLayout and now it's getting back at me.
I'm
> now rewriting it; but I'm having problems here.
>
> I have containers A and B and C.
> A has an XYLayout
> B and C have ToolbarLayouts
>
> Now B can only exist within A. And C can only exist within B or within
> another C.
>
> I expect the following of B and C:
>
> B and C have children in rows only - one below the other and centered
about
> the vertical axis.
>
> Both B and C start out with a given Minimum size. That means they are at
> least a given size and they can only grow larger.
>
> I don't want the children of B or C to be shrunk.If I'm adding a child to
> B.. (adding a new row) and B is not large enough; then B should expand to
so
> that the new child can be accomodated.
>
> My first question is: Should I be using the ToolbarLayout for B and C ? I
> think it fulfills my requirements; but I'm not sure because I faced the
> following problems.
>
>
> Even though I was setting the minimum size for both B and C; it seemed to
be
> getting ignored. The figures were much smaller than the minimumSize that I
> had specified.
>
> If I set the preferredSize for the figures; then they would start off at
the
> right size, but they would not grow when I added more children.
>
> I suspect the problem is with my refreshVisuals method.
> Since B is in A, which has an XYLayout; I have the following code in
> refreshVisuals for B's editpart.
>
> protected void refreshVisuals() {
> Point loc = getModel().getLocation();
> Dimension size= new Dimension(-1,-1);
> Rectangle r = new Rectangle(loc ,size);
>
> ((GraphicalEditPart) getParent()).setLayoutConstraint(
> this,
> getFigure(),
> r);
> }
>
> I'm not sure about whether setting the size to (-1,-1) when B has a
> ToolbarLayout and A has a XYLayout will cause some preferredSizes to be
> used. In any case, I don't intend to set the preferredSize because then
the
> Containers don't grow larger than the preferredSize. What should I be
> setting the size to ?
>
>
> The refresh Visuals for C does nothing.. it looks like this. I assume the
> ToolbarLayout is supposed to set the postion and the bounds.
>
> protected void refreshVisuals() {
>
> }
>
>
> The crux of the problem is, my figures aren't starting out at the right
> sizes. If I don't set the preferredSize, then the figures initially appear
> really small (20, 20) I think; but they expand correctly when objects are
> added to them.
>
> Where am I going wrong ?
>
> Thanks in advance,
> Brian.
>
>
|
|
| |
Re: What layout should I use ? [message #99309 is a reply to message #99294] |
Mon, 13 October 2003 09:51   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
You may be having problems if the preferred size is smaller than the minimum
size. I'm not sure if the layouts expect this to happen.
BTW, you can use borders to ensure a certain preferred size. It's not
really intended as a way to extend the layout's preferred size, but it might
work in this case. Try using a border on that figure which implements a
preferred size of 250x100. Then, do NOT set minimum, preferred, or any
other sizes on the figures or layouts. And, continue using -1, -1 as the
width/height with XY layout.
"Brian Fernandes" <brian.fernandes@codito.com> wrote in message
news:bme8l9$stq$1@eclipse.org...
> Hi Randy,
>
> I had a look at the article again, but unfortunately I couldn't spot any
> problems with what I'm doing.
>
> What I'm doing is similar to a Class Diagram; but with the following
> difference.
>
> From the article ...
> Imagine the class diagram with only the Label and no Compartment Figure
> children. The UMLClassFigure would just be large enough to hold the label
+
> borders (say 100x20 pixels) - this would be managed by the ToolbarLayout.
I
> can reproduce in my Editor. Okay.
>
> Additionally what I need is; even though there is only a Label in the
> UMLClassFigure (which could be accomodated in 100x20), I would like the
> UMLClassFigure to start at a size of say 250x100. Now if by adding
> CompartementFigure children, the space requirement goes above 250x100,
then
> the UMLClassFigure will expand.
>
> Is there any provision for this in the ToolbarLayout ? The children should
> start a given fixed size .. if the parent is not large enough to
accomodate
> the minium size of the children , then it expands. And of course.. all
> elements in the layout could expand possibly infinitely as required. It
> seems pretty obvious that the minimumSize of a figure should ensure this;
> but it does not seem to be working.
>
> Thanks,
> Brian.
>
>
>
|
|
|
Re: What layout should I use ? [message #99385 is a reply to message #99309] |
Mon, 13 October 2003 10:49  |
Eclipse User |
|
|
|
Originally posted by: brian.fernandes.codito.com
"Randy Hudson" <none@us.ibm.com> wrote in message
news:bmeakp$v3h$1@eclipse.org...
> You may be having problems if the preferred size is smaller than the
minimum
> size. I'm not sure if the layouts expect this to happen.
>
I have not set the preferred size at all on any of the containers; because
though this does give the desired initial effect, when the children require
more space the containers simply refuse to expand.
> BTW, you can use borders to ensure a certain preferred size.
hmm. yeah.. I think the Border sizes are being included within the
getPreferredSize or calculatePreferredSize calculations as a result of this,
preferred size is getting set and hence it is NOT null and definitely
smaller than the MinimumSize.
> It's not
> really intended as a way to extend the layout's preferred size, but it
might
> work in this case. Try using a border on that figure which implements a
> preferred size of 250x100. Then, do NOT set minimum, preferred, or any
> other sizes on the figures or layouts. And, continue using -1, -1 as the
> width/height with XY layout.
>
I did think of doing this, but that would mean I will have figures with
huge borders all the time. When I add a child to the figure... the space
would be there; but because of the borders, the figure would grow even
larger.
I have got a temporary workaround, I think. I've overridden
ToolbarLayout#calculatePreferredSize
protected Dimension calculatePreferredSize(IFigure container, int wHint, int
hHint) {
Dimension pSize = super.calculatePreferredSize(container, wHint, hHint);
Dimension mSize = container.getMinimumSize();
if(mSize.height > pSize.height) pSize.height = mSize.height;
if(mSize.width > pSize.width) pSize.width = mSize.width;
return pSize;
}
This seems to work just right, but now the alignment seems to be a bit
screwed. It's a vertical Toolbar layout, and I want CENTER alignment.
The children seem to center themselves about the vertical axis, but they are
not centered about the other axis.. they are not in the middle of the
figure.
What do you suggest ?
Thanks again,
Brian.
> "Brian Fernandes" <brian.fernandes@codito.com> wrote in message
> news:bme8l9$stq$1@eclipse.org...
> > Hi Randy,
> >
> > I had a look at the article again, but unfortunately I couldn't spot
any
> > problems with what I'm doing.
> >
> > What I'm doing is similar to a Class Diagram; but with the following
> > difference.
> >
> > From the article ...
> > Imagine the class diagram with only the Label and no Compartment Figure
> > children. The UMLClassFigure would just be large enough to hold the
label
> +
> > borders (say 100x20 pixels) - this would be managed by the
ToolbarLayout.
> I
> > can reproduce in my Editor. Okay.
> >
> > Additionally what I need is; even though there is only a Label in the
> > UMLClassFigure (which could be accomodated in 100x20), I would like the
> > UMLClassFigure to start at a size of say 250x100. Now if by adding
> > CompartementFigure children, the space requirement goes above 250x100,
> then
> > the UMLClassFigure will expand.
> >
> > Is there any provision for this in the ToolbarLayout ? The children
should
> > start a given fixed size .. if the parent is not large enough to
> accomodate
> > the minium size of the children , then it expands. And of course.. all
> > elements in the layout could expand possibly infinitely as required. It
> > seems pretty obvious that the minimumSize of a figure should ensure
this;
> > but it does not seem to be working.
> >
> > Thanks,
> > Brian.
> >
> >
> >
>
>
|
|
|
Goto Forum:
Current Time: Sat May 10 15:52:39 EDT 2025
Powered by FUDForum. Page generated in 0.03292 seconds
|