1

I have a pretty large ZEST Tree, displaying a Hashtree (Merkletree). Because of its size and limited available space it gets so compressed you can't read it anymore:

my ZEST Graph

Therefore I want to be able to grab more space than the actual shell has, and implement a scrolling/dragging option to move around with the mouse.

However, I can't find a subelement in which I can contain it, which doesn't get filled into the space I have.

I already have tried SashForm (org.eclipse.swt.custom.SashForm), but it couldn't become bigger than the window.

Is there a possibility to implement my plan or is it generally not supported in SWT?

Baz
  • 36,440
  • 11
  • 68
  • 94
  • If you feel an answer solved the problem, please mark it as 'accepted' by clicking the green check mark. This helps keep the focus on older posts which still don't have answers. – Rüdiger Herrmann Dec 19 '16 at 16:56

3 Answers3

0

I know little about Zest, thus you should first look if Zest itself offers zooming and/or scrolling.

If there is no built-in support, you can use SWT's ScrolledComposite. See here for more information:

Community
  • 1
  • 1
Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • Thanks for the awnser, I actually managed to get it to work with a mix of Composite and SashForm and will post the code when it is finished. – tassadarius Dec 23 '16 at 11:56
0

By setting the style of the Graph to SWT.V_SCROLL | SWT.H_SCROLL you can make the graph scrollable:

Graph graph = new Graph(shell, SWT.H_SCROLL | SWT.V_SCROLL);
Baz
  • 36,440
  • 11
  • 68
  • 94
  • This does not really work. Yes the graph becomes scrollable, but it gets space allocated from the GridLayout, which it doesn't extend. So the graph just stays in its bounds and is scrollable, but doesn't actively get more space – tassadarius Dec 23 '16 at 11:57
0

After some time I got it working in a decent way. I use a simple PaintListener with the method setSize. For the Zooming I use the class org.eclipse.gef.editparts.ZoomManager. I found one big disatvantage, this class needs a lot of performance and there are certainly other solutions as well.

I hope the code makes clear why and how.

public class ZoomableZestGraph extends Composite {

private GraphViewer graphViewer;
private Graph graph;

public ZoomableZestGraph(Composite parent, int style) {
    super(parent, style);
    this.setLayout(new GridLayout(1, true));    
    this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,1));


    //create a GraphViewer and Graph
    graphViewer = new GraphViewer(this, SWT.V_SCROLL | SWT.H_SCROLL);
    graph = graphViewer.getGraphControl();
    graph.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
    graph.setHorizontalScrollBarVisibility(Graph.ALWAYS);
    graph.setVerticalScrollBarVisibility(Graph.ALWAYS);


    //Fill our graph with some nodes and connect them
    GraphNode node1 = new GraphNode(graph, SWT.NONE, "Earendil");
    GraphNode node2 = new GraphNode(graph, SWT.NONE, "Elros");
    GraphNode node3 = new GraphNode(graph, SWT.NONE, "Elrond");
    GraphNode node4 = new GraphNode(graph, SWT.NONE, "Elladan");
    GraphNode node5 = new GraphNode(graph, SWT.NONE, "Elrohir");
    GraphNode node6 = new GraphNode(graph, SWT.NONE, "Arwen");


    new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1, node2);
    new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1, node3);
    new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node2, node4);
    new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node2, node5);
    new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node2, node6);

    /*
    This graphViewer consists of 2 components: the control and the graph (Figure)
    We want to give the control a size by the layout and the graph a custom, bigger value.
    For the control (graphViewer.getControl) I simply grab all available space
    */
    GridDataFactory.fillDefaults().grab(true, true).applyTo(graphViewer.getControl());

    //For the graph we have to create a PaintListener.
    graph.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
        graph.setSize(1300, 1080);

        }
    });
    //The Graph now fills the shell/parent composite, 
    //but the actual graph size can be set as we want in the paint //listener

    //Zooming with the class org.eclipse.gef.editparts.ZoomManager
    //As arguments we need a ScalableFigure which we receive by graph.getRootLayer and the Viewport.
    ZoomManager zoomManager = new ZoomManager(graph.getRootLayer(), graph.getViewport());

    //we bind the zoom mechanic to a simple mouse wheel listener
    graph.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseScrolled(MouseEvent e) {
            if (e.count < 0) {
                zoomManager.zoomOut();
            } else {
                zoomManager.zoomIn();
            }
        }
    });
    //We give the focus to our graphViewer, so it receives the MouseWheel Events
    graphViewer.getControl().forceFocus();
    }

   @Override
   protected void checkSubclass() {
     //we are a composite subclass
   }

}

Note: I didn't include the imports