예제 #1
0
 @Override
 public void actionPerformed(ActionEvent evt) {
   TreePath path = resultTree.getSelectionPath();
   DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();
   for (Enumeration e = operNode.children(); e.hasMoreElements(); ) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
     resultTree.collapsePath(new TreePath(node.getPath()));
   }
   resultTree.scrollPathToVisible(new TreePath(operNode.getPath()));
 }
예제 #2
0
  /**
   * Update the layouts tree.
   *
   * @param current The name of the current layout or <CODE>null</CODE> if none.
   */
  public void updateLayouts(Path current) throws PipelineException {
    DefaultMutableTreeNode root = null;
    {
      root = new DefaultMutableTreeNode(new TreeData(), true);

      {
        Path path = new Path(PackageInfo.getSettingsPath(), "layouts");
        rebuildTreeModel(path, new Path("/"), root);
      }

      DefaultTreeModel model = (DefaultTreeModel) pTree.getModel();
      model.setRoot(root);

      {
        Enumeration e = root.depthFirstEnumeration();
        if (e != null) {
          while (e.hasMoreElements()) {
            DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) e.nextElement();
            pTree.expandPath(new TreePath(tnode.getPath()));
          }
        }
      }
    }

    pTree.clearSelection();
    if (current != null) {
      TreePath tpath = null;
      DefaultMutableTreeNode tnode = root;
      for (String comp : current.getComponents()) {
        DefaultMutableTreeNode next = null;
        Enumeration e = tnode.children();
        if (e != null) {
          while (e.hasMoreElements()) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
            TreeData data = (TreeData) child.getUserObject();
            if (data.toString().equals(comp)) {
              tpath = new TreePath(child.getPath());
              next = child;
              break;
            }
          }
        }

        if (next == null) break;

        tnode = next;
      }

      if (tpath != null) {
        pTree.setSelectionPath(tpath);
        pTree.makeVisible(tpath);
      }
    }
  }
예제 #3
0
    @Override
    public void actionPerformed(ActionEvent evt) {
      JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) evt.getSource();
      boolean curState = menuItem.isSelected();

      TreePath path = resultTree.getSelectionPath();
      DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent();

      HyperSearchOperationNode operNodeObj = (HyperSearchOperationNode) operNode.getUserObject();
      if (curState) operNodeObj.cacheResultNodes(operNode);
      operNode.removeAllChildren();
      if (curState) {
        Exception excp = null;
        try {
          operNodeObj.insertTreeNodes(resultTree, operNode);
        } catch (Exception ex) {
          operNodeObj.restoreFlatNodes(resultTree, operNode);
          menuItem.setSelected(false);
          excp = ex;
        } finally {
          ((DefaultTreeModel) resultTree.getModel()).nodeStructureChanged(operNode);
          expandAllNodes(operNode);
          resultTree.scrollPathToVisible(new TreePath(operNode.getPath()));
        }
        if (excp != null) throw new RuntimeException(excp);
      } else operNodeObj.restoreFlatNodes(resultTree, operNode);

      operNodeObj.setTreeViewDisplayed(menuItem.isSelected());
    }
예제 #4
0
파일: TreeView.java 프로젝트: jexp/idea2
 private void collapseTargets() {
   DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot();
   for (int i = 0; i < root.getChildCount(); i++) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
     myTree.collapsePath(new TreePath(node.getPath()));
   }
 }
 @Override
 public void keyPressed(KeyEvent e) {
   TreePath path = myTree.getLeadSelectionPath();
   if (path == null) return;
   final Object lastComponent = path.getLastPathComponent();
   if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (lastComponent instanceof ParentNode) return;
     doOKAction();
     e.consume();
   } else if (e.getKeyCode() == KeyEvent.VK_INSERT) {
     if (lastComponent instanceof ElementNode) {
       final DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;
       if (!mySelectedNodes.contains(node)) {
         if (node.getNextNode() != null) {
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
         }
       } else {
         if (node.getNextNode() != null) {
           myTree.removeSelectionPath(new TreePath(node.getPath()));
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
           myTree.repaint();
         }
       }
       e.consume();
     }
   }
 }
 public void addSelectionPathTo(final Object element) {
   DefaultMutableTreeNode node = myAbstractTreeBuilder.getNodeForElement(element);
   if (node != null) {
     final JTree tree = getTree();
     final TreePath path = new TreePath(node.getPath());
     if (node == tree.getModel().getRoot() && !tree.isExpanded(path)) tree.expandPath(path);
     tree.addSelectionPath(path);
   }
 }
  @Nullable
  private static TreePath findNodePath(MavenArchetype object, TreeModel model, Object parent) {
    for (int i = 0; i < model.getChildCount(parent); i++) {
      DefaultMutableTreeNode each = (DefaultMutableTreeNode) model.getChild(parent, i);
      if (each.getUserObject().equals(object)) return new TreePath(each.getPath());

      TreePath result = findNodePath(object, model, each);
      if (result != null) return result;
    }
    return null;
  }
