Java 类javax.swing.tree.DefaultMutableTreeNode 实例源码

项目:jdk8u-jdk    文件:Test4631471.java   
public static TreeNode getRoot() {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode first = new DefaultMutableTreeNode("first");
    DefaultMutableTreeNode second = new DefaultMutableTreeNode("second");
    DefaultMutableTreeNode third = new DefaultMutableTreeNode("third");

    first.add(new DefaultMutableTreeNode("1.1"));
    first.add(new DefaultMutableTreeNode("1.2"));
    first.add(new DefaultMutableTreeNode("1.3"));

    second.add(new DefaultMutableTreeNode("2.1"));
    second.add(new DefaultMutableTreeNode("2.2"));
    second.add(new DefaultMutableTreeNode("2.3"));

    third.add(new DefaultMutableTreeNode("3.1"));
    third.add(new DefaultMutableTreeNode("3.2"));
    third.add(new DefaultMutableTreeNode("3.3"));

    node.add(first);
    node.add(second);
    node.add(third);

    return node;
}
项目:openjdk-jdk10    文件:Test8015926.java   
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
项目:rapidminer    文件:PlotConfigurationTreeModel.java   
/**
 * @param root
 */
public PlotConfigurationTreeModel(DefaultMutableTreeNode root, PlotConfiguration plotConfig,
        PlotConfigurationTree plotConfigTree) {
    super(root);
    this.plotConfig = plotConfig;
    this.plotConfigTree = plotConfigTree;

    if (root != null) {
        fillNewPlotConfigNode(plotConfig);
    }

    if (plotConfig != null) {
        plotConfig.addPlotConfigurationListener(this);
    }

}
项目:MFM    文件:MAMEtoJTree.java   
private DefaultMutableTreeNode createRamoptionNode(Ramoption ramoption) {
    DefaultMutableTreeNode dmtNode = new DefaultMutableTreeNode("ramoption");

    String value = ramoption.getValue();
    if (value != null && !value.isEmpty()) {
        dmtNode.add(new DefaultMutableTreeNode("value" + valueDivider + value));
    }

    String aDefault = ramoption.getDefault();
    if (aDefault != null && !aDefault.isEmpty()) {
        dmtNode.add(new DefaultMutableTreeNode("default" + valueDivider + aDefault));
    }

    return dmtNode;
}
项目:Luyten4Forge    文件:CellRenderer.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
        int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    if (node.getChildCount() > 0) {
        setIcon(this.pack);
    } else if (getFileName(node).endsWith(".class") || getFileName(node).endsWith(".java")) {
        setIcon(this.java_image);
    } else if (getFileName(node).endsWith(".yml") || getFileName(node).endsWith(".yaml")) {
        setIcon(this.yml_image);
    } else {
        setIcon(this.file_image);
    }

    return this;
}
项目:freecol    文件:NationTypeDetailPanel.java   
/**
 * {@inheritDoc}
 */
@Override
public void addSubTrees(DefaultMutableTreeNode root) {
    DefaultMutableTreeNode parent
        = new DefaultMutableTreeNode(new ColopediaTreeItem(this, getId(),
                getName(), null));

    List<NationType> nations = new ArrayList<>();
    nations.addAll(getSpecification().getEuropeanNationTypes());
    nations.addAll(getSpecification().getREFNationTypes());
    nations.addAll(getSpecification().getIndianNationTypes());
    ImageIcon icon = new ImageIcon(ImageLibrary.getMiscImage(ImageLibrary.BELLS, ImageLibrary.ICON_SIZE));
    for (NationType type : nations) {
        parent.add(buildItem(type, icon));
    }
    root.add(parent);
}
项目:incubator-netbeans    文件:RevertDeletedAction.java   
private void retrieveDeletedFiles(final Node[] activatedNodes, final RevertPanel p) {
    VCSContext ctx = VCSContext.forNodes(activatedNodes);
    Set<VCSFileProxy> rootSet = ctx.getRootFiles();        
    if(rootSet == null || rootSet.size() < 1) { 
        return;
    }                                        
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    for (VCSFileProxy root : rootSet) {            
        PlainFileNode rfn = new PlainFileNode(root);
        populateNode(rfn, root, !VersioningSupport.isFlat(root));
        if(rfn.getChildCount() > 0) {
            rootNode.add(rfn);
        }
    }
    if(rootNode.getChildCount() > 0) {
        p.setRootNode(rootNode);
    } else {
        p.setRootNode(null);
    }
}
项目:featurea    文件:SimulationTreePanel.java   
/**
 * Shows the a dialog allowing the user to edit the ray.
 */
