我在解析文件并创建具有属性的节点后使用 GraphStream 导入文件。创建节点后我想要的是在 GUI 中编辑它们的属性。就像我在图表的右侧和左侧一样,在文本框中显示我单击的节点的属性。比保存这些属性。
我的代码:
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
LayersGraph lg=new LayersGraph();
Viewer viewer=new Viewer ( lg.graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
viewer.enableAutoLayout();
ViewerPipe fromViewer=viewer.newViewerPipe();
lg.createGraph();
View view=viewer.addDefaultView(false);
clisten=new NodeClickListener(fromViewer,view,lg.graph);
fromViewer.addViewerListener((ViewerListener) clisten);
frame.getContentPane().add((Component) view);
JTextArea textArea = new JTextArea();
frame.getContentPane().add(textArea, BorderLayout.WEST);
textArea.setText("The graph has etc....");
NodeClickListener:
公共类 NodeClickListener 实现 ViewerListener , MouseInputListener{
public boolean loop = true;
private ViewerPipe vpipe = null;
private View vw = null;
private Graph graph = null;
public HashMap<String,String> attributes=new HashMap<String,String>();
/**
* Constructor
* @param vpipe - Viewer Pipe of the graph UI
* @param vw - View of the current graph in swing
* @param g - graph object for the current graph in use
*/
public NodeClickListener(ViewerPipe vpipe, View vw, Graph g) {
this.loop=true;
this.vpipe = vpipe;
this.vw = vw;
this.graph = g;
// Keep piping back while grph is out to hook mouse clicks
this.vw.addMouseListener(this);
}
/**
* Close the view when graph is no longer needed and detach all listners
* @param id - not used, but inherited by interface
*/
public void viewClosed(String id) {
loop = false;
vw.removeMouseListener(this);
}
/**
* Button push hook to label nodes/edges
* @param id - string id of node
*/
public void buttonPushed(String id) {
System.out.println("Button pushed on node "+id);
Node n = graph.getNode(id);
//String _ui_label = n.getAttribute("_ui.label");
String ui_label = n.getAttribute("ui.label");
System.out.println("ui_label: "+ui_label);
for(String key:n.getEachAttributeKey()){
Object value=n.getAttribute(key);
System.out.println("Key: "+key+" Value: "+value.toString());
attributes.put(key, value.toString());
}
}
我想将属性发送到表单并在表单中为单击的每个节点创建动态标签和文本框,以便能够编辑属性。任何人都知道我该怎么做?也可能是线程之间同步的问题?
谢谢