/**
  * Called when the selection changed in the tree. Loads the selected certificate.
  *
  * @param e the event
  */
 private void valueChangedPerformed(TreeSelectionEvent e) {
   Object o = e.getNewLeadSelectionPath().getLastPathComponent();
   if (o instanceof DefaultMutableTreeNode) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
     infoTextPane.setText(toString(node.getUserObject()));
   }
 }
 static boolean isButtonEnabled(boolean rec, TreePath[] paths, TreeSelectionEvent e) {
   if (paths != null) {
     for (TreePath path : paths) {
       if (!e.isAddedPath(path)) continue;
       final PackageDependenciesNode node = (PackageDependenciesNode) path.getLastPathComponent();
       if (PatternDialectProvider.getInstance(DependencyUISettings.getInstance().SCOPE_TYPE)
               .createPackageSet(node, rec)
           != null) {
         return true;
       }
     }
   }
   return false;
 }
 /**
  * Called whenever the value of the selection changes.
  *
  * @param e the event that characterizes the change.
  */
 public void valueChanged(TreeSelectionEvent e) {
   TreePath path = e.getPath();
   if (path != null) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
     if (node.isLeaf()) {
       if (getInformation(path) != null) {
         // When selecting an image information.
         XmlInformation info = getInformation(path);
         for (int i = 0; i < listener_list.size(); i++) {
           InformationTreeSelectionListener listener =
               (InformationTreeSelectionListener) listener_list.elementAt(i);
           listener.select(info);
         }
       } else {
         // When expanding a folder.
         expandNode(node);
       }
     }
   }
 }
    public void valueChanged(TreeSelectionEvent event) {
      // DefaultMutableTreeNode node = new DefaultMutableTreeNode();
      DefaultMutableTreeNode node;
      TreePath paths[] = event.getPaths();

      // Statistical variables
      Object bestNode;
      Object worstNode;
      double avgFitness = 0;
      double bestFitness = -1;
      double worstFitness = -1;

      // Update Selection Panel to reflect current selections
      for (int i = 0; i < paths.length; i++) {
        // If a parent node is selected, select all children nodes
        DefaultMutableTreeNode tmpNode = (DefaultMutableTreeNode) paths[i].getLastPathComponent();

        // If Root is selected, clear all selections
        if (tmpNode.isRoot()) {
          tree.clearSelection();
          selectedChildrenPaths.removeAllElements();
          break;
        }

        if (tmpNode.getAllowsChildren()) {
          ArrayList tmpNodeChildren = new ArrayList();

          for (Enumeration e = tmpNode.children(); e.hasMoreElements(); ) {
            DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement();
            TreePath treePath = new TreePath(childNode.getPath());

            if (event.isAddedPath(paths[i])) {
              if (!selectedChildrenPaths.contains(treePath))
                selectedChildrenPaths.addElement(treePath);
            } else selectedChildrenPaths.removeElement(treePath);
          }

          // TreePath [] treePaths = new TreePath[tmpNodeChildren.size()];

          // if ( event.isAddedPath(paths[i]) )
          //    tree.addSelectionPaths( (TreePath []) tmpNodeChildren.toArray(treePaths) );
          // else
          //    tree.removeSelectionPaths( (TreePath[]) tmpNodeChildren.toArray(treePaths) );

          // Collapse parent view -- commented for future use, DO NOT IMPLEMENT AS SHOWN
          // tree.collapsePath( paths[i] );
        } else // only a single node is being examined
        {
          if (event.isAddedPath(paths[i])) {
            if (!selectedChildrenPaths.contains(paths[i]))
              selectedChildrenPaths.addElement(paths[i]);
          } else selectedChildrenPaths.removeElement(paths[i]);
        }
      }

      // If selections exist, enabled "Save Selected" menu item
      if (selectedChildrenPaths.size() > 0) miSave.setEnabled(true);
      else miSave.setEnabled(false);

      // Calculate selection information statistics
      for (int j = 0; j < selectedChildrenPaths.size(); j++) {
        double fitness = 0;

        node =
            (DefaultMutableTreeNode)
                ((TreePath) selectedChildrenPaths.elementAt(j)).getLastPathComponent();

        fitness = gaMonitor.getFitness(node.getUserObject());

        avgFitness += fitness;

        if (fitness > bestFitness || bestFitness == -1) {
          bestFitness = fitness;
          bestNode = node;
        }

        if (fitness < worstFitness || worstFitness == -1) {
          worstFitness = fitness;
          worstNode = node;
        }
      }

      // Finialize Statistics
      if (bestFitness != -1) avgFitness = avgFitness / (double) selectedChildrenPaths.size();

      // Panel may not exist!  If null, ignore
      if (selectionStatsPanel != null) {
        if (bestFitness != -1)
          selectionStatsPanel.setSelectionStats(
              selectedChildrenPaths.size(), avgFitness, bestFitness, worstFitness);
        else selectionStatsPanel.setEmptySelection();
      }
    }