private void editRayAction() {
    // getProperty the currently selected body
    TreePath path = this.tree.getSelectionPath();
    // make sure something is selected
    if (path != null) {
        // getProperty the selected node
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        // make sure its a ray that is selected
        if (node.getUserObject() instanceof SandboxRay) {
            // getProperty the ray from the node
            SandboxRay ray = (SandboxRay) node.getUserObject();
            // show the right dialog
            synchronized (Simulation.LOCK) {
                SandboxRay nRay = EditRayDialog.show(ControlUtilities.getParentWindow(this), ray);
                this.simulation.getRays().remove(ray);
                this.simulation.getRays().add(nRay);
                node.setUserObject(nRay);
            }
        }
    }
}
项目:oxygen-dita-translation-package-builder    文件:PreviewDialog.java   
/**
 * Returns the index of a child of a given node, provided its string value.
 * 
 * @param node The node to search its children.
 * @param childValue The value of the child to compare with.
 * @return The index.
 */
private int childIndex(final DefaultMutableTreeNode node, final String childValue) {
  @SuppressWarnings("unchecked")
  Enumeration<DefaultMutableTreeNode> children = node.children();
  DefaultMutableTreeNode child = null;
  int index = -1;

  while (children.hasMoreElements() && index < 0) {
    child = children.nextElement();

    if (child.getUserObject() != null && childValue.equals(child.getUserObject())) {
      index = node.getIndex(child);
    }
  }

  return index;
}
项目:FreeCol    文件:OptionGroupUI.java   
/**
 * This function analyses a tree selection event and calls the
 * right methods to take care of building the requested unit's
 * details.
 *
 * @param event The incoming TreeSelectionEvent.
 */
@Override
public void valueChanged(TreeSelectionEvent event) {
    detailPanel.removeAll();
    DefaultMutableTreeNode node
        = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (node != null) {
        if (node.isLeaf()) {
            OptionGroup group = (OptionGroup) node.getUserObject();
            for (Option option : group.getOptions()) {
                addOptionUI(option, editable && group.isEditable());
            }
        } else {
            tree.expandPath(event.getPath());
        }
    }
    detailPanel.revalidate();
    detailPanel.repaint();
}
项目:routerapp    文件:NavigationView.java   
/**
 * @param e
 */
protected void itemSelected(MouseEvent e) {
 if (e.getClickCount() == 2) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

     if (node != null) {
         if (node.isLeaf())
            if (node.getParent() != null) {
            if (node.getParent().toString().equals("graphs")) {
                  for (int i=0 ; i<observers.size() ; i++)
                      (observers.get(i)).graphSelected(node.toString());
              }
              else if (node.getParent().toString().equals("animations")) {
                  for (int i=0 ; i<observers.size() ; i++)
                      (observers.get(i)).animationSelected(node.toString());
              }
              else if (node.getParent().toString().equals("algorithms")) {
                  for (int i=0 ; i<observers.size() ; i++)
                      (observers.get(i)).algorithmSelected(node.toString());
              }
          }
  }
    }
}
项目:gate-core    文件:MainFrame.java   
@Override
public void actionPerformed(ActionEvent e) {
  Runnable runner = new Runnable() {
    @Override
    public void run() {
      TreePath[] paths = resourcesTree.getSelectionPaths();
      for(TreePath path : paths) {
        final Object userObject = ((DefaultMutableTreeNode)
          path.getLastPathComponent()).getUserObject();
        if(userObject instanceof NameBearerHandle) {
          SwingUtilities.invokeLater(new Runnable() { @Override
          public void run() {
            ((NameBearerHandle)userObject).getCloseAction()
              .actionPerformed(null);
          }});
        }
      }
    }
  };
  Thread thread = new Thread(runner, "CloseSelectedResourcesAction");
  thread.setPriority(Thread.MIN_PRIORITY);
  thread.start();
}
项目:AgentWorkbench    文件:DynFormBase.java   
/**
 * Provides the Vector of all currently available nodes of the same kind as the current node.
 *
 * @param currNode The current node of the object structure
 * @return the multiple nodes available
 */
private Vector<DefaultMutableTreeNode> getMultipleNodesAvailable(DefaultMutableTreeNode currNode) {

    // --- The result vector of all needed nodes ------------------------------------ 
    Vector<DefaultMutableTreeNode> nodesFound = new Vector<DefaultMutableTreeNode>();
    // --- Can we find the number of similar nodes to the current one? -------------- 
    DynType currDT = (DynType) currNode.getUserObject();

    // --- The current parentNode and the position of the current node --------------
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) currNode.getParent();

    // --- Search for all similar nodes --------------------------------------------- 
    for (int i = 0; i < parentNode.getChildCount(); i++) {
        DefaultMutableTreeNode checkNode = (DefaultMutableTreeNode) parentNode.getChildAt(i);
        DynType checkDT = (DynType) checkNode.getUserObject();
        if (checkDT.equals(currDT)) {
            nodesFound.add(checkNode);
        } 
    }
    return nodesFound;

}
项目:Mujeed-Arabic-Prolog    文件:FileTree.java   
/** Construct a FileTree */
 public FileTree(File dir) {
   setLayout(new BorderLayout());
   applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
   setBorder(null);

   // Make a tree list with all the nodes, and make it a JTree
   JTree tree = new JTree(addNodes(null, dir));
   tree.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

   // Add a listener
   tree.addTreeSelectionListener(new TreeSelectionListener() {
     public void valueChanged(TreeSelectionEvent e) {
       DefaultMutableTreeNode node = (DefaultMutableTreeNode) e
           .getPath().getLastPathComponent();
     }
   });

   add(BorderLayout.CENTER, tree);

   JScrollPane scrollBarExplorer = new JScrollPane();
   scrollBarExplorer.getViewport().add(tree);
   scrollBarExplorer.setBorder(null);
add(scrollBarExplorer, BorderLayout.CENTER);

 }
项目:incubator-netbeans    文件:ExcludeDependencyPanel.java   
private TreeNode createReferenceModel(Set<DependencyNode> nds, CheckNode trans) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(null, true);
    ChangeListener list = new Listener();
    List<CheckNode> s = new ArrayList<CheckNode>();
    Icon icn = ImageUtilities.image2Icon(ImageUtilities.loadImage(IconResources.DEPENDENCY_ICON, true)); //NOI18N
    change2Trans.put(list, trans);
    change2Refs.put(list, s);
    for (DependencyNode nd : nds) {
        String label = nd.getArtifact().getGroupId() + ":" + nd.getArtifact().getArtifactId();
        CheckNode child = new CheckNode(nd, label, icn);
        child.setSelected(isSingle);
        child.addChangeListener(list);
        s.add(child);
        root.add(child);
    }
    return root;
}
项目:featurea    文件:SimulationTreePanel.java   
/**
 * Shows an add new joint dialog using the given joint panel.
 * <p>
 * If the user closes or cancels, nothing is modified.  If the user clicks the add button
 * a new joint is created and added to the world.
 *
 * @param clazz the joint class
 */
private void addJointAction(Class<? extends Joint> clazz) {
    synchronized (Simulation.LOCK) {
        SandboxBody[] bodies = this.getBodies();
        // check the joint class type
        if (bodies == null || bodies.length == 0 || (clazz != PinJoint.class && bodies.length == 1)) {
            JOptionPane.showMessageDialog(ControlUtilities.getParentWindow(this), Messages.getString("menu.resources.joint.add.warning"),
                    Messages.getString("menu.resources.joint.add.warning.title"), JOptionPane.ERROR_MESSAGE);
            return;
        }

        Joint joint = AddJointDialog.show(ControlUtilities.getParentWindow(this), bodies, clazz);
        if (joint != null) {
            // add the joint to the world
            this.simulation.getWorld().addJoint(joint);
            // add the joint to the root node
            DefaultMutableTreeNode jointNode = new DefaultMutableTreeNode(joint);
            // insert into the tree
            this.model.insertNodeInto(jointNode, this.jointFolder, this.jointFolder.getChildCount());
            // expand the path to the new node
            this.tree.expandPath(new TreePath(jointNode.getPath()).getParentPath());
        }
    }
}
项目:swingspy    文件:SwingSpyPanel.java   
/**
 * Recursively adds new nodes to the tree.
 */
protected void addNode(DefaultMutableTreeNode parent, Component component, Component selectedComponent) {
    DefaultMutableTreeNode componentNode = new DefaultMutableTreeNode(new ComponentWrapper(component));
    parent.add(componentNode);
    if (component == selectedComponent) {
        TreePath selectedPath = new TreePath(componentNode.getPath());
        componentTree.setSelectionPath(selectedPath);
        componentTree.scrollPathToVisible(selectedPath);
    }

    if (component instanceof Container) {
        Container container = (Container) component;
        Component[] childComponents = container.getComponents();
        for (Component child : childComponents) {
            addNode(componentNode, child, selectedComponent);
        }
    }
}
项目:featurea    文件:SimulationTreePanel.java   
/**
 * Applies a force to the given body if the user accepts the input.
 */
private void applyForceAction() {
    // the current selection should have the body selected
    TreePath path = this.tree.getSelectionPath();
    // make sure that something is selected
    if (path != null) {
        // getProperty the currently selected node
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        // make sure the selected node is a body
        if (node.getUserObject() instanceof SandboxBody) {
            // getProperty the body from the node
            SandboxBody body = (SandboxBody) node.getUserObject();
            // show the force input dialog
            Vector2 f = ApplyForceDialog.show(ControlUtilities.getParentWindow(this));
            // make sure the user accepted the input
            if (f != null) {
                synchronized (Simulation.LOCK) {
                    body.applyForce(f);
                }
            }
        }
    }
}
项目:incubator-netbeans    文件:HintsPanel.java   
private void handleClick(MouseEvent e) {
    if (e.isPopupTrigger()) {
        Point p = e.getPoint();
        TreePath path = errorTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
        if (path != null) {
            DefaultMutableTreeNode o = (DefaultMutableTreeNode) path.getLastPathComponent();
            if (o.getUserObject() instanceof HintMetadata) {
                HintMetadata hint = (HintMetadata) o.getUserObject();
                if (hint.category.equals(Utilities.CUSTOM_CATEGORY)) {
                    JPopupMenu popup = new JPopupMenu();
                    popup.add(new JMenuItem(new RenameHint(o, hint, path)));
                    popup.add(new JMenuItem(new RemoveHint(o, hint)));
                    popup.show(errorTree, e.getX(), e.getY());
                }
            }
        }
    }
}
项目:featurea    文件:SimulationTreePanel.java   
/**
 * Called when the user clicks the Center On Origin menu item on a body.
 */
private void centerOnOriginAction() {
    // the current selection should have the body selected
    TreePath path = this.tree.getSelectionPath();
    // make sure that something is selected
    if (path != null) {
        // getProperty the currently selected node
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        // make sure the selected node is a body
        if (node.getUserObject() instanceof SandboxBody) {
            // getProperty the body from the node
            SandboxBody body = (SandboxBody) node.getUserObject();
            synchronized (Simulation.LOCK) {
                // re-center the body
                body.translateToOrigin();
            }
        }

    }
}
项目:scorekeeperfrontend    文件:CarTreeRenderer.java   
/**
 * Overridden DefaultTreeCellRenderer method to change the type of drawing.
 * @param tree      the main tree object
 * @param value     the value we want to display
 * @param isSel     if this tree node is selected
 * @param isExp     if this tree node is expanded
 * @param isLeaf    if this is a leaf node
 * @param index     the index of this node in the tree node array
 * @param cHasFocus if the focus is on this node
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                    boolean isSel, boolean isExp, boolean isLeaf, int index, boolean cHasFocus)
{
    super.getTreeCellRendererComponent(tree, value, isSel, isExp, isLeaf, index, cHasFocus);

    Object o = ((DefaultMutableTreeNode)value).getUserObject();
    if (o instanceof Entrant)
    {
        Entrant e = (Entrant)o;

        String display = e.getNumber() + " - " + e.getName() + " - " + e.getCarModel() + " " + Database.d.getEffectiveIndexStr(e.getCar());
        setText(display);
    }

    return this;
}
项目:rlc-analyser    文件:RLCTreeBuilder.java   
/**
 * This method will create the configuration tab tree
 *
 * @param dataStore
 *            - the RLCDataStore that was used to collect all the data for
 *            the RLCs processed
 * @param configurationDataStore
 *            - the ConfigurationDataStore that was used to collect all the
 *            data for the RLCs processed
 * @return JScrollPane
 */
public JScrollPane createConfigurationResultsTree(final RLCDataStore dataStore,
                                                  final ConfigurationDataStore configurationDataStore) {
    final DefaultMutableTreeNode top = new DefaultMutableTreeNode("root");

    final ConfigurationAnalyser configurationAnalyser = new ConfigurationAnalyser(configurationDataStore);

    // Populate with config tab results
    final DefaultMutableTreeNode commPointAnalysis = new DefaultMutableTreeNode("Communication Points");
    for (final String type : configurationAnalyser.getAllCommunicationPointTypes()) {
        final List<ModifiedPropertyCountData> properties = configurationAnalyser
                .getModifiedCommunicationPointPropertyCounts(type, -1);
        addResultTreeNode(commPointAnalysis, "" + type + " configuration", properties);
    }
    top.add(commPointAnalysis);

    return new JScrollPane(manipulateJTree(top));
}
项目:FreeCol    文件:OptionGroupUI.java   
/**
 * Builds the JTree which represents the navigation menu and then
 * returns it
 *
 * @param group The {@code OptionGroup} to build from.
 * @param parent The tree to build onto.
 */
private void buildTree(OptionGroup group, DefaultMutableTreeNode parent) {
    for (Option option : group.getOptions()) {
        if (option instanceof OptionGroup) {
            if (!((OptionGroup)option).isVisible()) continue;
            DefaultMutableTreeNode branch
                = new DefaultMutableTreeNode(option);
            parent.add(branch);
            buildTree((OptionGroup) option, branch);
        }
    }
}
项目:rlc-analyser    文件:RLCTreeBuilder.java   
/**
 * This method is used to add nodes to a tree
 *
 * @param node
 *            - the node to be added to
 * @param categoryName
 *            - the group name of the list of the items
 * @param counts
 *            - list of counts values
 */
private void addResultTreeNode(final DefaultMutableTreeNode node, final String categoryName,
                               final List<ModifiedPropertyCountData> counts) {
    final DefaultMutableTreeNode category = new DefaultMutableTreeNode(categoryName);
    node.add(category);

    for (final ModifiedPropertyCountData count : counts) {
        final DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(ResultsFormatter.formatCount(count));
        category.add(childNode);
    }
}
项目:jdk8u-jdk    文件:XSheet.java   
public boolean isMBeanNode(DefaultMutableTreeNode node) {
    Object userObject = node.getUserObject();
    if (userObject instanceof XNodeInfo) {
        XNodeInfo uo = (XNodeInfo) userObject;
        return uo.getType().equals(Type.MBEAN);
    }
    return false;
}
项目:UaicNlpToolkit    文件:MyTreeModel.java   
public void valueForPathChanged(TreePath path, Object newValue) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    String name = ((String) newValue).trim();
    if (node.toString().equals(name))//s-a introdus acelasi text
        return;

    boolean ok = true;
    if (name == null || name.isEmpty()) {
        ok = false;
        JOptionPane.showMessageDialog(grammarEditor.frame, "The node name cannot be empty", "Error", JOptionPane.ERROR_MESSAGE);
    } else if (grammarEditor.grammar.getGraphs().containsKey(name)) {
        ok = false;
        JOptionPane.showMessageDialog(grammarEditor.frame, "A graph with this name exists already", "Error", JOptionPane.ERROR_MESSAGE);
    }

    if (!ok) {
        grammarEditor.graphTree.startEditingAtPath(path);
    } else {
        RenameGraphCommand renameGraphCommand = new RenameGraphCommand();
        renameGraphCommand.graph = ((MyTreeNodeObject) node.getUserObject()).graph;
        renameGraphCommand.grammarEditor = grammarEditor;
        renameGraphCommand.prevName = renameGraphCommand.graph.getId();
        renameGraphCommand.nextName = name;
        grammarEditor.grammar.getGraphs().put(name, renameGraphCommand.graph);
        grammarEditor.grammar.getGraphs().remove(renameGraphCommand.graph.getId());
        renameGraphCommand.graph.setId(name);


        grammarEditor.undoSupport.postEdit(renameGraphCommand);
        grammarEditor.refreshTree();
    }

    nodeChanged(node);
}
项目:sbc-qsystem    文件:PComplexService.java   
@Override
public boolean canImport(TransferHandler.TransferSupport info) {

    final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
    final TreePath tp = dl.getPath();
    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) tp
        .getLastPathComponent();
    return parent.getParent().getParent() == null;
}
项目:VASSAL-src    文件:ConfigureTree.java   
protected Action buildCloneAction(final Configurable target) {
  final DefaultMutableTreeNode targetNode = getTreeNode(target);
  if (targetNode.getParent() != null) {
    return new AbstractAction("Clone") {
      private static final long serialVersionUID = 1L;

      public void actionPerformed(ActionEvent evt) {
        Configurable clone = null;
        try {
          clone = target.getClass().getConstructor().newInstance();
        }
        catch (Throwable t) {
          ReflectionUtils.handleNewInstanceFailure(t, target.getClass());
        }

        if (clone != null) {
          clone.build(target.getBuildElement(Builder.createNewDocument()));
          insert(getParent(targetNode), clone,
                 targetNode.getParent().getIndex(targetNode) + 1);
        }
      }
    };
  }
  else {
    return null;
  }
}
项目:incubator-netbeans    文件:PathsCustomizer.java   
private static DefaultTreeModel toTreeModel(final DefaultListModel lm, final String rootName) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootName);
    for (int i = 0; i < lm.getSize(); i++) {
        Object obj = lm.getElementAt(i);
        if (obj instanceof ClassPathSupport.Item) {
            root.add(toTreeNode(obj));
        }
    }
    return new DefaultTreeModel(root);
}
项目:UaicNlpToolkit    文件:MyTreeCellEditor.java   
@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
    MyTreeNodeObject myTreeNodeObject = (MyTreeNodeObject) ((DefaultMutableTreeNode) value).getUserObject();
    if (myTreeNodeObject.graph == null || myTreeNodeObject.graph.getId().equals("Main")) {
        Toolkit.getDefaultToolkit().beep();
        return renderer.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, true); // hasFocus == true
    }
    return super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
}
项目:smile_1.5.0_java7    文件:SmileDemo.java   
/** Required by TreeSelectionListener interface. */
@Override
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

    if (node != null && node.isLeaf()) {
        int pos = workspace.getDividerLocation();
        workspace.setTopComponent((JPanel) node.getUserObject());
        workspace.setDividerLocation(pos);
    }
}
项目:JAddOn    文件:TreeTransferHandler.java   
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree)c;
    TreePath[] paths = tree.getSelectionPaths();
    if(paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies =
            new ArrayList<DefaultMutableTreeNode>();
        List<DefaultMutableTreeNode> toRemove =
            new ArrayList<DefaultMutableTreeNode>();
        DefaultMutableTreeNode node =
            (DefaultMutableTreeNode)paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = copy(node);
        copies.add(copy);
        toRemove.add(node);
        for(int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next =
                (DefaultMutableTreeNode)paths[i].getLastPathComponent();
            // Do not allow higher level nodes to be added to list.
            if(next.getLevel() < node.getLevel()) {
                break;
            } else if(next.getLevel() > node.getLevel()) {  // child node
                copy.add(copy(next));
                // node already contains child
            } else {                                        // sibling
                copies.add(copy(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes =
            copies.toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove =
            toRemove.toArray(new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
项目:gate-core    文件:MainFrame.java   
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
  boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
    hasFocus);
  if(value == resourcesTreeRoot) {
    setIcon(MainFrame.getIcon("GATE"));
    setToolTipText("Resources tree root ");
  }
  else if(value == applicationsRoot) {
    setIcon(MainFrame.getIcon("applications"));
    setToolTipText("Run processes on data ");
  }
  else if(value == languageResourcesRoot) {
    setIcon(MainFrame.getIcon("lrs"));
    setToolTipText("Data used for annotating ");
  }
  else if(value == processingResourcesRoot) {
    setIcon(MainFrame.getIcon("prs"));
    setToolTipText("Processes that annotate data ");
  }
  else if(value == datastoresRoot) {
    setIcon(MainFrame.getIcon("datastores"));
    setToolTipText("Repositories for large data ");
  }
  else {
    // not one of the default root nodes
    value = ((DefaultMutableTreeNode)value).getUserObject();
    if(value instanceof Handle) {
      setIcon(((Handle)value).getIcon());
      setText(((Handle)value).getTitle());
      setToolTipText(((Handle)value).getTooltipText());
    }
  }
  return this;
}
项目:openjdk-jdk10    文件:LastNodeLowerHalfDrop.java   
private void expandTree(JTree tree) {
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel()
            .getRoot();
    Enumeration e = root.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        if (node.isLeaf()) {
            continue;
        }
        int row = tree.getRowForPath(new TreePath(node.getPath()));
        tree.expandRow(row);
    }
}
项目:featurea    文件:ClassEditor.java   
private void jTree1ValueChanged(TreeSelectionEvent paramTreeSelectionEvent) {
    DefaultMutableTreeNode localDefaultMutableTreeNode = (DefaultMutableTreeNode) this.jTree1.getLastSelectedPathComponent();
    if (localDefaultMutableTreeNode == null) {
        return;
    }
    ClassFileStatus localClassFileStatus = (ClassFileStatus) localDefaultMutableTreeNode;
    switchClass(localClassFileStatus);
}
项目:MFM    文件:MFMController.java   
private String getMouseSelectedGame() {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) folderTree.getLastSelectedPathComponent();
    if (node == null) {
        return null;
    }
    Object nodeInfo = node.getUserObject();
    return nodeInfo.toString();
}
项目:AgentWorkbench    文件:ThreadInfoStorageTree.java   
/**
 * Filter node by key.
 *
 * @param node the node
 * @param key the key
 */
private void filterNodeByKey(DefaultMutableTreeNode node, String key){

        Vector<DefaultMutableTreeNode> toDeleteVect= new Vector<DefaultMutableTreeNode>();

        @SuppressWarnings("unchecked")
        Enumeration<DefaultMutableTreeNode> e = node.breadthFirstEnumeration();
        if(e != null){
            while (e.hasMoreElements()){
                DefaultMutableTreeNode actualElement = e.nextElement();
                if (actualElement.isLeaf() == true && key.isEmpty() == false && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == false) {
                    //--- immediate removal invalidates the enumeration ---
    //              actualElement.removeFromParent();
                    // --- remember for later removal ---
                    toDeleteVect.add(actualElement); 
                }
                if(actualElement.isLeaf() == true && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == true){
                    //--- (re)expand collapsed parent if search string matches ---
                    int level = actualElement.getLevel() -1;
                    StringBuilder sb = new StringBuilder();
                    sb.append(level -1).append(",");
                    String levelString = sb.toString();
                    if(expansionState.contains(levelString) == false){
                        levelString = sb.append(level).append(",").toString();
                        expansionState = expansionState.concat(levelString);
                    }
                }
            }
        }
        //--- delete nodes ---
        for( int i=0; i < toDeleteVect.size(); i++){
            toDeleteVect.get(i).removeFromParent();
        }
    }
项目:geomapapp    文件:KMLExportConfigDialog.java   
private void addScale() {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode("Scaled by");

    getContentPane().remove(currentComponent);

    JPanel scalePanel = new ScalePanel(node); 
    currentComponent = scalePanel;
    getContentPane().add(scalePanel);
    scalePanels.add(scalePanel);

    ((DefaultTreeModel) tree.getModel()).insertNodeInto(node, data, data.getChildCount());
    tree.setSelectionPath(new TreePath(node.getPath()));

    getContentPane().validate();
}
项目:Luyten4Forge    文件:TreeUtil.java   
private String getRowPathStr(TreePath trp) {
    String pathStr = "";
    if (trp.getPathCount() > 1) {
        for (int i = 1; i < trp.getPathCount(); i++) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) trp.getPathComponent(i);
            TreeNodeUserObject userObject = (TreeNodeUserObject) node.getUserObject();
            pathStr = pathStr + userObject.getOriginalName() + "/";
        }
    }
    return pathStr;
}
项目:featurea    文件:MyRmlTagTreeTransferHandler.java   
@Override
public void insertNodeInto(DefaultMutableTreeNode parent, int index, DefaultMutableTreeNode child) {
    RmlTag parentRmlTag = (RmlTag) parent.getUserObject();
    RmlTag childRmlTag = (RmlTag) child.getUserObject();
    editor.replaceRmlTag(parentRmlTag, childRmlTag, index);
    lastParentRmlTag = parentRmlTag;
    lastIndex = index;
}