Lin*_*k19 10 java swt graph eclipse-rcp zest
我一直在玩Zest GraphViewer超过一个星期,现在试图发现它可以为我的应用程序做些什么,但到目前为止我还没有能够满足我的要求.
我希望有人可以指出我需要的资源,因为我无法找到与Google一起使用的所有资源,或者可以告诉我我的想法是否可行.
版
我已经在RCP项目的依赖项中获得了Zest核心1.3.0和Zest布局1.1.0.这来自我从Zest网站上下载的网站.
要求
右键单击功能可以来自单一选择,因为我可以在任何地方使用弹出窗口,但是它基于当前所选节点,但我宁愿不这样做.
由于性质或我们的应用程序和用户,我无法做到这一点,我可能还需要找到另一个具有此功能的基于RCP/SWT的Graph绘图包.
任何这些问题的任何帮助将不胜感激.
格伦x
public static void main(String[] args) throws FontFormatException, IOException
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Graph graph = new Graph(shell, SWT.NONE);
GraphNode node1 = new GraphNode(graph, SWT.NONE, "Jim");
GraphNode node2 = new GraphNode(graph, SWT.NONE, "Jack");
GraphNode node3 = new GraphNode(graph, SWT.NONE, "Joe");
GraphNode node4 = new GraphNode(graph, SWT.NONE, "Bill");
/* Context menu */
graph.addMenuDetectListener(new MenuDetectListener()
{
@Override
public void menuDetected(MenuDetectEvent e)
{
Point point = graph.toControl(e.x, e.y);
IFigure fig = graph.getFigureAt(point.x, point.y);
if (fig != null)
{
Menu menu = new Menu(shell, SWT.POP_UP);
MenuItem exit = new MenuItem(menu, SWT.NONE);
exit.setText("Hello! This is " + ((GraphLabel) fig).getText());
menu.setVisible(true);
}
else
{
Menu menu = new Menu(shell, SWT.POP_UP);
MenuItem exit = new MenuItem(menu, SWT.NONE);
exit.setText("Nothing here...");
menu.setVisible(true);
}
}
});
/* Lets have a directed connection */
new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1, node2);
/* Lets have a dotted graph connection */
new GraphConnection(graph, ZestStyles.CONNECTIONS_DOT, node2, node3);
/* Standard connection */
new GraphConnection(graph, SWT.NONE, node3, node1);
/* Change line color and line width */
GraphConnection graphConnection = new GraphConnection(graph, SWT.NONE, node1, node4);
graphConnection.changeLineColor(shell.getDisplay().getSystemColor(SWT.COLOR_GREEN));
/* Also set a text */
graphConnection.setText("This is a text");
graphConnection.setHighlightColor(shell.getDisplay().getSystemColor(SWT.COLOR_RED));
graphConnection.setLineWidth(3);
graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
graph.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
System.out.println(e.item);
/* Make sure that only the newest item is selected */
graph.setSelection(new GraphItem[]{(GraphItem)e.item});
}
});
shell.pack();
shell.open();
shell.setSize(400, 300);
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Run Code Online (Sandbox Code Playgroud)
它支持单节点/边缘选择,取消选择和右键单击功能.
看起来像这样:
如果您使用本GraphViewer
教程的示例并将其添加到View
代码中,它仍然可以正常工作:
final Graph graph = viewer.getGraphControl();
graph.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
System.out.println(e.item);
graph.setSelection(new GraphItem[]{(GraphItem)e.item});
}
});
Run Code Online (Sandbox Code Playgroud)