📄 jtree.java
字号:
* Return the UI associated with this <code>JTree</code> object. * * @return the associated <code>TreeUI</code> object */ public TreeUI getUI() { return (TreeUI) ui; } /** * Sets the UI associated with this <code>JTree</code> object. * * @param ui the <code>TreeUI</code> to associate */ public void setUI(TreeUI ui) { super.setUI(ui); } /** * This method resets the UI used to the Look and Feel defaults.. */ public void updateUI() { setUI((TreeUI) UIManager.getUI(this)); } /** * This method returns the String ID of the UI class of Separator. * * @return The UI class' String ID. */ public String getUIClassID() { return "TreeUI"; } /** * Gets the AccessibleContext associated with this * <code>JTree</code>. * * @return the associated context */ public AccessibleContext getAccessibleContext() { return new AccessibleJTree(); } /** * Returns the preferred viewport size. * * @return the preferred size */ public Dimension getPreferredScrollableViewportSize() { return new Dimension (getPreferredSize().width, getVisibleRowCount()*getRowHeight()); } /** * Return the preferred scrolling amount (in pixels) for the given scrolling * direction and orientation. This method handles a partially exposed row by * returning the distance required to completely expose the item. * * @param visibleRect the currently visible part of the component. * @param orientation the scrolling orientation * @param direction the scrolling direction (negative - up, positive -down). * The values greater than one means that more mouse wheel or similar * events were generated, and hence it is better to scroll the longer * distance. * @author Audrius Meskauskas (audriusa@bioinformatics.org) */ public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { int delta; // Round so that the top would start from the row boundary if (orientation == SwingConstants.VERTICAL) { // One pixel down, otherwise picks another row too high. int row = getClosestRowForLocation(visibleRect.x, visibleRect.y + 1); row = row + direction; if (row < 0) row = 0; Rectangle newTop = getRowBounds(row); delta = newTop.y - visibleRect.y; } else delta = direction * rowHeight == 0 ? 20 : rowHeight; return delta; } public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { return getScrollableUnitIncrement(visibleRect, orientation, direction); } public boolean getScrollableTracksViewportHeight() { if (getParent() instanceof JViewport) return ((JViewport) getParent()).getHeight() > getPreferredSize().height; return false; } public boolean getScrollableTracksViewportWidth() { if (getParent() instanceof JViewport) return ((JViewport) getParent()).getWidth() > getPreferredSize().width; return false; } /** * Adds a <code>TreeExpansionListener</code> object to the tree. * * @param listener the listener to add */ public void addTreeExpansionListener(TreeExpansionListener listener) { listenerList.add(TreeExpansionListener.class, listener); } /** * Removes a <code>TreeExpansionListener</code> object from the tree. * * @param listener the listener to remove */ public void removeTreeExpansionListener(TreeExpansionListener listener) { listenerList.remove(TreeExpansionListener.class, listener); } /** * Returns all added <code>TreeExpansionListener</code> objects. * * @return an array of listeners */ public TreeExpansionListener[] getTreeExpansionListeners() { return (TreeExpansionListener[]) getListeners(TreeExpansionListener.class); } /** * Notifies all listeners that the tree was collapsed. * * @param path the path to the node that was collapsed */ public void fireTreeCollapsed(TreePath path) { TreeExpansionEvent event = new TreeExpansionEvent(this, path); TreeExpansionListener[] listeners = getTreeExpansionListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].treeCollapsed(event); } /** * Notifies all listeners that the tree was expanded. * * @param path the path to the node that was expanded */ public void fireTreeExpanded(TreePath path) { TreeExpansionEvent event = new TreeExpansionEvent(this, path); TreeExpansionListener[] listeners = getTreeExpansionListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].treeExpanded(event); } /** * Adds a <code>TreeSelctionListener</code> object to the tree. * * @param listener the listener to add */ public void addTreeSelectionListener(TreeSelectionListener listener) { listenerList.add(TreeSelectionListener.class, listener); } /** * Removes a <code>TreeSelectionListener</code> object from the tree. * * @param listener the listener to remove */ public void removeTreeSelectionListener(TreeSelectionListener listener) { listenerList.remove(TreeSelectionListener.class, listener); } /** * Returns all added <code>TreeSelectionListener</code> objects. * * @return an array of listeners */ public TreeSelectionListener[] getTreeSelectionListeners() { return (TreeSelectionListener[]) getListeners(TreeSelectionListener.class); } /** * Notifies all listeners when the selection of the tree changed. * * @param event the event to send */ protected void fireValueChanged(TreeSelectionEvent event) { TreeSelectionListener[] listeners = getTreeSelectionListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].valueChanged(event); } /** * Adds a <code>TreeWillExpandListener</code> object to the tree. * * @param listener the listener to add */ public void addTreeWillExpandListener(TreeWillExpandListener listener) { listenerList.add(TreeWillExpandListener.class, listener); } /** * Removes a <code>TreeWillExpandListener</code> object from the tree. * * @param listener the listener to remove */ public void removeTreeWillExpandListener(TreeWillExpandListener listener) { listenerList.remove(TreeWillExpandListener.class, listener); } /** * Returns all added <code>TreeWillExpandListener</code> objects. * * @return an array of listeners */ public TreeWillExpandListener[] getTreeWillExpandListeners() { return (TreeWillExpandListener[]) getListeners(TreeWillExpandListener.class); } /** * Notifies all listeners that the tree will collapse. * * @param path the path to the node that will collapse */ public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException { TreeExpansionEvent event = new TreeExpansionEvent(this, path); TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].treeWillCollapse(event); } /** * Notifies all listeners that the tree will expand. * * @param path the path to the node that will expand */ public void fireTreeWillExpand(TreePath path) throws ExpandVetoException { TreeExpansionEvent event = new TreeExpansionEvent(this, path); TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].treeWillExpand(event); } /** * Returns the model of this <code>JTree</code> object. * * @return the associated <code>TreeModel</code> */ public TreeModel getModel() { return treeModel; } /** * Sets the model to use in <code>JTree</code>. * * @param model the <code>TreeModel</code> to use */ public void setModel(TreeModel model) { if (treeModel == model) return; // add treeModelListener to the new model if (treeModelListener == null) treeModelListener = createTreeModelListener(); if (model != null) // as setModel(null) is allowed model.addTreeModelListener(treeModelListener); TreeModel oldValue = treeModel; treeModel = model; firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model); updateUI(); } /** * Checks if this <code>JTree</code> object is editable. * * @return <code>true</code> if this tree object is editable, * <code>false</code> otherwise */ public boolean isEditable() { return editable; } /** * Sets the <code>editable</code> property. * * @param flag <code>true</code> to make this tree object editable, * <code>false</code> otherwise */ public void setEditable(boolean flag) { if (editable == flag) return; boolean oldValue = editable; editable = flag; firePropertyChange(EDITABLE_PROPERTY, oldValue, editable); } /** * Checks if the root element is visible. * * @return <code>true</code> if the root element is visible, * <code>false</code> otherwise */ public boolean isRootVisible() { return rootVisible; } public void setRootVisible(boolean flag) { if (rootVisible == flag) return; boolean oldValue = rootVisible; rootVisible = flag; firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, flag); } public boolean getShowsRootHandles() { return showsRootHandles; } public void setShowsRootHandles(boolean flag) { if (showsRootHandles == flag) return; boolean oldValue = showsRootHandles; showsRootHandles = flag; firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, flag); } public TreeCellEditor getCellEditor() { return cellEditor; } public void setCellEditor(TreeCellEditor editor) { if (cellEditor == editor) return; TreeCellEditor oldValue = cellEditor; cellEditor = editor; firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor); } public TreeCellRenderer getCellRenderer() { return cellRenderer; } public void setCellRenderer(TreeCellRenderer newRenderer) { if (cellRenderer == newRenderer) return; TreeCellRenderer oldValue = cellRenderer; cellRenderer = newRenderer; firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, newRenderer); } public TreeSelectionModel getSelectionModel() { return selectionModel; } public void setSelectionModel(TreeSelectionModel model) { if (selectionModel == model) return; if (selectionModel != null) selectionModel.removeTreeSelectionListener(selectionRedirector); TreeSelectionModel oldValue = selectionModel; selectionModel = model; if (selectionModel != null) selectionModel.addTreeSelectionListener(selectionRedirector); firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model); revalidate(); repaint(); } public int getVisibleRowCount() { return visibleRowCount; } public void setVisibleRowCount(int rows) { if (visibleRowCount == rows) return; int oldValue = visibleRowCount; visibleRowCount = rows; firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldValue, rows); } public boolean isLargeModel() { return largeModel; } public void setLargeModel(boolean large) { if (largeModel == large) return; boolean oldValue = largeModel; largeModel = large; firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, large); } public int getRowHeight() { return rowHeight; } public void setRowHeight(int height) { if (rowHeight == height) return; int oldValue = rowHeight; rowHeight = height; firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, height); } public boolean isFixedRowHeight() { return rowHeight > 0; } public boolean getInvokesStopCellEditing() { return invokesStopCellEditing; } public void setInvokesStopCellEditing(boolean invoke) { if (invokesStopCellEditing == invoke) return; boolean oldValue = invokesStopCellEditing; invokesStopCellEditing = invoke; firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue, invoke); } /** * @since 1.3 */ public int getToggleClickCount() { return toggleClickCount; } /** * @since 1.3 */ public void setToggleClickCount(int count) { if (toggleClickCount == count) return; int oldValue = toggleClickCount; toggleClickCount = count; firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldValue, count); } public void scrollPathToVisible(TreePath path) { if (path == null) return; Object[] oPath = path.getPath(); TreePath temp = new TreePath(oPath[0]); boolean stop = false; int i = 1; while (!stop) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -