List of usage examples for javax.swing.tree DefaultMutableTreeNode getLevel
public int getLevel()
From source file:Main.java
public static void expand(JTree tree, int level) { DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); while (currentNode != null) { if (currentNode.getLevel() <= level) { tree.expandPath(new TreePath(currentNode.getPath())); }// ww w. j a va 2 s .c o m currentNode = currentNode.getNextNode(); } }
From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java
public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) labelsTree.getLastSelectedPathComponent(); if (node != null) { logger.debug("Labels tree selection path: " + node.getPath()[node.getLevel()]); if (node.getUserObject() instanceof NotebookNodeUserObject) { NotebookNodeUserObject labelNode = (NotebookNodeUserObject) node.getUserObject(); // TODO bundle StatusBar.show("Label " + labelNode.getNotebookUri() + " selected..."); notebooksTree.reloadModel(labelNode.getNotebookUri()); }//www . jav a 2 s . c o m } }
From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTree.java
public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) notebooksTree.getLastSelectedPathComponent(); if (node != null && !notebooksTree.isRoot(node)) { logger.debug("Outlines tree selection path: " + node.getPath()[node.getLevel()]); if (node.getUserObject() instanceof NotebookNodeUserObject) { NotebookNodeUserObject notebookNode = (NotebookNodeUserObject) node.getUserObject(); // TODO bundle StatusBar.show("Outline " + notebookNode.getNotebookUri() + " selected..."); try { OutlineJPanel.getInstance().conceptJPanel.clear(); MindRaider.profile.setActiveOutlineUri(null); MindRaider.outlineCustodian.loadOutline(new URI(notebookNode.getNotebookUri())); OutlineJPanel.getInstance().refresh(); } catch (URISyntaxException e1) { // TODO option with question whether to remove non-existent notebook logger.debug("Unable to load Outline: ", e1); }/*from w w w . j av a 2s . c om*/ } if (notebooksTree.getToolbar() != null) { notebooksTree.getToolbar().enableDisableToolbarButtons(NotebooksTree.LEVEL_NOTEBOOKS); } } else { if (notebooksTree.getToolbar() != null) { notebooksTree.getToolbar().enableDisableToolbarButtons(NotebooksTree.LEVEL_ROOT); } } }
From source file:org.netxilia.server.rest.HomeResource.java
/** * build the HTML tags for a tree like view * /* ww w .j a v a 2 s .c o m*/ * @param foldersSheet * @param treeview * @throws NetxiliaBusinessException * @throws NetxiliaResourceException */ private DefaultMutableTreeNode buildWorkbookTree(IWorkbook workbook, ISheet foldersSheet, Set<SheetFullName> sheetNames) throws NetxiliaResourceException, NetxiliaBusinessException { DefaultMutableTreeNode workbookNode = new DefaultMutableTreeNode( new TreeViewData(workbook.getId().getKey(), workbook.getName(), "workbook")); Stack<DefaultMutableTreeNode> stockNodes = new Stack<DefaultMutableTreeNode>(); stockNodes.push(workbookNode); Set<SheetFullName> alreadyInsertedSheets = new HashSet<SheetFullName>(); if (foldersSheet != null) { Matrix<CellData> folderCells = foldersSheet.receiveCells(AreaReference.ALL).getNonBlocking(); for (List<CellData> row : folderCells.getRows()) { int level = 0; String nodeName = null; for (CellData cell : row) { if (cell.getValue() != null) { nodeName = cell.getValue().getStringValue(); if (nodeName != null && nodeName.length() > 0) { level = cell.getReference().getColumnIndex(); break; } } } if (nodeName == null) { // empty line - ignored continue; } // first level for folders is 1 (under the root node) level = level + 1; SheetFullName sheetName = new SheetFullName(workbook.getName(), nodeName); boolean isSheet = sheetNames.contains(sheetName); if (isSheet) { alreadyInsertedSheets.add(sheetName); } DefaultMutableTreeNode crt = new DefaultMutableTreeNode(new TreeViewData(sheetName.toString(), sheetName.getSheetName(), isSheet ? "sheet" : "folder")); while (!stockNodes.empty()) { DefaultMutableTreeNode node = stockNodes.peek(); if (level > node.getLevel()) { // make sure is the direct child node.add(crt); break; } stockNodes.pop(); } stockNodes.push(crt); } } // add the sheets not already added for (SheetFullName sheetName : sheetNames) { if (alreadyInsertedSheets.contains(sheetName)) { continue; } DefaultMutableTreeNode sheetNode = new DefaultMutableTreeNode( new TreeViewData(sheetName.toString(), sheetName.getSheetName(), "sheet")); workbookNode.add(sheetNode); } return workbookNode; }
From source file:gui.GraphsPanel.java
/** detectWeakEdges(). * /*from ww w.j ava 2 s.c o m*/ */ public void detectWeakEdges(TreeNode root, float sensitivity) { Color customColor = Color.WHITE; // TV get a snapshot of original colors for each node with singleton Color prevColor = null; @SuppressWarnings("unchecked") Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration(); while (en.hasMoreElements()) { DefaultMutableTreeNode node = en.nextElement(); DenNode dNode = (DenNode) node.getUserObject(); Integer level = node.getLevel(); if (prevColor == null) { prevColor = dNode.getColor(); } if (level == 0) { dNode.setColor(customColor); } else if (level != 0) { DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject(); if ((dNode.getSimilarity() > this.getThreshold()) && (pdNode.getColor().equals(Color.WHITE))) { dNode.setColor( Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f)); } else { dNode.setColor(pdNode.getColor()); } dNode.resetEdgeColor(); if (((dNode.getSimilarity() - pdNode.getSimilarity()) > sensitivity)) { dNode.setEdgeColor(Color.RED); } } } }
From source file:gui.GraphsPanel.java
/** TODO: re-implement the algorithm from vertexColor. * Vertice Coloring algorithm executed before the vertexColor Transformer is * called// w w w. j ava2 s .c o m * TV same algorithm initially set as a vertexColor Transformer COPY FROM * PROCESSCLUSTERRESULTS */ public void colorizeTree(TreeNode root, float threshold) { // System.out.println("___GraphsPanel: COLORIZE TREE!"); Color customColor = Color.WHITE; // int groupCount = // cluster.getAvLnkDendrogram().getGroupCount(threshold); // int counter = groupCount; // traverese the tree // Enumeration en = // ((DefaultMutableTreeNode)root).depthFirstEnumeration(); @SuppressWarnings("unchecked") Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration(); while (en.hasMoreElements()) { // Unfortunately the enumeration isn't genericised so we need to // downcast // when calling nextElement(): DefaultMutableTreeNode node = en.nextElement(); DenNode dNode = (DenNode) node.getUserObject(); Integer level = node.getLevel(); if (level == 0) { dNode.setColor(customColor); } else if (level != 0) { DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject(); if ((dNode.getSimilarity() > threshold) && (pdNode.getColor().equals(Color.WHITE))) { dNode.setColor( Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f)); } else { dNode.setColor(pdNode.getColor()); } // TV if (((dNode.getSimilarity() - pdNode.getSimilarity()) > this.getSensitivity())) { dNode.setEdgeColor(Color.BLACK); } } } }
From source file:org.kuali.maven.plugins.externals.MojoHelper.java
public String getDisplayString(DefaultMutableTreeNode node) { Project project = (Project) node.getUserObject(); GAV gav = project.getGav();/*from w ww . j av a2 s. c o m*/ GAV parent = project.getParent(); int level = node.getLevel(); StringBuilder sb = new StringBuilder(); sb.append(StringUtils.repeat(" ", level)); sb.append(toString(parent)); sb.append(" -> "); sb.append(toString(gav)); sb.append("\n"); Enumeration<?> children = node.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); sb.append(getDisplayString(child)); } return sb.toString(); }
From source file:org.kuali.maven.plugins.externals.MojoHelper.java
public void incrementVersions(DefaultMutableTreeNode node) { Project project = (Project) node.getUserObject(); GAV gav = project.getGav();//from w w w .ja v a 2 s . c o m String oldVersion = gav.getVersion(); if (!StringUtils.isBlank(oldVersion)) { String newVersion = getNextVersion(oldVersion); GAV newGav = new GAV(); newGav.setGroupId(gav.getGroupId()); newGav.setArtifactId(gav.getArtifactId()); newGav.setVersion(newVersion); project.setNewGav(newGav); logger.info(StringUtils.repeat(" ", node.getLevel()) + gav.getArtifactId() + ":" + gav.getArtifactId() + ":" + oldVersion + "->" + newVersion); } List<DefaultMutableTreeNode> children = getChildren(node); for (DefaultMutableTreeNode child : children) { incrementVersions(child); } }
From source file:org.kuali.maven.plugins.externals.MojoHelper.java
public String getDisplayString(DefaultMutableTreeNode node, File basedir, String pomFile) { Project project = (Project) node.getUserObject(); File pom = project.getPom();//from ww w.ja v a 2 s . c om String pomPath = pom.getAbsolutePath(); String displayPath = pomPath.replace(basedir.getAbsolutePath(), ""); displayPath = displayPath.replace(pomFile, ""); if (!node.isRoot()) { displayPath = displayPath.substring(0, displayPath.length() - 1); int pos = displayPath.lastIndexOf(File.separator); displayPath = displayPath.substring(pos); displayPath = displayPath.replace("/", ""); } int level = node.getLevel(); StringBuilder sb = new StringBuilder(); sb.append(StringUtils.repeat(" ", level)); sb.append(displayPath); sb.append("\n"); Enumeration<?> children = node.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); sb.append(getDisplayString(child, basedir, pomFile)); } return sb.toString(); }
From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java
/** * Constructor.//from w w w .j a v a2s . c om */ private TrashJPanel() { treeNodeToResourceUriMap = new HashMap(); rootNode = new DefaultMutableTreeNode(Messages.getString("TrashJPanel.notebookArchive")); treeModel = new DefaultTreeModel(rootNode); treeModel.addTreeModelListener(new MyTreeModelListener()); tree = new JTree(treeModel); tree.setEditable(false); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addTreeExpansionListener(this); tree.addTreeWillExpandListener(this); tree.setShowsRootHandles(true); tree.putClientProperty("JTree.lineStyle", "Angled"); // tree rendered // TODO implement own renderer in order to tooltips tree.setCellRenderer(new TrashTreeCellRenderer(IconsRegistry.getImageIcon("trashFull.png"), IconsRegistry.getImageIcon("explorerNotebookIcon.png"))); setLayout(new BorderLayout()); // control panel JToolBar tp = new JToolBar(); tp.setLayout(new GridLayout(1, 6)); undoButton = new JButton("", IconsRegistry.getImageIcon("trashUndo.png")); undoButton.setEnabled(false); undoButton.setToolTipText("Restore Outline"); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return; } new RestoreNotebookJDialog((String) treeNodeToResourceUriMap.get(node), "Restore Outline", "Restore", true); } }); tp.add(undoButton); deleteButton = new JButton("", IconsRegistry.getImageIcon("explorerDeleteSmall.png")); deleteButton.setToolTipText("Delete Outline"); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return; } int result = JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Do you really want to DELETE this Outline?", "Delete Outline", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { MindRaider.labelCustodian.deleteOutline((String) treeNodeToResourceUriMap.get(node)); refresh(); ExplorerJPanel.getInstance().refresh(); } } }); tp.add(deleteButton); emptyButton = new JButton("", IconsRegistry.getImageIcon("trashEmpty.png")); emptyButton.setToolTipText(Messages.getString("TrashJPanel.emptyArchive")); emptyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Do you really want to DELETE all discarded Outlines?", "Empty Trash", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { final SwingWorker worker = new SwingWorker() { public Object construct() { ProgressDialogJFrame progressDialogJFrame = new ProgressDialogJFrame("Empty Trash", "<html><br> <b>Deleting:</b> </html>"); try { ResourceDescriptor[] resourceDescriptors = MindRaider.labelCustodian .getDiscardedOutlineDescriptors(); if (resourceDescriptors != null) { for (int i = 0; i < resourceDescriptors.length; i++) { MindRaider.labelCustodian.deleteOutline(resourceDescriptors[i].getUri()); } refresh(); } } finally { if (progressDialogJFrame != null) { progressDialogJFrame.dispose(); } } return null; } }; worker.start(); } } }); tp.add(emptyButton); add(tp, BorderLayout.NORTH); // add the tree JScrollPane scrollPane = new JScrollPane(tree); add(scrollPane); // build the whole tree buildTree(); // click handler tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return; } logger.debug("Tree selection path: " + node.getPath()[node.getLevel()]); enableDisableToolbarButtons(node.getLevel()); } }); }