Problem sizing the LayeredPane [message #227603] |
Fri, 08 December 2006 12:01 |
Boris Klug Messages: 9 Registered: July 2009 |
Junior Member |
|
|
Hi!
I try to display a kind of E/R-diagram in a LayeredPane. I have two layers, one for the connections and one for the nodes.
I use a XYLayout and set the position and the size of all nodes. I open the window using the fixed size of 400,300.
The problem is, that the scrollbars behave totally wired: When the diagram is small, I can scroll so that the diagram is no longer visible. When the diagram is big, I cant see the whole diagram even when I scroll.
I thought that the size of the canvas depends on the nodes and connections I insered and that the scrollbars are automatically hidden/shown.
If the size of the pane is not calculated automatically, how can I set the size manually? A pane.setSize() does not help.
See my code below
Display d = new Display();
Shell shell = new Shell(d);
canvas = new FigureCanvas(shell);
canvas.setBackground(ColorConstants.white);
canvas.setLayout(new FillLayout());
LayeredPane rootPane = new LayeredPane();
canvas.setContents(rootPane);
Layer figures = new Layer();
XYLayout draw2DLayout = new XYLayout();
figures.setLayoutManager(draw2DLayout);
figures.setOpaque(false);
rootPane.add(figures, LayerConstants.PRIMARY_LAYER);
ConnectionLayer connections = new ConnectionLayer();
ConnectionRouter router = new ShortestPathConnectionRouter(figures);
connections.setConnectionRouter(router);
rootPane.add(connections, LayerConstants.CONNECTION_LAYER);
(add all the nodes and connections here)
shell.setSize(400, 300);
shell.open();
// Events bearbeiten
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();
|
|
|
Re: Problem sizing the LayeredPane [message #227622 is a reply to message #227603] |
Fri, 08 December 2006 22:09 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
Are you setting the constraint on the layout manager?
You don't want to go the route of sizing the pane yourself. It works
properly. Track down what it is that you're doing wrong instead.
"Boris Klug" <boris.klug@debeka.de> wrote in message
news:19259109.1165579322545.JavaMail.root@cp1.javalobby.org...
> Hi!
>
> I try to display a kind of E/R-diagram in a LayeredPane. I have two
> layers, one for the connections and one for the nodes.
>
> I use a XYLayout and set the position and the size of all nodes. I open
> the window using the fixed size of 400,300.
>
> The problem is, that the scrollbars behave totally wired: When the diagram
> is small, I can scroll so that the diagram is no longer visible. When the
> diagram is big, I cant see the whole diagram even when I scroll.
>
> I thought that the size of the canvas depends on the nodes and connections
> I insered and that the scrollbars are automatically hidden/shown.
> If the size of the pane is not calculated automatically, how can I set the
> size manually? A pane.setSize() does not help.
>
> See my code below
>
>
> Display d = new Display();
> Shell shell = new Shell(d);
> canvas = new FigureCanvas(shell);
> canvas.setBackground(ColorConstants.white);
> canvas.setLayout(new FillLayout());
> LayeredPane rootPane = new LayeredPane();
> canvas.setContents(rootPane);
>
> Layer figures = new Layer();
> XYLayout draw2DLayout = new XYLayout();
> figures.setLayoutManager(draw2DLayout);
> figures.setOpaque(false);
> rootPane.add(figures, LayerConstants.PRIMARY_LAYER);
>
> ConnectionLayer connections = new ConnectionLayer();
> ConnectionRouter router = new ShortestPathConnectionRouter(figures);
> connections.setConnectionRouter(router);
> rootPane.add(connections, LayerConstants.CONNECTION_LAYER);
>
> (add all the nodes and connections here)
>
> shell.setSize(400, 300);
> shell.open();
>
> // Events bearbeiten
> while (!shell.isDisposed())
> while (!d.readAndDispatch())
> d.sleep();
>
|
|
|
|
|
|
Re: Problem sizing the LayeredPane [message #228129 is a reply to message #227958] |
Sat, 16 December 2006 21:09 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
ConnectionLayer is a freeform figure, whose layout mechanism works
differently from regular figures. What you see is not totally random
behaviour, just that once ConnectionLayer has been sized to be a certain
size, it will always return that as its preferred size.
If you want freeform support (being able to see figures in negative
coordinates), switch to a freeform mode. Set the canvas' viewport to be a
FreeformViewport and switch to a freeform layer with a freeform layout as
your primary layer.
If not, then you can just set a preferred size on the connection layer. 0,0
will work fine. But that would mean that the connection layer would always
be sized by the primary layer (it will be made as big as the primary layer),
not by the connections it contains. This works fine so long as your
connections cannot go beyond the union of the bounds of your nodes.
As a side note, you should use constraints to place your figures. Something
like:
Label s1 = new Label("L1");
figures.add(s1, new Rectangle(100, 100, 100, 40));
"Boris Klug" <boris.klug@debeka.de> wrote in message
news:20051960.1166013902578.JavaMail.root@cp1.javalobby.org...
> Here a minimal code snippet which shows the problem.
> Note that there are no connections in the connection layer.
>
> If you remove the (empty!) conncetion layer, the problem is gone.
>
>
>
> public static void main(String args[]) {
> Display d = new Display();
> Shell shell = new Shell(d);
> shell.setSize(300, 200);
> shell.setLayout(new FillLayout());
>
> FigureCanvas canvas = new FigureCanvas(shell);
> canvas.setBackground(d.getSystemColor(SWT.COLOR_WHITE));
>
> IFigure root = new LayeredPane();
> Layer figures = new Layer();
> figures.setLayoutManager(new XYLayout());
> figures.setOpaque(false);
> root.add(figures);
>
> ConnectionLayer connections = new ConnectionLayer();
> connections.setConnectionRouter(new
> ShortestPathConnectionRouter(figures));
> root.add(connections);
>
> Label s1 = new Label("L1");
> s1.setLocation(new Point(10,10));
> s1.setSize(100, 40);
> figures.add(s1);
>
> canvas.setContents(root);
> shell.open();
> while (!shell.isDisposed())
> while (!d.readAndDispatch())
> d.sleep();
> }
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.05291 seconds