Example usage for javax.swing.tree TreePath TreePath

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

Introduction

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

Prototype

public TreePath(Object lastPathComponent) 

Source Link

Document

Creates a TreePath containing a single element.

Usage

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Initializes action objects. <br>
 * Does not assign actions to components yet!
 *//*from   w ww. j a  v  a  2 s .  com*/
private void initializeActions() {

    actionSelectAll = new AbstractAction(Localization.lang("Select all")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot();
            rootNode.setSelected(true);
            tree.invalidate();
            tree.repaint();
        }
    };

    actionUnselectAll = new AbstractAction(Localization.lang("Unselect all")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot();
            rootNode.setSelected(false);
            tree.invalidate();
            tree.repaint();
        }
    };

    actionExpandTree = new AbstractAction(Localization.lang("Expand all")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot();
            expandTree(tree, new TreePath(rootNode), true);
        }
    };

    actionCollapseTree = new AbstractAction(Localization.lang("Collapse all")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            CheckableTreeNode rootNode = (CheckableTreeNode) tree.getModel().getRoot();
            expandTree(tree, new TreePath(rootNode), false);
        }
    };

    dialogPositionListener = new ComponentAdapter() {

        /* (non-Javadoc)
         * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
         */
        @Override
        public void componentResized(ComponentEvent e) {
            storeSizeOfDialog();
        }

        /* (non-Javadoc)
         * @see java.awt.event.ComponentAdapter#componentMoved(java.awt.event.ComponentEvent)
         */
        @Override
        public void componentMoved(ComponentEvent e) {
            storeSizeOfDialog();
        }
    };

}

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

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

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

    treeModel.insertNodeInto(childNode, top, top.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }//from  w w w.  jav  a  2s . co m
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:base.BasePlayer.AddGenome.java

static void checkGenomes() {

    //DefaultMutableTreeNode
    File checkdir = Main.genomeDir, checkAnnodir;
    File[] addDir, annodir;//  w  w w. ja va2 s  .  com
    root.removeAllChildren();
    int counter = 0;
    for (int i = model.getRowCount() - 1; i >= 0; i--) {
        model.removeRow(i);
    }
    for (int i = remmodel.getRowCount() - 1; i >= 0; i--) {
        remmodel.removeRow(i);
    }

    removables.clear();

    int currentlen = 0, length = 0;
    if (checkdir == null) {
        try {
            checkdir = new File(userDir + "/genomes");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    addDir = checkdir.listFiles();
    for (int f = 0; f < addDir.length; f++) {

        try {
            if (!addDir[f].isDirectory()) {
                continue;
            }
            currentlen = genometable.getFontMetrics(genometable.getFont()).stringWidth(addDir[f].getName());
            if (currentlen > length) {
                length = currentlen;
            }

            AddGenome.removables.add(addDir[f].getName());
            checkAnnodir = new File(checkdir + "/" + addDir[f].getName() + "/annotation/");
            annodir = checkAnnodir.listFiles();
            DefaultMutableTreeNode genome = new DefaultMutableTreeNode(addDir[f].getName());
            root.add(genome);
            if (annodir == null) {
                counter++;
                genome.add(new DefaultMutableTreeNode("Add new annotation..."));
            } else {
                counter += annodir.length + 3;
                for (int a = 0; a < annodir.length; a++) {
                    currentlen = genometable.getFontMetrics(genometable.getFont())
                            .stringWidth(annodir[a].getName());
                    if (currentlen > length) {
                        length = currentlen;
                    }
                    genome.add(new DefaultMutableTreeNode(annodir[a].getName()));
                }
                genome.add(new DefaultMutableTreeNode("Add new annotation..."));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (counter == 0) {
        counter = 1;
        length = genometable.getFontMetrics(genometable.getFont()).stringWidth("Add new annotation...");
    }
    counter++;
    root.add(new DefaultMutableTreeNode("Add new reference..."));
    genometable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    for (int i = 0; i < organisms.size(); i++) {
        if (!AddGenome.removables.contains(organisms.get(i))) {
            Object[] row = { organisms.get(i), "" + sizeHash.get(organisms.get(i))[0] / 1048576 };
            model.addRow(row);
            currentlen = genometable.getFontMetrics(genometable.getFont()).stringWidth(organisms.get(i));
            if (currentlen > length) {
                length = currentlen;
            }
        }
    }

    AddGenome.longestName = length;

    if (genometable.getRowCount() > 15) {
        genometable.setPreferredScrollableViewportSize((new Dimension(
                AddGenome.longestName + 20 + Main.defaultFontSize * 8, genometable.getRowHeight() * 15)));
        genometable.setMinimumSize(new Dimension(AddGenome.longestName + 20, genometable.getRowHeight() * 15));
    } else {
        genometable.setPreferredScrollableViewportSize(
                (new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8,
                        genometable.getRowHeight() * (genometable.getRowCount() + 1))));
        genometable.setMinimumSize(new Dimension(AddGenome.longestName + 20,
                genometable.getRowHeight() * (genometable.getRowCount() + 1)));
    }

    if (remtable.getRowCount() > 15) {
        remtable.setPreferredScrollableViewportSize((new Dimension(
                AddGenome.longestName + 20 + Main.defaultFontSize * 8, remtable.getRowHeight() * 15)));
    } else {
        remtable.setPreferredScrollableViewportSize(
                (new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8,
                        remtable.getRowHeight() * (remtable.getRowCount() + 1))));
    }
    //Main.defaultFontSize = 12;
    genometable.getColumnModel().getColumn(0).setPreferredWidth(AddGenome.longestName + 10);
    genometable.getColumnModel().getColumn(0).setMinWidth(AddGenome.longestName + 10);
    //   genometable.getColumnModel().getColumn(1).setPreferredWidth(Main.defaultFontSize*8);
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    model.reload();
    int rowheight = tree.getRowHeight();
    if (rowheight < 1) {
        rowheight = Main.defaultFontSize + 4;
    }

    treescroll.setPreferredSize(
            new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight));
    treescroll.setMinimumSize(
            new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight));
    remscroll.setPreferredSize(
            new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight));
    remscroll.setMinimumSize(
            new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight));
    tree.expandPath(new TreePath(root));

    setFonts(Main.menuFont);
}

From source file:de.quadrillenschule.azocamsyncd.gui.ExploreWifiSDPanel.java

public void updateTree() {
    Enumeration<TreePath> storeExpand = remotejTree
            .getExpandedDescendants(new TreePath(remotejTree.getModel().getRoot()));
    rootNode.removeAllChildren();/*from w  ww  .  ja va  2 s .  c o  m*/
    createNodes(rootNode);
    if (dtm == null) {
        dtm = new DefaultTreeModel(rootNode);
        remotejTree.setModel(dtm);

    }
    dtm.nodeStructureChanged(rootNode);
    if (storeExpand != null) {
        while (storeExpand.hasMoreElements()) {
            TreePath t = storeExpand.nextElement();
            remotejTree.expandPath(t);
            remotejTree.setSelectionPath(t);
        }
    }
}

From source file:fr.jmmc.jmcs.logging.LogbackGui.java

/**
 * Generate the tree from the current edited list of Loggers
 *///from   w  w w  .j  av a 2  s  . c o  m
private void generateTree() {

    visitJulLoggers();

    final GenericJTree<Logger> treeLoggers = getTreeLoggers();

    final LoggerContext loggerContext = _rootLogger.getLoggerContext();

    final DefaultMutableTreeNode rootNode = treeLoggers.getRootNode();

    // remove complete hierarchy:
    rootNode.removeAllChildren();

    // update the root node with the root logger (Logger[ROOT]):
    rootNode.setUserObject(_rootLogger);

    int pos;
    String path;
    DefaultMutableTreeNode parentNode;

    for (Logger logger : loggerContext.getLoggerList()) {

        // skip root logger
        if (logger != _rootLogger) {

            pos = logger.getName().lastIndexOf('.');

            if (pos == -1) {
                // no path
                path = null;
                parentNode = null;

            } else {
                path = logger.getName().substring(0, pos);

                parentNode = treeLoggers.findTreeNode(loggerContext.getLogger(path));
            }

            if (parentNode == null) {
                parentNode = rootNode;
            }

            if (parentNode != null) {
                treeLoggers.addNode(parentNode, logger);
            }
        }
    }

    // fire node structure changed :
    treeLoggers.fireNodeChanged(rootNode);

    // select root node
    treeLoggers.selectPath(new TreePath(rootNode.getPath()));
}

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

public DefaultMutableTreeNode insertNode(QueryMasterData node) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

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

    if (ascending) {
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
    } else {//from   w w w . ja v a  2 s .c  o  m
        treeModel.insertNodeInto(childNode, top, 0);
    }

    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()));

    previousQueries.add(node);

    return childNode;
}

From source file:com.igormaznitsa.sciareto.ui.tree.ExplorerTree.java

public void setModel(@Nonnull final NodeProjectGroup model, final boolean expandFirst) {
      this.projectTree.setModel(Assertions.assertNotNull(model));
      if (expandFirst && model.getChildCount() > 0) {
          this.projectTree.expandPath(new TreePath(new Object[] { model, model.getChildAt(0) }));
      }//from w ww . j  av  a 2 s.c  o  m
  }

From source file:de.codesourcery.jasm16.ide.ui.views.SourceEditorView.java

protected void onCaretUpdate(CaretEvent e) {
    // if AST inspector is visible, make sure the current AST node is visible
    // (scroll there if it isn't)
    if (!isASTInspectorVisible()) {
        return;//ww w . jav  a2s.  c  om
    }

    final AST ast = getCurrentCompilationUnit() != null ? getCurrentCompilationUnit().getAST() : null;
    if (ast == null) {
        return;
    }

    final ASTNode n = ast.getNodeInRange(e.getDot());
    if (n != null) {
        TreePath path = new TreePath(n.getPathToRoot());
        astTree.setSelectionPath(path);
        astTree.scrollPathToVisible(path);
    }
}

From source file:fi.elfcloud.client.tree.ClusterHierarchyModel.java

public void fetchAll(final File destination) {
    ClusterNode node = (ClusterNode) getRoot();
    if (node.getChildCount() >= 0) {
        TreePath[] paths = new TreePath[node.getChildCount()];
        for (int i = 0; i < node.getChildCount(); i++) {
            ClusterTreeNode child = (ClusterTreeNode) node.getChildAt(i);
            paths[i] = new TreePath(child.getPath());
        }//from  w w  w.  j a va2 s  .c  o m
        downloadPaths(paths, destination);
    }
}

From source file:uk.co.markfrimston.tasktree.Main.java

protected void load() {
    try {//w w  w.j a va2  s .  c o  m
        this.taskTree.load();

        // make top level tasks visible
        for (int i = 0; i < this.taskTree.getRoot().getChildCount(); i++) {
            tree.makeVisible(
                    new TreePath(((DefaultMutableTreeNode) this.taskTree.getRoot().getChildAt(i)).getPath()));
        }
    } catch (Exception e) {
        error(e.getMessage());
    }
}