📄 jtree.java
字号:
removeSelectionPaths(paths); } public void clearSelection() { selectionModel.clearSelection(); } public TreePath getLeadSelectionPath() { return leadSelectionPath; } /** * @since 1.3 */ public void setLeadSelectionPath(TreePath path) { if (leadSelectionPath == path) return; TreePath oldValue = leadSelectionPath; leadSelectionPath = path; firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, path); } /** * @since 1.3 */ public TreePath getAnchorSelectionPath() { return anchorSelectionPath; } /** * @since 1.3 */ public void setAnchorSelectionPath(TreePath path) { if (anchorSelectionPath == path) return; TreePath oldValue = anchorSelectionPath; anchorSelectionPath = path; firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, path); } public int getLeadSelectionRow() { return selectionModel.getLeadSelectionRow(); } public int getMaxSelectionRow() { return selectionModel.getMaxSelectionRow(); } public int getMinSelectionRow() { return selectionModel.getMinSelectionRow(); } public int getSelectionCount() { return selectionModel.getSelectionCount(); } public TreePath getSelectionPath() { return selectionModel.getSelectionPath(); } public TreePath[] getSelectionPaths() { return selectionModel.getSelectionPaths(); } public int[] getSelectionRows() { return selectionModel.getSelectionRows(); } public boolean isPathSelected(TreePath path) { return selectionModel.isPathSelected(path); } public boolean isRowSelected(int row) { return selectionModel.isRowSelected(row); } public boolean isSelectionEmpty() { return selectionModel.isSelectionEmpty(); } /** * Return the value of the <code>dragEnabled</code> property. * * @return the value * * @since 1.4 */ public boolean getDragEnabled() { return dragEnabled; } /** * Set the <code>dragEnabled</code> property. * * @param enabled new value * * @since 1.4 */ public void setDragEnabled(boolean enabled) { dragEnabled = enabled; } public int getRowCount() { TreeUI ui = getUI(); if (ui != null) return ui.getRowCount(this); return 0; } public void collapsePath(TreePath path) { setExpandedState(path, false); } public void collapseRow(int row) { if (row < 0 || row >= getRowCount()) return; TreePath path = getPathForRow(row); if (path != null) collapsePath(path); } public void expandPath(TreePath path) { // Don't expand if last path component is a leaf node. if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent()))) return; setExpandedState(path, true); } public void expandRow(int row) { if (row < 0 || row >= getRowCount()) return; TreePath path = getPathForRow(row); if (path != null) expandPath(path); } public boolean isCollapsed(TreePath path) { return ! isExpanded(path); } public boolean isCollapsed(int row) { if (row < 0 || row >= getRowCount()) return false; TreePath path = getPathForRow(row); if (path != null) return isCollapsed(path); return false; } public boolean isExpanded(TreePath path) { if (path == null) return false; Object state = nodeStates.get(path); if ((state == null) || (state != EXPANDED)) return false; TreePath parent = path.getParentPath(); if (parent != null) return isExpanded(parent); return true; } public boolean isExpanded(int row) { if (row < 0 || row >= getRowCount()) return false; TreePath path = getPathForRow(row); if (path != null) return isExpanded(path); return false; } /** * @since 1.3 */ public boolean getExpandsSelectedPaths() { return expandsSelectedPaths; } /** * @since 1.3 */ public void setExpandsSelectedPaths(boolean flag) { if (expandsSelectedPaths == flag) return; boolean oldValue = expandsSelectedPaths; expandsSelectedPaths = flag; firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue, flag); } public Rectangle getPathBounds(TreePath path) { TreeUI ui = getUI(); if (ui == null) return null; return ui.getPathBounds(this, path); } public Rectangle getRowBounds(int row) { TreePath path = getPathForRow(row); if (path != null) return getPathBounds(path); return null; } public boolean isEditing() { TreeUI ui = getUI(); if (ui != null) return ui.isEditing(this); return false; } public boolean stopEditing() { TreeUI ui = getUI(); if (ui != null) return ui.stopEditing(this); return false; } public void cancelEditing() { TreeUI ui = getUI(); if (ui != null) ui.cancelEditing(this); } public void startEditingAtPath(TreePath path) { TreeUI ui = getUI(); if (ui != null) ui.startEditingAtPath(this, path); } public TreePath getEditingPath() { TreeUI ui = getUI(); if (ui != null) return ui.getEditingPath(this); return null; } public TreePath getPathForLocation(int x, int y) { TreePath path = getClosestPathForLocation(x, y); if (path != null) { Rectangle rect = getPathBounds(path); if ((rect != null) && rect.contains(x, y)) return path; } return null; } public int getRowForLocation(int x, int y) { TreePath path = getPathForLocation(x, y); if (path != null) return getRowForPath(path); return -1; } public TreePath getClosestPathForLocation(int x, int y) { TreeUI ui = getUI(); if (ui != null) return ui.getClosestPathForLocation(this, x, y); return null; } public int getClosestRowForLocation(int x, int y) { TreePath path = getClosestPathForLocation(x, y); if (path != null) return getRowForPath(path); return -1; } public Object getLastSelectedPathComponent() { TreePath path = getSelectionPath(); if (path != null) return path.getLastPathComponent(); return null; } private void checkExpandParents(TreePath path) throws ExpandVetoException { TreePath parent = path.getParentPath(); if (parent != null) checkExpandParents(parent); fireTreeWillExpand(path); } private void doExpandParents(TreePath path, boolean state) { TreePath parent = path.getParentPath(); if (isExpanded(parent)) return; if (parent != null) doExpandParents(parent, false); nodeStates.put(path, state ? EXPANDED : COLLAPSED); } protected void setExpandedState(TreePath path, boolean state) { if (path == null) return; TreePath parent = path.getParentPath(); try { while (parent != null) checkExpandParents(parent); } catch (ExpandVetoException e) { // Expansion vetoed. return; } doExpandParents(path, state); } protected void clearToggledPaths() { nodeStates.clear(); } protected Enumeration getDescendantToggledPaths(TreePath parent) { if (parent == null) return null; Enumeration nodes = nodeStates.keys(); Vector result = new Vector(); while (nodes.hasMoreElements()) { TreePath path = (TreePath) nodes.nextElement(); if (path.isDescendant(parent)) result.addElement(path); } return result.elements(); } public boolean hasBeenExpanded(TreePath path) { if (path == null) return false; return nodeStates.get(path) != null; } public boolean isVisible(TreePath path) { if (path == null) return false; TreePath parent = path.getParentPath(); if (parent == null) return true; // Is root node. return isExpanded(parent); } public void makeVisible(TreePath path) { if (path == null) return; expandPath(path.getParentPath()); } public boolean isPathEditable(TreePath path) { return isEditable(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -