1

我有一个非常大的 ZEST 树,显示一个哈希树(Merkletree)。由于它的大小和有限的可用空间,它变得如此压缩,您无法再阅读它:

我的热情图

因此,我希望能够获得比实际外壳更多的空间,并实现滚动/拖动选项以使用鼠标四处移动。

但是,我找不到可以包含它的子元素,它不会填充到我拥有的空间中。

我已经尝试过SashForm(org.eclipse.swt.custom.SashForm),但它不能变得比窗口大。

是否有可能实施我的计划,或者 SWT 通常不支持它?

4

3 回答 3

0

Graph通过设置to的样式,SWT.V_SCROLL | SWT.H_SCROLL您可以使图形可滚动:

Graph graph = new Graph(shell, SWT.H_SCROLL | SWT.V_SCROLL);
于 2016-12-16T18:39:31.597 回答
0

一段时间后,我让它以一种体面的方式工作。我使用一个简单的 PaintListener 和 setSize 方法。对于缩放,我使用类 org.eclipse.gef.editparts.ZoomManager。我发现了一个很大的缺点,这个类需要很多性能,当然还有其他解决方案。

我希望代码清楚地说明原因和方式。

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
   }

}

注意:我没有包括进口

于 2017-03-19T17:18:18.230 回答
0

我对 Zest 知之甚少,因此您应该首先查看 Zest 本身是否提供缩放和/或滚动功能。

如果没有内置支持,您可以使用 SWT 的ScrolledComposite. 浏览此处获取更多信息:

于 2016-12-16T15:35:21.307 回答