Example #1
0
 private void update() {
   Collection<V> selected = new Vector<V>(this.graph.getPickedVertexState().getPicked());
   // if nothing is selected, this Collection should also contain nothing.
   if (selected.size() == 0) {
     this.clear();
     return;
   }
   // Basically here we add all neighbors of the first selected node, then
   // remove any nodes which are not neighbors of each selected node until
   // we have gone through the entire selection.
   Collection<V> neighbors;
   boolean firstPass = true;
   for (V v : selected) {
     if (firstPass) {
       if (!this.contains(v)) {
         this.addAll(graph.getNeighbors(v));
       }
       firstPass = false;
     }
     this.remove(v);
     neighbors = graph.getNeighbors(v);
     for (V u : new Vector<V>(this)) {
       if (!neighbors.contains(u)) {
         this.remove(u);
       }
     }
   }
 }
Example #2
0
 public void stateChanged(PickedStateChangeEvent<V> event) {
   // check to see if a vertex was added to or taken away from the selection.
   // if one was added, we can improve performance by simply removing nodes
   // from the NeighborCollection which are not neighbors of the new node.
   if (event.getStateChange()) {
     if (graph.getPickedVertexState().getPicked().size() == 1) {
       Collection newNeighbors = graph.getNeighbors(event.getItem());
       if (newNeighbors != null) this.addAll(newNeighbors);
     } else {
       for (V v : new Vector<V>(this)) {
         this.remove(event.getItem());
         try {
           if (!graph.isNeighbor(event.getItem(), v)) this.remove(v);
         } catch (IllegalArgumentException e) {
         }
       }
     }
   } else {
     this.update();
   }
 }
Example #3
0
 /**
  * Sets a new Layout for the graph.
  *
  * @param layout A Class object containing the Layout to be used.
  */
 public void setGraphLayout(Class<? extends AbstractLayout> layout) {
   this.setGraphLayout((Layout<V, E>) GraphVisualizer.getLayoutInstance(layout, this.graph));
 }
Example #4
0
 /**
  * Creates a new layout instance from a Class Object.
  *
  * @param layout The Class object to create the instance of.
  * @return A new instance of the Layout.
  */
 protected static Layout getLayoutInstance(Class<? extends AbstractLayout> layout) {
   return GraphVisualizer.getLayoutInstance(layout, new UndirectedSparseGraph());
 }
Example #5
0
 /**
  * Constructs a GraphVisualizer Object.
  *
  * @param layout A Class object of the type of class to use for the graph layout.
  * @param size The initial size of the GraphVisualizer Object.
  */
 public GraphVisualizer(Class<? extends AbstractLayout> layout, Dimension size) {
   super(GraphVisualizer.getLayoutInstance(layout), size);
   this.setup();
 }
Example #6
0
 public NeighborCollection(GraphVisualizer graph) {
   this.graph = graph;
   graph.addPickedVertexStateChangeListener(this);
   graph.addEdgeChangeListener(this);
 }