List of usage examples for javax.swing.tree DefaultMutableTreeNode getParent
public TreeNode getParent()
From source file:gui.GraphsPanel.java
/** TODO: re-implement the algorithm from vertexColor. * Vertice Coloring algorithm executed before the vertexColor Transformer is * called/*from w w w . j av a 2s .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:gui.GraphsPanel.java
/** detectWeakEdges(). * /* w ww . j a va 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:Main.java
public Main() { DefaultMutableTreeNode forums = new DefaultMutableTreeNode("B"); forums.add(new DefaultMutableTreeNode("T")); DefaultMutableTreeNode articles = new DefaultMutableTreeNode("A"); articles.add(new DefaultMutableTreeNode("A")); DefaultMutableTreeNode examples = new DefaultMutableTreeNode("E"); examples.add(new DefaultMutableTreeNode("E")); rootNode.add(forums);/*from w w w . ja v a 2s. c om*/ rootNode.add(articles); rootNode.add(examples); m_tree.setEditable(true); m_tree.setSelectionRow(0); JScrollPane scrollPane = new JScrollPane(m_tree); getContentPane().add(scrollPane, BorderLayout.CENTER); JPanel panel = new JPanel(); m_addButton = new JButton("Add Node"); m_addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent(); if (selNode == null) { return; } DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New"); m_model.insertNodeInto(newNode, selNode, selNode.getChildCount()); TreeNode[] nodes = m_model.getPathToRoot(newNode); TreePath path = new TreePath(nodes); m_tree.scrollPathToVisible(path); m_tree.setSelectionPath(path); m_tree.startEditingAtPath(path); } }); panel.add(m_addButton); getContentPane().add(panel, BorderLayout.SOUTH); m_delButton = new JButton("Delete Node"); m_delButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent(); if (selNode == null) { return; } MutableTreeNode parent = (MutableTreeNode) (selNode.getParent()); if (parent == null) { return; } MutableTreeNode toBeSelNode = (MutableTreeNode) selNode.getPreviousSibling(); if (toBeSelNode == null) { toBeSelNode = (MutableTreeNode) selNode.getNextSibling(); } if (toBeSelNode == null) { toBeSelNode = parent; } TreeNode[] nodes = m_model.getPathToRoot(toBeSelNode); TreePath path = new TreePath(nodes); m_tree.scrollPathToVisible(path); m_tree.setSelectionPath(path); m_model.removeNodeFromParent(selNode); } }); panel.add(m_delButton); getContentPane().add(panel, BorderLayout.SOUTH); setSize(300, 400); setVisible(true); }
From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java
/** * Discard concept.//from w w w .j a v a2 s . c o m */ public void conceptDiscard() { if (MindRaider.profile.getActiveOutlineUri() == null) { JOptionPane.showMessageDialog(OutlineJPanel.this, Messages.getString("NotebookOutlineJPanel.toDiscardConceptTheNotebookMustBeOpened"), Messages.getString("NotebookOutlineJPanel.discardConceptError"), JOptionPane.ERROR_MESSAGE); return; } // move concept up in the tree DefaultMutableTreeNode node = getSelectedTreeNode(); if (node != null) { if (node.isLeaf() && node.getParent() != null) { try { if (JOptionPane.showConfirmDialog(MindRaider.mainJFrame, Messages.getString("NotebookOutlineJPanel.doYouWantToDiscardConcept", node.toString()), Messages.getString("NotebookOutlineJPanel.discardConcept"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { return; } DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); String notebookUri = MindRaider.outlineCustodian.getActiveOutlineResource().resource .getMetadata().getUri().toString(); MindRaider.noteCustodian.discard(notebookUri, ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri()); refresh(); MindRaider.spidersGraph.selectNodeByUri(notebookUri); MindRaider.spidersGraph.renderModel(); conceptJPanel.clear(); } catch (Exception e1) { logger.debug(Messages.getString("NotebookOutlineJPanel.unableToDiscardConcept"), e1); StatusBar.show(Messages.getString("NotebookOutlineJPanel.unableToDiscardConcept")); } } else { StatusBar.show(Messages.getString("NotebookOutlineJPanel.discardingOnlyLeafConcepts")); JOptionPane.showMessageDialog(OutlineJPanel.this, Messages.getString("NotebookOutlineJPanel.discardingOnlyLeafConcepts"), "Concept Discard Error", JOptionPane.ERROR_MESSAGE); return; } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected")); } }
From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java
/** * Down concept./*from www . ja v a 2 s . c o m*/ */ public boolean conceptDown() { // move concept down in the tree DefaultMutableTreeNode node = getSelectedTreeNode(); if (node != null) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent != null) { DefaultMutableTreeNode nextSibling = node.getNextSibling(); if (nextSibling != null) { if (MindRaider.noteCustodian.down(MindRaider.outlineCustodian.getActiveOutlineResource(), ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri())) { int siblingIndex = parent.getIndex(nextSibling); parent.remove(node); parent.insert(node, siblingIndex); treeTable.updateUI(); logger.debug("Node moved down!"); return true; } // else node the last in the sequence } else { logger.debug("No sibling!"); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noParent")); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected")); } return false; }
From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java
/** * Demote concept./*from w ww . ja v a2 s. co m*/ */ public void conceptDemote() { // current node becomes the first child of the previous sibling, if node // has index 0, then do nothing DefaultMutableTreeNode node = getSelectedTreeNode(); if (node != null) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent != null) { DefaultMutableTreeNode previous = (DefaultMutableTreeNode) parent.getChildBefore(node); if (previous != null) { parent.remove(node); previous.insert(node, previous.getChildCount()); treeTable.updateUI(); logger.debug(Messages.getString("NotebookOutlineJPanel.conceptDemoted")); MindRaider.noteCustodian.demote(MindRaider.outlineCustodian.getActiveOutlineResource(), ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri()); setSelectedTreeNodeConcept(((OutlineNode) node).getUri()); } else { logger.debug(Messages.getString("NotebookOutlineJPanel.isTheFirstChild")); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noParent")); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected!")); } }
From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java
/** * Promote concept./*from ww w.jav a 2 s . co m*/ */ public void conceptPromote() { // imagine the row and move it to the level up (left) in this row // node must be stored as parent's parent DefaultMutableTreeNode node = getSelectedTreeNode(); if (node != null) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent != null) { DefaultMutableTreeNode pparent = (DefaultMutableTreeNode) parent.getParent(); if (pparent != null) { // now put it right behind previous parent int parentIndex = pparent.getIndex(parent); parent.remove(node); pparent.insert(node, parentIndex + 1); treeTable.updateUI(); logger.debug(Messages.getString("NotebookOutlineJPanel.noNodePromoted")); MindRaider.noteCustodian.promote(MindRaider.outlineCustodian.getActiveOutlineResource(), ((OutlineNode) pparent).getUri(), ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri()); } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noParentsParent")); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noParent")); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected")); } }
From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java
/** * Up concept.//from w ww . j a v a2s . c o m */ public boolean conceptUp() { // move concept up in the tree DefaultMutableTreeNode node = getSelectedTreeNode(); if (node != null) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent != null) { DefaultMutableTreeNode previousSibling = node.getPreviousSibling(); if (previousSibling != null) { // move it up in the model if (MindRaider.noteCustodian.up(MindRaider.outlineCustodian.getActiveOutlineResource(), ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri())) { int siblingIndex = parent.getIndex(previousSibling); parent.remove(node); parent.insert(node, siblingIndex); treeTable.updateUI(); logger.debug(Messages.getString("NotebookOutlineJPanel.noMovedUp")); return true; } // else it is the first concept in the sequence } else { logger.debug("No sibling!"); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noParent")); } } else { logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected")); } return false; }
From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java
/** * Creates a list of {@link File}s for all leaf nodes in the tree structure * <code>node</code>, which have been marked as <i>selected</i>. <br> * <br>/*from www .j av a2 s .co m*/ * <code>Selected</code> nodes correspond to those entries in the tree, * whose checkbox is <code>checked</code>. * * SIDE EFFECT: The checked nodes are removed from the tree. * * @param node * The root node representing a tree structure. * @return A list of files of all checked leaf nodes. */ private List<File> getFileListFromNode(CheckableTreeNode node) { List<File> filesList = new ArrayList<>(); Enumeration<CheckableTreeNode> children = node.depthFirstEnumeration(); List<CheckableTreeNode> nodesToRemove = new ArrayList<>(); for (CheckableTreeNode child : Collections.list(children)) { if (child.isLeaf() && child.isSelected()) { File nodeFile = ((FileNodeWrapper) child.getUserObject()).file; if ((nodeFile != null) && nodeFile.isFile()) { filesList.add(nodeFile); nodesToRemove.add(child); } } } // remove imported files from tree DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); for (CheckableTreeNode nodeToRemove : nodesToRemove) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) nodeToRemove.getParent(); model.removeNodeFromParent(nodeToRemove); // remove empty parent node while ((parent != null) && parent.isLeaf()) { DefaultMutableTreeNode pp = (DefaultMutableTreeNode) parent.getParent(); if (pp != null) { model.removeNodeFromParent(parent); } parent = pp; } // TODO: update counter / see: getTreeCellRendererComponent for label generation } tree.invalidate(); tree.repaint(); return filesList; }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
/** * Deletes a ForRow or a FormCell./*w ww .j a v a2 s .com*/ */ protected void delControl(final TYPE type) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getSelectionModel().getSelectionPath() .getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent(); Object formObj = selectedNode.getUserObject(); // For when we select delete row Menu when on a Control if (type == TYPE.DelRow && formObj instanceof FormCell) { selectedNode = parentNode; parentNode = (DefaultMutableTreeNode) parentNode.getParent(); formObj = selectedNode.getUserObject(); } if (formObj instanceof FormRow) { FormRow row = (FormRow) formObj; ((FormViewDef) parentNode.getUserObject()).getRows().remove(row); for (FormCellIFace formCell : row.getCells()) { idHash.remove(formCell.getIdent()); } } else if (formObj instanceof FormCell) { FormCell formCell = (FormCell) formObj; ((FormRow) parentNode.getUserObject()).getCells().remove(formCell); idHash.remove(formCell.getIdent()); } renumberRows(formViewDef.getRows()); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.removeNodeFromParent(selectedNode); }