示例#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);
       }
     }
   }
 }
示例#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();
   }
 }