List of usage examples for javax.swing.tree TreePath getParentPath
public TreePath getParentPath()
From source file:com.nbt.TreeFrame.java
protected void updateActions() { Map<Integer, Action> actionMap = new LinkedHashMap<Integer, Action>(); actionMap.put(NBTConstants.TYPE_BYTE, addByteAction); actionMap.put(NBTConstants.TYPE_SHORT, addShortAction); actionMap.put(NBTConstants.TYPE_INT, addIntAction); actionMap.put(NBTConstants.TYPE_LONG, addLongAction); actionMap.put(NBTConstants.TYPE_FLOAT, addFloatAction); actionMap.put(NBTConstants.TYPE_DOUBLE, addDoubleAction); actionMap.put(NBTConstants.TYPE_BYTE_ARRAY, addByteArrayAction); actionMap.put(NBTConstants.TYPE_STRING, addStringAction); actionMap.put(NBTConstants.TYPE_LIST, addListAction); actionMap.put(NBTConstants.TYPE_COMPOUND, addCompoundAction); for (Action action : actionMap.values()) action.setEnabled(false);/*w w w . j a v a2 s . c o m*/ Action[] actions = { openAction }; for (Action action : actions) action.setEnabled(false); if (treeTable == null) return; int row = treeTable.getSelectedRow(); deleteAction.setEnabled(row > 0); if (row == -1) return; TreePath path = treeTable.getPathForRow(row); Object last = path.getLastPathComponent(); TreePath parentPath = path.getParentPath(); Object parentLast = parentPath == null ? null : parentPath.getLastPathComponent(); if (last instanceof ByteArrayTag || parentLast instanceof ByteArrayTag || last instanceof ByteWrapper || parentLast instanceof ByteWrapper) { addByteAction.setEnabled(true); } else if (last instanceof ListTag || parentLast instanceof ListTag) { if (!(last instanceof ListTag)) last = parentLast; ListTag list = (ListTag) last; @SuppressWarnings("unchecked") Class<Tag<?>> c = (Class<Tag<?>>) list.getType(); int type = NBTUtils.getTypeCode(c); Action action = actionMap.get(type); action.setEnabled(true); } else if (last instanceof CompoundTag || parentLast instanceof CompoundTag || last instanceof TagWrapper || parentLast instanceof TagWrapper) { for (Action action : actionMap.values()) action.setEnabled(true); } else if (last instanceof Region || last instanceof World || last instanceof NBTFileBranch) { openAction.setEnabled(true); } }
From source file:com.jvms.i18neditor.editor.Editor.java
private void setupGlobalKeyEventDispatcher() { KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(e -> { if (e.getID() != KeyEvent.KEY_PRESSED || !e.isAltDown() || (SystemUtils.IS_OS_MAC && !e.isMetaDown()) || (!SystemUtils.IS_OS_MAC && !e.isShiftDown())) { return false; }// w ww. ja v a 2 s . com TreePath selected = translationTree.getSelectionPath(); if (selected == null) { return false; } boolean result = false; int row = translationTree.getRowForPath(selected); switch (e.getKeyCode()) { case KeyEvent.VK_RIGHT: if (!translationTree.isExpanded(row)) { translationTree.expandRow(row); } result = true; break; case KeyEvent.VK_LEFT: if (translationTree.isCollapsed(row)) { translationTree.setSelectionPath(selected.getParentPath()); } else { translationTree.collapseRow(row); } result = true; break; case KeyEvent.VK_UP: TreePath prev = translationTree.getPathForRow(Math.max(0, row - 1)); if (prev != null) { translationTree.setSelectionPath(prev); } result = true; break; case KeyEvent.VK_DOWN: TreePath next = translationTree.getPathForRow(row + 1); if (next != null) { translationTree.setSelectionPath(next); } result = true; break; } if (result && !resourceFields.isEmpty()) { Component comp = getFocusOwner(); if (comp != null && (comp instanceof ResourceField || comp.equals(this))) { TranslationTreeNode current = translationTree.getSelectionNode(); if (!current.isLeaf() || current.isRoot()) { requestFocusInWindow(); } else if (comp.equals(this)) { requestFocusInFirstResourceField(); } } } return result; }); }
From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java
private void expandTree() { List<TreePath> paths = treeModel.getPaths(); for (TreePath path : paths) { if (path.equals(activeLeafPath)) { tree.setSelectionPath(path); tree.scrollPathToVisible(path); }/*from w w w. j a v a 2 s . co m*/ tree.expandPath(path.getParentPath()); } }
From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java
private void expandTreeAndSelect(final LoadProfileEntity selectedItem) { List<TreePath> paths = treeModel.getPaths(); for (TreePath path : paths) { if (path.getLastPathComponent().equals(selectedItem)) { tree.setSelectionPath(path); tree.scrollPathToVisible(path); }/*from w ww .jav a 2s . c o m*/ tree.expandPath(path.getParentPath()); } }
From source file:com.pironet.tda.TDA.java
/** * navigate to root node of currently active dump */// ww w. ja v a 2 s. c o m private void navigateToDump() { TreePath currentPath = tree.getSelectionPath(); tree.setSelectionPath(currentPath.getParentPath()); tree.scrollPathToVisible(currentPath.getParentPath()); }
From source file:com.pironet.tda.TDA.java
/** * navigate to the currently selected dump in logfile *//*ww w .j ava 2s .com*/ private void navigateToDumpInLogfile() { Object userObject = ((DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent()) .getUserObject(); if (userObject instanceof ThreadDumpInfo) { ThreadDumpInfo ti = (ThreadDumpInfo) userObject; int lineNumber = ti.getLogLine(); // find log file node. TreePath selPath = tree.getSelectionPath(); while (selPath != null && !checkNameFromNode((DefaultMutableTreeNode) selPath.getLastPathComponent(), File.separator)) { selPath = selPath.getParentPath(); } tree.setSelectionPath(selPath); tree.scrollPathToVisible(selPath); if (selPath == null) { return; } Enumeration childs = ((DefaultMutableTreeNode) selPath.getLastPathComponent()).children(); boolean found = false; DefaultMutableTreeNode logfileContent = null; while (!found && childs.hasMoreElements()) { logfileContent = (DefaultMutableTreeNode) childs.nextElement(); found = logfileContent.getUserObject() instanceof LogFileContent; } if (found) { TreePath monitorPath = new TreePath(logfileContent.getPath()); tree.setSelectionPath(monitorPath); tree.scrollPathToVisible(monitorPath); displayLogFileContent(logfileContent.getUserObject()); jeditPane.setFirstLine(lineNumber - 1); } } }
From source file:com.pironet.tda.TDA.java
/** * close the currently selected dump.// ww w . j ava 2 s . co m */ private void closeCurrentDump() { TreePath selPath = tree.getSelectionPath(); while (selPath != null && !(checkNameFromNode((DefaultMutableTreeNode) selPath.getLastPathComponent(), File.separator) || checkNameFromNode((DefaultMutableTreeNode) selPath.getLastPathComponent(), 2, File.separator))) { selPath = selPath.getParentPath(); } Object[] options = { "Close File", "Cancel close" }; String fileName = ((DefaultMutableTreeNode) selPath.getLastPathComponent()).getUserObject().toString(); fileName = fileName.substring(fileName.indexOf(File.separator)); int selectValue = JOptionPane.showOptionDialog(null, "<html><body>Are you sure, you want to close the currently selected dump file<br><b>" + fileName + "</b></body></html>", "Confirm closing...", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); // if first option "close file" is selected. if (selectValue == 0) { // remove stuff from the top nodes topNodes.remove(selPath.getLastPathComponent()); if (topNodes.size() == 0) { // simply do a reinit, as there isn't anything to display removeAll(); revalidate(); init(runningAsJConsolePlugin, runningAsVisualVMPlugin); getMainMenu().getLongMenuItem().setEnabled(false); getMainMenu().getCloseMenuItem().setEnabled(false); getMainMenu().getSaveSessionMenuItem().setEnabled(false); getMainMenu().getCloseToolBarButton().setEnabled(false); getMainMenu().getExpandButton().setEnabled(false); getMainMenu().getCollapseButton().setEnabled(false); getMainMenu().getFindLRThreadsToolBarButton().setEnabled(false); getMainMenu().getCloseAllMenuItem().setEnabled(false); getMainMenu().getExpandAllMenuItem().setEnabled(false); getMainMenu().getCollapseAllMenuItem().setEnabled(false); } else { // rebuild jtree getMainMenu().getCloseMenuItem().setEnabled(false); getMainMenu().getCloseToolBarButton().setEnabled(false); createTree(); } revalidate(); } }
From source file:org.apache.pdfbox.debugger.PDFDebugger.java
private void jTree1ValueChanged(TreeSelectionEvent evt) { TreePath path = tree.getSelectionPath(); if (path != null) { try {//from w w w .ja v a 2 s.c om Object selectedNode = path.getLastPathComponent(); statusBar.getStatusLabel().setText(""); if (isPage(selectedNode)) { showPage(selectedNode); return; } if (isSpecialColorSpace(selectedNode) || isOtherColorSpace(selectedNode)) { showColorPane(selectedNode); return; } if (path.getParentPath() != null && isFlagNode(selectedNode, path.getParentPath().getLastPathComponent())) { Object parentNode = path.getParentPath().getLastPathComponent(); showFlagPane(parentNode, selectedNode); return; } if (isStream(selectedNode)) { showStream((COSStream) getUnderneathObject(selectedNode), path); return; } if (isFont(selectedNode)) { showFont(selectedNode, path); return; } if (isString(selectedNode)) { showString(selectedNode); return; } if (jSplitPane1.getRightComponent() == null || !jSplitPane1.getRightComponent().equals(jScrollPane2)) { replaceRightComponent(jScrollPane2); } jTextPane1.setText(convertToString(selectedNode)); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } }
From source file:org.apache.pdfbox.debugger.PDFDebugger.java
private void showStream(COSStream stream, TreePath path) throws IOException { boolean isContentStream = false; boolean isThumb = false; COSName key = getNodeKey(path.getLastPathComponent()); COSName parentKey = getNodeKey(path.getParentPath().getLastPathComponent()); COSDictionary resourcesDic = null;/*from w ww. j a v a 2s . co m*/ if (COSName.CONTENTS.equals(key)) { Object pageObj = path.getParentPath().getLastPathComponent(); COSDictionary page = (COSDictionary) getUnderneathObject(pageObj); resourcesDic = (COSDictionary) page.getDictionaryObject(COSName.RESOURCES); isContentStream = true; } else if (COSName.CONTENTS.equals(parentKey) || COSName.CHAR_PROCS.equals(parentKey)) { Object pageObj = path.getParentPath().getParentPath().getLastPathComponent(); COSDictionary page = (COSDictionary) getUnderneathObject(pageObj); resourcesDic = (COSDictionary) page.getDictionaryObject(COSName.RESOURCES); isContentStream = true; } else if (COSName.FORM.equals(stream.getCOSName(COSName.SUBTYPE)) || COSName.PATTERN.equals(stream.getCOSName(COSName.TYPE)) || stream.getInt(COSName.PATTERN_TYPE) == 1) { if (stream.containsKey(COSName.RESOURCES)) { resourcesDic = (COSDictionary) stream.getDictionaryObject(COSName.RESOURCES); } isContentStream = true; } else if (COSName.THUMB.equals(key)) { resourcesDic = null; isThumb = true; } else if (COSName.IMAGE.equals((stream).getCOSName(COSName.SUBTYPE))) { // not to be used for /Thumb, even if it contains /Subtype /Image Object resourcesObj = path.getParentPath().getParentPath().getLastPathComponent(); resourcesDic = (COSDictionary) getUnderneathObject(resourcesObj); } StreamPane streamPane = new StreamPane(stream, isContentStream, isThumb, resourcesDic); replaceRightComponent(streamPane.getPanel()); }
From source file:org.apache.pdfbox.debugger.PDFDebugger.java
private void showFont(Object selectedNode, TreePath path) { COSName fontName = getNodeKey(selectedNode); COSDictionary resourceDic = (COSDictionary) getUnderneathObject( path.getParentPath().getParentPath().getLastPathComponent()); FontEncodingPaneController fontEncodingPaneController = new FontEncodingPaneController(fontName, resourceDic);/*ww w . j a v a 2s. com*/ JPanel pane = fontEncodingPaneController.getPane(); if (pane == null) { // unsupported font type replaceRightComponent(jScrollPane2); return; } replaceRightComponent(pane); }