예제 #8
0
파일: TreeUtil.java 프로젝트: jexp/idea2
  public static ActionCallback selectInTree(
      DefaultMutableTreeNode node, boolean requestFocus, JTree tree, boolean center) {
    if (node == null) return new ActionCallback.Done();

    final TreePath treePath = new TreePath(node.getPath());
    tree.expandPath(treePath);
    if (requestFocus) {
      tree.requestFocus();
    }
    return selectPath(tree, treePath, center);
  }
예제 #9
0
파일: TreeUtil.java 프로젝트: jexp/idea2
 public static void unselect(JTree tree, final DefaultMutableTreeNode node) {
   final TreePath rootPath = new TreePath(node.getPath());
   final TreePath[] selectionPaths = tree.getSelectionPaths();
   if (selectionPaths != null) {
     for (TreePath selectionPath : selectionPaths) {
       if (selectionPath.getPathCount() > rootPath.getPathCount()
           && rootPath.isDescendant(selectionPath)) {
         tree.removeSelectionPath(selectionPath);
       }
     }
   }
 }
예제 #10
0
 private void _storePaths(DefaultMutableTreeNode root) {
   ArrayList<TreeNode> childNodes = childrenToArray(root);
   for (final Object childNode1 : childNodes) {
     DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) childNode1;
     TreePath path = new TreePath(childNode.getPath());
     if (myTree.isPathSelected(path)) {
       addPathToList(childNode, mySelectionPaths);
     }
     if ((myTree.isExpanded(path) || childNode.getChildCount() == 0) && !childNode.isLeaf()) {
       addPathToList(childNode, myPathsToExpand);
       _storePaths(childNode);
     }
   }
 }
 public void restore() {
   final UsageNode node = myUsageNodes.get(myUsage);
   if (node == NULL_NODE || node == null) {
     return;
   }
   final DefaultMutableTreeNode parentGroupingNode = (DefaultMutableTreeNode) node.getParent();
   if (parentGroupingNode != null) {
     final TreePath treePath = new TreePath(parentGroupingNode.getPath());
     myTree.expandPath(treePath);
     if (mySelected) {
       myTree.addSelectionPath(treePath.pathByAddingChild(node));
     }
   }
 }
예제 #12
0
    public void storePaths() {
      myPathsToExpand = new ArrayList<String>();
      mySelectionPaths = new ArrayList<String>();

      DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot();

      TreePath path = new TreePath(root.getPath());
      if (myTree.isPathSelected(path)) {
        addPathToList(root, mySelectionPaths);
      }
      if (myTree.isExpanded(path) || root.getChildCount() == 0) {
        addPathToList(root, myPathsToExpand);
        _storePaths(root);
      }
    }
 private void restoreUsageExpandState(final Collection<UsageState> states) {
   // always expand the last level group
   final DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot();
   for (int i = root.getChildCount() - 1; i >= 0; i--) {
     final DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i);
     if (child instanceof GroupNode) {
       final TreePath treePath = new TreePath(child.getPath());
       myTree.expandPath(treePath);
     }
   }
   myTree.getSelectionModel().clearSelection();
   for (final UsageState usageState : states) {
     usageState.restore();
   }
 }
예제 #14
0
  /**
   * Expands the sub folders and image informations under the specified node.
   *
   * @param node the node.
   */
  protected void expandNode(DefaultMutableTreeNode node) {
    try {
      Object[] paths = node.getPath();

      String path_str = "";
      Vector folder_list = new Vector();
      for (int i = 1; i < paths.length; i++) {
        String name = (String) ((DefaultMutableTreeNode) paths[i]).getUserObject();
        path_str += "/" + name;

        // Converts January...December to 1...12.
        if (mode == DATE_ORIENTED && i == 2) {
          for (int m = 1; m <= 12; m++) {
            if (JulianDay.getFullSpellMonthString(m).equals(name)) name = String.valueOf(m);
          }
        }

        folder_list.addElement(name);
      }

      // When to expand sub folders.
      Vector folders = new Vector();
      if (mode == DATE_ORIENTED) folders = db_manager.getDateOrientedFolders(folder_list);
      if (mode == PATH_ORIENTED) folders = db_manager.getPathOrientedFolders(folder_list);
      addNode(node, folders);

      // When to expand image informations.
      XmlDBAccessor accessor = null;
      if (mode == DATE_ORIENTED) accessor = db_manager.getDateOrientedAccessor(folder_list);
      if (mode == PATH_ORIENTED) accessor = db_manager.getPathOrientedAccessor(folder_list);
      if (accessor != null) {
        Vector name_list = new Vector();
        XmlInformation info = (XmlInformation) accessor.getFirstElement();
        while (info != null) {
          name_list.addElement(info.getPath());
          hash_info.put(path_str + "/" + info.getPath(), info);
          info = (XmlInformation) accessor.getNextElement();
        }
        addNode(node, name_list);
      }

      revalidate();
      repaint();
    } catch (IOException exception) {
      String message = "Failed to read the database.";
      JOptionPane.showMessageDialog(pane, message, "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
예제 #15
0
    public void restorePaths() {
      final ArrayList<DefaultMutableTreeNode> nodesToExpand = getNodesByPaths(myPathsToExpand);
      for (DefaultMutableTreeNode node : nodesToExpand) {
        myTree.expandPath(new TreePath(node.getPath()));
      }

      if (myTree.getSelectionModel().getSelectionCount() == 0) {
        final ArrayList<DefaultMutableTreeNode> nodesToSelect = getNodesByPaths(mySelectionPaths);
        if (!nodesToSelect.isEmpty()) {
          for (DefaultMutableTreeNode node : nodesToSelect) {
            TreeUtil.selectInTree(node, false, myTree);
          }
        } else {
          myTree.setSelectionRow(0);
        }
      }
    }
예제 #16
0
파일: TreeUtil.java 프로젝트: jexp/idea2
  public static ActionCallback selectInTree(
      Project project,
      DefaultMutableTreeNode node,
      boolean requestFocus,
      JTree tree,
      boolean center) {
    if (node == null) return new ActionCallback.Done();

    final TreePath treePath = new TreePath(node.getPath());
    tree.expandPath(treePath);
    if (requestFocus) {
      ActionCallback result = new ActionCallback(2);
      IdeFocusManager.getInstance(project).requestFocus(tree, true).notifyWhenDone(result);
      selectPath(tree, treePath, center).notifyWhenDone(result);
      return result;
    }
    return selectPath(tree, treePath, center);
  }
예제 #17
0
  /**
   * Processes an idChanged event. Search is different from all other navigators in that you while
   * search tree is synchronized the highlighting doesn't occur unless selected from the search
   * navigator.
   */
  public void idChanged(HelpModelEvent e) {
    ID id = e.getID();
    URL url = e.getURL();
    HelpModel helpModel = searchnav.getModel();
    debug("idChanged(" + e + ")");

    if (e.getSource() != helpModel) {
      debug("Internal inconsistency!");
      debug("  " + e.getSource() + " != " + helpModel);
      throw new Error("Internal error");
    }

    TreePath s = tree.getSelectionPath();
    if (s != null) {
      Object o = s.getLastPathComponent();
      // should require only a TreeNode
      if (o instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode tn = (DefaultMutableTreeNode) o;
        SearchTOCItem item = (SearchTOCItem) tn.getUserObject();
        if (item != null) {
          ID nId = item.getID();
          if (nId != null && nId.equals(id)) {
            return;
          }
        }
      }
    }

    DefaultMutableTreeNode node = findIDorURL(topNode, id, url);
    if (node == null) {
      // node doesn't exist. Need to clear the selection.
      debug("node didn't exist");
      tree.clearSelection();
      return;
    }
    TreePath path = new TreePath(node.getPath());
    tree.expandPath(path);
    tree.setSelectionPath(path);
    tree.scrollPathToVisible(path);
  }
  private void restoreSelection(Pair<ElementNode, List<ElementNode>> pair) {
    List<ElementNode> selectedNodes = pair.second;

    DefaultMutableTreeNode root = getRootNode();

    ArrayList<TreePath> toSelect = new ArrayList<TreePath>();
    for (ElementNode node : selectedNodes) {
      DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
      if (root.isNodeDescendant(treeNode)) {
        toSelect.add(new TreePath(treeNode.getPath()));
      }
    }

    if (!toSelect.isEmpty()) {
      myTree.setSelectionPaths(toSelect.toArray(new TreePath[toSelect.size()]));
    }

    ElementNode leadNode = pair.first;
    if (leadNode != null) {
      myTree.setLeadSelectionPath(new TreePath(((DefaultMutableTreeNode) leadNode).getPath()));
    }
  }
  // ===============================================================
  // ===============================================================
  void removeThread() {
    DefaultMutableTreeNode node = getSelectedNode();

    if (node != null) {
      Object obj = node.getUserObject();
      if (obj instanceof PollThread) {
        //	Check if device(s) associated.
        if (node.getChildCount() == 0) {
          //	get future selected node
          DefaultMutableTreeNode next_node = getFutureSelectedNode(node);
          //	Remove selected one
          treeModel.removeNodeFromParent(node);
          PollThread pt = (PollThread) obj;
          threadsInfo.remove(pt);
          //	And select the found node
          TreeNode[] tree_node = next_node.getPath();
          TreePath path = new TreePath(tree_node);
          setSelectionPath(path);
          scrollPathToVisible(path);
        } else Utils.popupError(parent, "Cannot remove a not empty thread !");
      }
    }
  }
예제 #20
0
파일: TreeView.java 프로젝트: jexp/idea2
 public void scrollToStatus() {
   if (myStatusNode != null) {
     TreeUtil.selectPath(myTree, new TreePath(myStatusNode.getPath()));
   }
 }
    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();
      }
    }