Node Creation and Information Retrieval
Application demonstrating the creation of nodes with attributes, and the retrieval and display of that information.
- To Add a node, enter a name and age and click 'Add Node'
- Clicking on a Node displays that nodes information in the box on the lower right corner
- Clicking on save exports a graphML representation of the node structure
Screenshot
Explanation
buttonListener.java
Override the standard actionPerformed
public void actionPerformed(ActionEvent e){
If new button is pressed, get the value of the name and age fields and create a new table row
if ("new".equals(e.getActionCommand())){
int row = table.addRow();
String name = nameLabel.getText();
int age = Integer.parseInt(ageLabel.getText());
table.set(row, "Name", name);
table.set(row, "Age", age);
viz.run("draw");
}
If save button is pressed, open a JFileChooser to allow user to save, then use GraphMLWriter to write out file
if ("save".equals(e.getActionCommand())){
JFileChooser fs = new JFileChooser();
int returnval = fs.showSaveDialog(content);
File save = fs.getSelectedFile();
System.out.println(save);
GraphMLWriter write = new GraphMLWriter();
if (returnval == JFileChooser.APPROVE_OPTION)
try{
write.writeGraph(graph, save);
//tw.writeTable(table, save);
}catch(Exception ex) {
System.out.println("Unable to Save File! : " + ex.toString());
ex.printStackTrace();
}
}
}
GraphBuild
GraphBuild extends visualization, so it's actually a visualization itself. The process of creating the visualization is standard, but the following function is added to the end to allow for the updating of the graph :
public void addName(String newName, int newAge){
row = table.addRow();
table.set(row, "Name", newName);
table.set(row, "Age", newAge);
}
VizControlListener
overrides itemClicked. Retrives the name and age from the visualitem (the clicked node) and displays it in the displayfield.
public void itemClicked(VisualItem v, MouseEvent e){
String thisname = v.getString("Name");
String thisage = v.getString("Age");
displayField.setText(thisname + " is " + thisage);
}