📄 defaulttreeselectionmodel.java
字号:
index = x; break; } } TreePath[] temp = new TreePath[selection.length - 1]; System.arraycopy(selection, 0, temp, 0, index); System.arraycopy(selection, index + 1, temp, index, selection.length - index - 1); selection = new TreePath[temp.length]; System.arraycopy(temp, 0, selection, 0, temp.length); fireValueChanged(new TreeSelectionEvent(this, v0, false, leadPath, paths[0])); } } } } /** * Returns the first path in the selection. This is especially useful when * the selectionMode is {@link #SINGLE_TREE_SELECTION}. * * @return the first path in the selection */ public TreePath getSelectionPath() { if ((selection == null) || (selection.length == 0)) return null; else return selection[0]; } /** * Returns the complete selection. * * @return the complete selection */ public TreePath[] getSelectionPaths() { return selection; } /** * Returns the number of paths in the selection. * * @return the number of paths in the selection */ public int getSelectionCount() { if (selection == null) return 0; else return selection.length; } /** * Checks if a given path is in the selection. * * @param path the path to check * * @return <code>true</code> if the path is in the selection, * <code>false</code> otherwise */ public boolean isPathSelected(TreePath path) { if (selection == null) return false; for (int i = 0; i < selection.length; i++) { if (selection[i].equals(path)) return true; } return false; } /** * Checks if the selection is empty. * * @return <code>true</code> if the selection is empty, <code>false</code> * otherwise */ public boolean isSelectionEmpty() { return ((selection == null) || (selection.length == 0)); } /** * Removes all paths from the selection. */ public void clearSelection() { leadPath = null; selection = null; } /** * Adds a <code>TreeSelectionListener</code> object to this model. * * @param listener the listener to add */ public void addTreeSelectionListener(TreeSelectionListener listener) { listenerList.add(TreeSelectionListener.class, listener); } /** * Removes a <code>TreeSelectionListener</code> object from this model. * * @param listener the listener to remove */ public void removeTreeSelectionListener(TreeSelectionListener listener) { listenerList.remove(TreeSelectionListener.class, listener); } /** * Returns all <code>TreeSelectionListener</code> added to this model. * * @return an array of listeners * * @since 1.4 */ public TreeSelectionListener[] getTreeSelectionListeners() { return (TreeSelectionListener[]) getListeners(TreeSelectionListener.class); } /** * fireValueChanged * * @param event the event to fire. */ protected void fireValueChanged(TreeSelectionEvent event) { TreeSelectionListener[] listeners = getTreeSelectionListeners(); for (int i = 0; i < listeners.length; ++i) listeners[i].valueChanged(event); } /** * Returns all added listeners of a special type. * * @param listenerType the listener type * * @return an array of listeners * * @since 1.3 */ public EventListener[] getListeners(Class listenerType) { return listenerList.getListeners(listenerType); } /** * Returns the currently selected rows. * * @return the currently selected rows */ public int[] getSelectionRows() { if (rowMapper == null) return null; else return rowMapper.getRowsForPaths(selection); } /** * Returns the smallest row index from the selection. * * @return the smallest row index from the selection */ public int getMinSelectionRow() { if ((rowMapper == null) || (selection == null) || (selection.length == 0)) return -1; else { int[] rows = rowMapper.getRowsForPaths(selection); int minRow = Integer.MAX_VALUE; for (int index = 0; index < rows.length; index++) minRow = Math.min(minRow, rows[index]); return minRow; } } /** * Returns the largest row index from the selection. * * @return the largest row index from the selection */ public int getMaxSelectionRow() { if ((rowMapper == null) || (selection == null) || (selection.length == 0)) return -1; else { int[] rows = rowMapper.getRowsForPaths(selection); int maxRow = -1; for (int index = 0; index < rows.length; index++) maxRow = Math.max(maxRow, rows[index]); return maxRow; } } /** * Checks if a particular row is selected. * * @param row the index of the row to check * * @return <code>true</code> if the row is in this selection, * <code>false</code> otherwise */ public boolean isRowSelected(int row) { return false; // TODO } /** * Updates the mappings from TreePaths to row indices. */ public void resetRowSelection() { // TODO } /** * getLeadSelectionRow * * @return int */ public int getLeadSelectionRow() { if ((rowMapper == null) || (leadPath == null)) return -1; else return rowMapper.getRowsForPaths(new TreePath[] { leadPath })[0]; } /** * getLeadSelectionPath * * @return TreePath */ public TreePath getLeadSelectionPath() { return leadPath; } /** * Adds a <code>PropertyChangeListener</code> object to this model. * * @param listener the listener to add. */ public void addPropertyChangeListener(PropertyChangeListener listener) { changeSupport.addPropertyChangeListener(listener); } /** * Removes a <code>PropertyChangeListener</code> object from this model. * * @param listener the listener to remove. */ public void removePropertyChangeListener(PropertyChangeListener listener) { changeSupport.removePropertyChangeListener(listener); } /** * Returns all added <code>PropertyChangeListener</code> objects. * * @return an array of listeners. * * @since 1.4 */ public PropertyChangeListener[] getPropertyChangeListeners() { return changeSupport.getPropertyChangeListeners(); } /** * Makes sure the currently selected paths are valid according to the * current selectionMode. * * If the selectionMode is set to {@link #CONTIGUOUS_TREE_SELECTION} and the * selection isn't contiguous then the selection is reset to the first set * of contguous paths. * * If the selectionMode is set to {@link #SINGLE_TREE_SELECTION} and the * selection has more than one path, the selection is reset to the contain * only the first path. */ protected void insureRowContinuity() { // TODO } /** * Returns <code>true</code> if the paths are contiguous or we have no * RowMapper assigned. * * @param paths the paths to check for continuity * @return <code>true</code> if the paths are contiguous or we have no * RowMapper assigned */ protected boolean arePathsContiguous(TreePath[] paths) { return false; // TODO } /** * Checks if the paths can be added. This returns <code>true</code> if: * <ul> * <li><code>paths</code> is <code>null</code> or empty</li> * <li>we have no RowMapper assigned</li> * <li>nothing is currently selected</li> * <li>selectionMode is {@link #DISCONTIGUOUS_TREE_SELECTION}</li> * <li>adding the paths to the selection still results in a contiguous set * of paths</li> * * @param paths the paths to check * * @return <code>true</code> if the paths can be added with respect to the * selectionMode */ protected boolean canPathsBeAdded(TreePath[] paths) { return false; // TODO } /** * Checks if the paths can be removed without breaking the continuity of the * selection according to selectionMode. * * @param paths the paths to check * @return <code>true</code> if the paths can be removed with respect to * the selectionMode */ protected boolean canPathsBeRemoved(TreePath[] paths) { return false; // TODO } /** * notifyPathChange * * @param value0 TODO * @param value1 TODO */ protected void notifyPathChange(Vector value0, TreePath value1) { // TODO } /** * Updates the lead index instance field. */ protected void updateLeadIndex() { // TODO } /** * Deprecated and not used. */ protected void insureUniqueness() { // TODO }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -