Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problem sizing the LayeredPane
Problem sizing the LayeredPane [message #227603] Fri, 08 December 2006 07:01 Go to next message
Boris Klug is currently offline 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 17:09 Go to previous messageGo to next message
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 #227771 is a reply to message #227622] Mon, 11 December 2006 04:53 Go to previous messageGo to next message
Boris Klug is currently offline Boris Klug
Messages: 9
Registered: July 2009
Junior Member
You are right: It would be best if the pane is sized automatically - but what is wrong with my code?

I will (again!) try to track it down. If I found it, I will post it here.

If anybody can given any hint - this would be good.
Re: Problem sizing the LayeredPane [message #227941 is a reply to message #227771] Wed, 13 December 2006 03:12 Go to previous messageGo to next message
Boris Klug is currently offline Boris Klug
Messages: 9
Registered: July 2009
Junior Member
What I figured out is that the problem lays in the ConnectionLayer. If I remove this layer and simply add all figures to the figures layer the resizing works fine. But than the connection are draw thru the figures because the conncetion path router cant work...
Re: Problem sizing the LayeredPane [message #227958 is a reply to message #227941] Wed, 13 December 2006 07:44 Go to previous messageGo to next message
Boris Klug is currently offline Boris Klug
Messages: 9
Registered: July 2009
Junior Member
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();
  }
Re: Problem sizing the LayeredPane [message #228129 is a reply to message #227958] Sat, 16 December 2006 16:09 Go to previous messageGo to next message
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();
>  }
> 
Re: Problem sizing the LayeredPane [message #228223 is a reply to message #228129] Mon, 18 December 2006 03:22 Go to previous message
Boris Klug is currently offline Boris Klug
Messages: 9
Registered: July 2009
Junior Member
Thank you a lot. Now I set the position and size of a figure using a constraint and set the size of the connection layer to (0,0) and everything is like I wanted it to be.

Great!
Previous Topic:painting Figure
Next Topic:getCreateCommand called repeatedly
Goto Forum:
  


Current Time: Wed Apr 16 18:47:25 EDT 2014

Powered by FUDForum. Page generated in 0.12980 seconds