Example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode.

Prototype

public DefaultMutableTreeNode(Object userObject) 

Source Link

Document

Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Usage

From source file:be.fedict.eid.tsl.tool.TslInternalFrame.java

private void addServiceProviderTab(JTabbedPane tabbedPane) {
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    tabbedPane.add("Service Providers", splitPane);

    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Service Providers");
    this.tree = new JTree(rootNode);
    this.tree.addTreeSelectionListener(this);
    for (TrustServiceProvider trustServiceProvider : this.trustServiceList.getTrustServiceProviders()) {
        DefaultMutableTreeNode trustServiceProviderNode = new DefaultMutableTreeNode(
                trustServiceProvider.getName());
        rootNode.add(trustServiceProviderNode);
        for (TrustService trustService : trustServiceProvider.getTrustServices()) {
            MutableTreeNode trustServiceNode = new DefaultMutableTreeNode(trustService);
            trustServiceProviderNode.add(trustServiceNode);
        }//from  ww  w .j  a v  a2  s  .com
    }
    this.tree.expandRow(0);

    JScrollPane treeScrollPane = new JScrollPane(this.tree);
    JPanel detailsPanel = new JPanel();
    splitPane.setLeftComponent(treeScrollPane);
    splitPane.setRightComponent(detailsPanel);

    initDetailsPanel(detailsPanel);
}

From source file:com.github.rholder.gradle.intellij.DependencyViewer.java

public void updateView(GradleNode rootDependency, final GradleNode selectedDependency) {
    // TODO replace this hack with something that populates the GradleNode graph

    DefaultMutableTreeNode fullRoot = new DefaultMutableTreeNode(new GradleNode("Project Dependencies"));
    if (rootDependency == null) {
        DefaultMutableTreeNode loading = new DefaultMutableTreeNode(new GradleNode("Loading..."));
        fullRoot.add(loading);// ww  w .j a  v a 2s . co m
    } else {
        DefaultMutableTreeNode flattenedRoot = convertToSortedTreeNode(rootDependency);
        DefaultMutableTreeNode hierarchyRoot = convertToHierarchyTreeNode(rootDependency);
        fullRoot.add(flattenedRoot);
        fullRoot.add(hierarchyRoot);
    }

    TreeModel treeModel = new DefaultTreeModel(fullRoot);
    final SimpleTree fullTree = new SimpleTree(treeModel);
    fullTree.setCellRenderer(dependencyCellRenderer);

    // expand path for first level from root
    //fullTree.expandPath(new TreePath(hierarchyRoot.getNextNode().getPath()));

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (gradleBaseDir != null) {
                toolWindow.setTitle("- " + gradleBaseDir);
            }
            splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(fullTree));
            splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(information));
        }
    });
}

From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java

private void createInstacesNode(IDataSourceProxy source, DefaultMutableTreeNode nodeChildFirst) {
    List<String> sourceInstancesName = (List<String>) source
            .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST);
    if (sourceInstancesName != null) {
        int i = 0;
        for (String stringa : sourceInstancesName) {
            String title = findTitle(stringa);
            TreeTopComponentAdapter ttca = new TreeTopComponentAdapter(null, false, false, true);
            DefaultMutableTreeNode nodeChild = new DefaultMutableTreeNode(ttca);
            ttca.setName(title);/*from  www.  jav a2s.co m*/
            nodeChildFirst.add(nodeChild);
        }
    } else {
        int i = 1;
        for (INode instanceNode : source.getOriginalInstances()) {
            TreeTopComponentAdapter ttca = new TreeTopComponentAdapter(null, false, false, true);
            DefaultMutableTreeNode nodeChild = new DefaultMutableTreeNode(ttca);
            ttca.setName("Instance: " + i++);
            nodeChildFirst.add(nodeChild);
        }
    }
}

From source file:DynamicTreeDemo.java

public DynamicTree() {
    super(new GridLayout(1, 0));

    rootNode = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(rootNode);

    tree = new JTree(treeModel);
    tree.setEditable(true);/*from w w w  .j a v a2s .  c  o  m*/
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setShowsRootHandles(true);

    JScrollPane scrollPane = new JScrollPane(tree);
    add(scrollPane);
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

public DefaultMutableTreeNode addNode(QueryInstanceData node, DefaultMutableTreeNode parent) {
    QueryMasterData logicdata = (QueryMasterData) parent.getUserObject();
    logicdata.runs.add(node);/*from   w  w w .  j  a  va  2  s.  c  o m*/

    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryInstanceData tmpData = new QueryInstanceData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0);
    QueryData tmpdata = (QueryData) tmpnode.getUserObject();
    if (tmpdata.name().equalsIgnoreCase("working ......")) {
        treeModel.removeNodeFromParent(tmpnode);
    }

    return childNode;
}

From source file:ldap.LdapClient.java

private void createTreeModel(DirContext context) {
    TreeNode root = null;//w  ww  .  j  a  v  a  2  s.  c  o m

    if (context != null) {
        String base = (String) SessionManager.getSession().getProperty("java.naming.provider.basedn");
        root = new LdapTreeNode(context, null, base);
    } else
        root = new DefaultMutableTreeNode(resources.getString("browser.not_connected"));

    treeModel = new DefaultTreeModel(root);
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, top, top.getChildCount());
    treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    // Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java

private void createInstanceChild(DefaultMutableTreeNode nodeTopComponent, IDataSourceProxy source,
        String type) {//from   w ww.  ja v a  2  s. c o m

    TreeTopComponentAdapter ttcaFirst = new TreeTopComponentAdapter(null, false, false, true);
    DefaultMutableTreeNode nodeChildFirst = new DefaultMutableTreeNode(ttcaFirst);
    ttcaFirst.setName(type);
    nodeTopComponent.add(nodeChildFirst);
    createInstacesNode(source, nodeChildFirst);
}

From source file:LocationSensitiveDemo.java

public LocationSensitiveDemo() {
    super("Location Sensitive Drag and Drop Demo");

    treeModel = getDefaultTreeModel();/*from  w  ww .ja  v a 2 s .  co m*/
    tree = new JTree(treeModel);
    tree.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.setDropMode(DropMode.ON);
    namesPath = tree.getPathForRow(2);
    tree.expandRow(2);
    tree.expandRow(1);
    tree.setRowHeight(0);

    tree.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // for the demo, we'll only support drops (not clipboard paste)
            if (!info.isDrop()) {
                return false;
            }

            String item = (String) indicateCombo.getSelectedItem();

            if (item.equals("Always")) {
                info.setShowDropLocation(true);
            } else if (item.equals("Never")) {
                info.setShowDropLocation(false);
            }

            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            // fetch the drop location
            JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();

            TreePath path = dl.getPath();

            // we don't support invalid paths or descendants of the names folder
            if (path == null || namesPath.isDescendant(path)) {
                return false;
            }

            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            // if we can't handle the import, say so
            if (!canImport(info)) {
                return false;
            }

            // fetch the drop location
            JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();

            // fetch the path and child index from the drop location
            TreePath path = dl.getPath();
            int childIndex = dl.getChildIndex();

            // fetch the data and bail if this fails
            String data;
            try {
                data = (String) info.getTransferable().getTransferData(DataFlavor.stringFlavor);
            } catch (UnsupportedFlavorException e) {
                return false;
            } catch (IOException e) {
                return false;
            }

            // if child index is -1, the drop was on top of the path, so we'll
            // treat it as inserting at the end of that path's list of children
            if (childIndex == -1) {
                childIndex = tree.getModel().getChildCount(path.getLastPathComponent());
            }

            // create a new node to represent the data and insert it into the model
            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(data);
            DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            treeModel.insertNodeInto(newNode, parentNode, childIndex);

            // make the new node visible and scroll so that it's visible
            tree.makeVisible(path.pathByAddingChild(newNode));
            tree.scrollRectToVisible(tree.getPathBounds(path.pathByAddingChild(newNode)));

            // demo stuff - remove for blog
            model.removeAllElements();
            model.insertElementAt("String " + (++count), 0);
            // end demo stuff

            return true;
        }
    });

    JList dragFrom = new JList(model);
    dragFrom.setFocusable(false);
    dragFrom.setPrototypeCellValue("String 0123456789");
    model.insertElementAt("String " + count, 0);
    dragFrom.setDragEnabled(true);
    dragFrom.setBorder(BorderFactory.createLoweredBevelBorder());

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    JPanel wrap = new JPanel();
    wrap.add(new JLabel("Drag from here:"));
    wrap.add(dragFrom);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.NORTH);

    getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
    indicateCombo = new JComboBox(new String[] { "Default", "Always", "Never" });
    indicateCombo.setSelectedItem("INSERT");

    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    wrap = new JPanel();
    wrap.add(new JLabel("Show drop location:"));
    wrap.add(indicateCombo);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.SOUTH);

    getContentPane().setPreferredSize(new Dimension(400, 450));
}

From source file:SAXTreeValidator.java

/**
 * <p>//from  ww  w.  jav a 2 s .co  m
 *   This indicates that a processing instruction (other than
 *     the XML declaration) has been encountered.
 * </p>
 *
 * @param target <code>String</code> target of PI
 * @param data <code>String</code containing all data sent to the PI.
 *               This typically looks like one or more attribute value
 *               pairs.
 * @throws <code>SAXException</code> when things go wrong
 */
public void processingInstruction(String target, String data) throws SAXException {

    DefaultMutableTreeNode pi = new DefaultMutableTreeNode(
            "PI (target = '" + target + "', data = '" + data + "')");
    current.add(pi);
}