List of usage examples for javax.swing.tree TreePath getLastPathComponent
public Object getLastPathComponent()
From source file:org.robotframework.swing.tree.TreeOperator.java
public boolean isLeaf(TreePath nodeIdentifier) { TreeNode lastPathComponent = (TreeNode) nodeIdentifier.getLastPathComponent(); return lastPathComponent.isLeaf(); }
From source file:org.robotframework.swing.tree.TreeOperator.java
public String getTreeNodeLabel(int index) { TreePath pathForRow = jTreeOperator.getPathForRow(index); return pathForRow.getLastPathComponent().toString(); }
From source file:org.sintef.thingml.FilePanel.java
public FilePanel(final ThingMLPanel editor, final ThingMLFrame frame, File rootF) { this.setLayout(new BorderLayout()); add(new JScrollPane(tree), BorderLayout.CENTER); File root = rootF;// w w w . ja va2 s . c o m if (root == null) { JFileChooser filechooser = new JFileChooser(); filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); filechooser.setDialogTitle("Select base directory for ThingML files"); File dir = ThingMLSettings.getInstance().get_default_work_dir(); if (dir != null) { filechooser.setSelectedFile(dir); } int returnVal = filechooser.showOpenDialog(null); if (filechooser.getSelectedFile() != null && returnVal == JFileChooser.APPROVE_OPTION) { ThingMLSettings.getInstance().store_default_work_dir(filechooser.getSelectedFile()); root = filechooser.getSelectedFile(); } else { System.exit(0); } } FileFilter fileFilter = new FileFilter() { @Override public boolean accept(File f) { return f.getName().endsWith(".thingml"); } }; final File root2 = root; try { simpleFileManager = new SimpleFileManager(root, fileFilter); } catch (IOException e) { e.printStackTrace(); } tree.setModel(new DefaultTreeModel(simpleFileManager.getDirectoryTree())); simpleFileManager.startMonitoring(); FileMonitor fileMonitor = simpleFileManager.getFileMonitor(); fileMonitor.addClient(this); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getNewLeadSelectionPath(); String file = path.getLastPathComponent().toString(); while (path.getParentPath() != null) { path = path.getParentPath(); file = path.getLastPathComponent() + "/" + file; } if (file.indexOf("/") > -1) { File fileF = new File(root2 + "/" + file.substring(file.indexOf("/"))); if (fileF.isFile()) { try { final InputStream input = new FileInputStream(fileF.getAbsolutePath()); final java.util.List<String> packLines = IOUtils.readLines(input); String content = ""; for (String line : packLines) { content += line + "\n"; } input.close(); editor.loadText(content, fileF); frame.setTitle("ThingML Editor : " + e.getNewLeadSelectionPath().getLastPathComponent().toString()); } catch (Exception ex) { ex.printStackTrace(); } } } } }); }
From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java
/** * Go through the ruleSet and populate the JList * * @param ruleToBeSelected The path to the rule that should be selected * after populating the tree *//*from w w w . jav a 2s .co m*/ void populateRuleTree(String ruleToBeSelected) { TreePath ttt = new TreePath(rootNode); Enumeration<TreePath> expandedDescendants = trRuleList.getExpandedDescendants(ttt); expandedNodes = (expandedDescendants == null ? new ArrayList<>() : Collections.list(expandedDescendants)); if (rootNode != null) { rootNode.removeAllChildren(); } for (Rule rule : exportRuleSet.getRules().values()) { String ruleName = rule.getName(); DefaultMutableTreeNode ruleNode = new DefaultMutableTreeNode( new Item(ruleName, ROOTNODE, ItemType.RULE)); rootNode.add(ruleNode); FileMIMETypeCondition fileMIMETypeCondition = rule.getFileMIMETypeCondition(); if (fileMIMETypeCondition != null) { ruleNode.add( new DefaultMutableTreeNode(new Item("MIME Type", ruleName, ItemType.MIME_TYPE_CLAUSE))); } List<FileSizeCondition> fileSizeConditions = rule.getFileSizeConditions(); for (FileSizeCondition fsc : fileSizeConditions) { ruleNode.add(new DefaultMutableTreeNode(new Item("File Size", ruleName, ItemType.SIZE_CLAUSE))); } for (Rule.ArtifactCondition artifact : rule.getArtifactConditions()) { DefaultMutableTreeNode clauseNode = new DefaultMutableTreeNode( new Item(artifact.getTreeDisplayName(), ruleName, ItemType.ARTIFACT_CLAUSE)); ruleNode.add(clauseNode); } } ((DefaultTreeModel) trRuleList.getModel()).reload(); // Re-expand any rules that were open previously and that still exist for (TreePath e : expandedNodes) { TreePath treePath = findTreePathByRuleName(e.getLastPathComponent().toString()); trRuleList.expandPath(treePath); } expandedNodes.clear(); // select the rule to leave the cursor in a logical place if (ruleToBeSelected != null) { TreePath treePath = findTreePathByRuleName(ruleToBeSelected); treeSelectionModel.setSelectionPath(treePath); trRuleList.expandPath(treePath); } }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTree() { treeModel = new DefaultTreeModel(null); tree = new JTree(treeModel); tree.setCellRenderer(new ComponentTreeCellRenderer()); // popup menu tree.addMouseListener(new PopupListener() { @Override//from w ww . j av a2 s. c om public void showPopup(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); DefaultMutableTreeNode node = (path == null) ? null : (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == null) return; // ensure we select the node... tree.setSelectionPath(path); // get the element Element element = (Element) node.getUserObject(); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this); popup.show(tree, e.getX(), e.getY()); } }); ToolTipManager.sharedInstance().setInitialDelay(0); tree.setToolTipText(""); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTree() { treeModel = new DefaultTreeModel(null); tree = new JTree(treeModel); tree.setCellRenderer(new ComponentTreeCellRenderer()); // popup menu tree.addMouseListener(new PopupListener() { @Override/*from w ww . j a v a 2 s .com*/ public void showPopup(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); DefaultMutableTreeNode node = (path == null) ? null : (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == null) return; // ensure we select the node... tree.setSelectionPath(path); // get the element Element element = (Element) node.getUserObject(); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this); popup.show(tree, e.getX(), e.getY()); } }); ToolTipManager.sharedInstance().setInitialDelay(0); tree.setToolTipText(""); }
From source file:org.wings.STree.java
/** * Returns the last path component in the first node of the current * selection.// w w w . ja v a 2s.c o m * * @return the last Object in the first selected node's TreePath, * or null if nothing is selected * @see TreePath#getLastPathComponent */ public Object getLastSelectedPathComponent() { Object obj = null; TreePath selPath = getSelectionModel().getSelectionPath(); if (selPath != null) { obj = selPath.getLastPathComponent(); } return obj; }
From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java
private boolean deleteSelectedTreeTableRow(org.jdesktop.swingx.JXTreeTable treeTable) { final AbstractPortfolioTreeTableModelEx portfolioTreeTableModel = (AbstractPortfolioTreeTableModelEx) treeTable .getTreeTableModel();// www.j a va2 s. c o m final TreePath[] treePaths = treeTable.getTreeSelectionModel().getSelectionPaths(); if (treePaths == null) { return false; } boolean atLeastOnce = false; for (TreePath treePath : treePaths) { final Object o = treePath.getLastPathComponent(); if (portfolioTreeTableModel.getRoot() == o) { continue; } final MutableTreeTableNode mutableTreeTableNode = (MutableTreeTableNode) o; if (isValidTreeTableNode(portfolioTreeTableModel, mutableTreeTableNode) == false) { //??? portfolioTreeTableModel.fireTreeTableNodeChanged(mutableTreeTableNode); continue; } if (o instanceof Transaction) { portfolioTreeTableModel.removeTransaction((Transaction) o); atLeastOnce = true; } else if (o instanceof TransactionSummary) { portfolioTreeTableModel.removeTransactionSummary((TransactionSummary) o); atLeastOnce = true; } } return atLeastOnce; }
From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java
private List<Transaction> getSelectedTransactions(JXTreeTable treeTable) { final TreePath[] treePaths = treeTable.getTreeSelectionModel().getSelectionPaths(); List<Transaction> transactions = new ArrayList<Transaction>(); if (treePaths == null) { return Collections.unmodifiableList(transactions); }/*w w w. ja v a 2 s . co m*/ for (TreePath treePath : treePaths) { final Object o = treePath.getLastPathComponent(); if (o instanceof Transaction) { final Transaction transaction = (Transaction) o; if (transactions.contains(transaction) == false) { transactions.add(transaction); } } else if (o instanceof TransactionSummary) { final TransactionSummary transactionSummary = (TransactionSummary) o; final int count = transactionSummary.getChildCount(); for (int i = 0; i < count; i++) { final Transaction transaction = (Transaction) transactionSummary.getChildAt(i); if (transactions.contains(transaction) == false) { transactions.add(transaction); } } } } return Collections.unmodifiableList(transactions); }
From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java
private List<Stock> getSelectedStocks(JXTreeTable treeTable) { final TreePath[] treePaths = treeTable.getTreeSelectionModel().getSelectionPaths(); List<Stock> stocks = new ArrayList<Stock>(); Set<Code> c = new HashSet<Code>(); if (treePaths == null) { return Collections.unmodifiableList(stocks); }/*from ww w . j a va 2 s .c o m*/ for (TreePath treePath : treePaths) { final Object lastPathComponent = treePath.getLastPathComponent(); if (lastPathComponent instanceof TransactionSummary) { final TransactionSummary transactionSummary = (TransactionSummary) lastPathComponent; assert (transactionSummary.getChildCount() > 0); final Transaction transaction = (Transaction) transactionSummary.getChildAt(0); final Stock stock = transaction.getStock(); final Code code = stock.code; if (c.contains(code)) continue; stocks.add(stock); c.add(code); } else if (lastPathComponent instanceof Transaction) { final Transaction transaction = (Transaction) lastPathComponent; final Stock stock = transaction.getStock(); final Code code = stock.code; if (c.contains(code)) continue; stocks.add(stock); c.add(code); } } return Collections.unmodifiableList(stocks); }