List of usage examples for javax.swing.tree TreePath getParentPath
public TreePath getParentPath()
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 .j av a2s . com 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.wings.STree.java
public boolean isVisible(TreePath path) { if (path != null) { TreePath parentPath = path.getParentPath(); if (parentPath != null) return isExpanded(parentPath); // Root./*from w ww. j av a 2s .c o m*/ return true; } return false; }
From source file:pcgen.gui2.tabs.spells.SpellBooksTab.java
/** * Identify the current spell book, being the spell book that spells should * be added to. If no books exist then return an empty string. * * @return The name of the 'current' spell book, or empty string if none * exist./*from ww w . j ava 2 s .c o m*/ */ String getCurrentSpellBookName() { String spellList = ""; Object selectedObject = selectedTable.getSelectedObject(); if (selectedObject != null) { if (selectedObject instanceof SpellNode) { spellList = ((SpellNode) selectedObject).getRootNode().getName(); } else if (selectedObject instanceof RootNode) { spellList = ((RootNode) selectedObject).getName(); } else { JTree tree = selectedTable.getTree(); TreePath path = tree.getSelectionPath(); while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) { path = path.getParentPath(); } spellList = path.getLastPathComponent().toString(); } } if (StringUtils.isEmpty(spellList)) { ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel(); if (!data.isEmpty()) { Object firstElem = data.getElementAt(0); if (firstElem instanceof SpellNode) { spellList = ((SpellNode) firstElem).getRootNode().getName(); } } } return spellList; }
From source file:pcgen.gui2.tabs.spells.SpellsPreparedTab.java
/** * Identify the current spell list, being the spell list that spell should * be added to. If no lists exist then a default one will be created. * * @param character The character qwe are checking for. * @return The name of the 'current' spell list. *///from w w w. ja v a2s. co m String getCurrentSpellListName(CharacterFacade character) { String spellList = ""; Object selectedObject = selectedTable.getSelectedObject(); if (selectedObject != null) { if (selectedObject instanceof SpellNode) { spellList = ((SpellNode) selectedObject).getRootNode().toString(); } else { JTree tree = selectedTable.getTree(); TreePath path = tree.getSelectionPath(); while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) { path = path.getParentPath(); } spellList = path.getLastPathComponent().toString(); } } if (StringUtils.isEmpty(spellList)) { spellList = spellListField.getText(); } if (StringUtils.isEmpty(spellList)) { ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel(); if (!data.isEmpty()) { Object firstElem = data.getElementAt(0); if (firstElem instanceof SpellNode) { spellList = ((SpellNode) firstElem).getRootNode().toString(); } } } if (StringUtils.isEmpty(spellList)) { // No lists exist, so create a default one! spellList = "Prepared Spells"; character.getSpellSupport().addSpellList(spellList); } return spellList; }