📄 jtree.java
字号:
while (isVisible(temp)) if (i < oPath.length) temp = temp.pathByAddingChild(oPath[i++]); else { stop = true; break; } makeVisible(temp); } Rectangle rect = getPathBounds(path); scrollRectToVisible(rect); revalidate(); repaint(); } public void scrollRowToVisible(int row) { scrollPathToVisible(getPathForRow(row)); } public boolean getScrollsOnExpand() { return scrollsOnExpand; } public void setScrollsOnExpand(boolean scroll) { if (scrollsOnExpand == scroll) return; boolean oldValue = scrollsOnExpand; scrollsOnExpand = scroll; firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, scroll); } public void setSelectionPath(TreePath path) { selectionModel.setSelectionPath(path); } public void setSelectionPaths(TreePath[] paths) { selectionModel.setSelectionPaths(paths); } public void setSelectionRow(int row) { TreePath path = getPathForRow(row); if (path != null) selectionModel.setSelectionPath(path); } public void setSelectionRows(int[] rows) { // Make sure we have an UI so getPathForRow() does not return null. if (rows == null || getUI() == null) return; TreePath[] paths = new TreePath[rows.length]; for (int i = rows.length - 1; i >= 0; --i) paths[i] = getPathForRow(rows[i]); setSelectionPaths(paths); } public void setSelectionInterval(int index0, int index1) { TreePath[] paths = getPathBetweenRows(index0, index1); if (paths != null) setSelectionPaths(paths); } public void addSelectionPath(TreePath path) { selectionModel.addSelectionPath(path); } public void addSelectionPaths(TreePath[] paths) { selectionModel.addSelectionPaths(paths); } public void addSelectionRow(int row) { TreePath path = getPathForRow(row); if (path != null) selectionModel.addSelectionPath(path); } public void addSelectionRows(int[] rows) { // Make sure we have an UI so getPathForRow() does not return null. if (rows == null || getUI() == null) return; TreePath[] paths = new TreePath[rows.length]; for (int i = rows.length - 1; i >= 0; --i) paths[i] = getPathForRow(rows[i]); addSelectionPaths(paths); } public void addSelectionInterval(int index0, int index1) { TreePath[] paths = getPathBetweenRows(index0, index1); if (paths != null) addSelectionPaths(paths); } public void removeSelectionPath(TreePath path) { selectionModel.removeSelectionPath(path); } public void removeSelectionPaths(TreePath[] paths) { selectionModel.removeSelectionPaths(paths); } public void removeSelectionRow(int row) { TreePath path = getPathForRow(row); if (path != null) selectionModel.removeSelectionPath(path); } public void removeSelectionRows(int[] rows) { if (rows == null || getUI() == null) return; TreePath[] paths = new TreePath[rows.length]; for (int i = rows.length - 1; i >= 0; --i) paths[i] = getPathForRow(rows[i]); removeSelectionPaths(paths); } public void removeSelectionInterval(int index0, int index1) { TreePath[] paths = getPathBetweenRows(index0, index1); if (paths != null) removeSelectionPaths(paths); } public void clearSelection() { selectionModel.clearSelection(); setLeadSelectionPath(null); } 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.isPathSelected(getPathForRow(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) { try { fireTreeWillCollapse(path); } catch (ExpandVetoException ev) { // We do nothing if attempt has been vetoed. } setExpandedState(path, false); fireTreeCollapsed(path); } 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 path is null if (path == null) return; try { fireTreeWillExpand(path); } catch (ExpandVetoException ev) { // We do nothing if attempt has been vetoed. } setExpandedState(path, true); fireTreeExpanded(path); } 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 (isEditing()) if (ui != null) return ui.stopEditing(this); return false; } public void cancelEditing() { TreeUI ui = getUI(); if (isEditing()) 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -