📄 basiclistui.java
字号:
public void mousePressed(MouseEvent e) { getHandler().mousePressed(e); } public void mouseDragged(MouseEvent e) { getHandler().mouseDragged(e); } public void mouseMoved(MouseEvent e) { getHandler().mouseMoved(e); } public void mouseReleased(MouseEvent e) { getHandler().mouseReleased(e); } } /** * Creates a delegate that implements MouseInputListener. * The delegate is added to the corresponding java.awt.Component listener * lists at installUI() time. Subclasses can override this method to return * a custom MouseInputListener, e.g. * <pre> * class MyListUI extends BasicListUI { * protected MouseInputListener <b>createMouseInputListener</b>() { * return new MyMouseInputHandler(); * } * public class MyMouseInputHandler extends MouseInputHandler { * public void mouseMoved(MouseEvent e) { * // do some extra work when the mouse moves * super.mouseMoved(e); * } * } * } * </pre> * * @see MouseInputHandler * @see #installUI */ protected MouseInputListener createMouseInputListener() { return getHandler(); } /** * This inner class is marked "public" due to a compiler bug. * This class should be treated as a "protected" inner class. * Instantiate it only within subclasses of BasicTableUI. */ public class FocusHandler implements FocusListener { protected void repaintCellFocus() { getHandler().repaintCellFocus(); } /* The focusGained() focusLost() methods run when the JList * focus changes. */ public void focusGained(FocusEvent e) { getHandler().focusGained(e); } public void focusLost(FocusEvent e) { getHandler().focusLost(e); } } protected FocusListener createFocusListener() { return getHandler(); } /** * The ListSelectionListener that's added to the JLists selection * model at installUI time, and whenever the JList.selectionModel property * changes. When the selection changes we repaint the affected rows. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see #createListSelectionListener * @see #getCellBounds * @see #installUI */ public class ListSelectionHandler implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { getHandler().valueChanged(e); } } /** * Creates an instance of ListSelectionHandler that's added to * the JLists by selectionModel as needed. Subclasses can override * this method to return a custom ListSelectionListener, e.g. * <pre> * class MyListUI extends BasicListUI { * protected ListSelectionListener <b>createListSelectionListener</b>() { * return new MySelectionListener(); * } * public class MySelectionListener extends ListSelectionHandler { * public void valueChanged(ListSelectionEvent e) { * // do some extra work when the selection changes * super.valueChange(e); * } * } * } * </pre> * * @see ListSelectionHandler * @see #installUI */ protected ListSelectionListener createListSelectionListener() { return getHandler(); } private void redrawList() { list.revalidate(); list.repaint(); } /** * The ListDataListener that's added to the JLists model at * installUI time, and whenever the JList.model property changes. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see JList#getModel * @see #maybeUpdateLayoutState * @see #createListDataListener * @see #installUI */ public class ListDataHandler implements ListDataListener { public void intervalAdded(ListDataEvent e) { getHandler().intervalAdded(e); } public void intervalRemoved(ListDataEvent e) { getHandler().intervalRemoved(e); } public void contentsChanged(ListDataEvent e) { getHandler().contentsChanged(e); } } /** * Creates an instance of ListDataListener that's added to * the JLists by model as needed. Subclasses can override * this method to return a custom ListDataListener, e.g. * <pre> * class MyListUI extends BasicListUI { * protected ListDataListener <b>createListDataListener</b>() { * return new MyListDataListener(); * } * public class MyListDataListener extends ListDataHandler { * public void contentsChanged(ListDataEvent e) { * // do some extra work when the models contents change * super.contentsChange(e); * } * } * } * </pre> * * @see ListDataListener * @see JList#getModel * @see #installUI */ protected ListDataListener createListDataListener() { return getHandler(); } /** * The PropertyChangeListener that's added to the JList at * installUI time. When the value of a JList property that * affects layout changes, we set a bit in updateLayoutStateNeeded. * If the JLists model changes we additionally remove our listeners * from the old model. Likewise for the JList selectionModel. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see #maybeUpdateLayoutState * @see #createPropertyChangeListener * @see #installUI */ public class PropertyChangeHandler implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent e) { getHandler().propertyChange(e); } } /** * Creates an instance of PropertyChangeHandler that's added to * the JList by installUI(). Subclasses can override this method * to return a custom PropertyChangeListener, e.g. * <pre> * class MyListUI extends BasicListUI { * protected PropertyChangeListener <b>createPropertyChangeListener</b>() { * return new MyPropertyChangeListener(); * } * public class MyPropertyChangeListener extends PropertyChangeHandler { * public void propertyChange(PropertyChangeEvent e) { * if (e.getPropertyName().equals("model")) { * // do some extra work when the model changes * } * super.propertyChange(e); * } * } * } * </pre> * * @see PropertyChangeListener * @see #installUI */ protected PropertyChangeListener createPropertyChangeListener() { return getHandler(); } /** Used by IncrementLeadSelectionAction. Indicates the action should * change the lead, and not select it. */ private static final int CHANGE_LEAD = 0; /** Used by IncrementLeadSelectionAction. Indicates the action should * change the selection and lead. */ private static final int CHANGE_SELECTION = 1; /** Used by IncrementLeadSelectionAction. Indicates the action should * extend the selection from the anchor to the next index. */ private static final int EXTEND_SELECTION = 2; private static class Actions extends UIAction { private static final String SELECT_PREVIOUS_COLUMN = "selectPreviousColumn"; private static final String SELECT_PREVIOUS_COLUMN_EXTEND = "selectPreviousColumnExtendSelection"; private static final String SELECT_PREVIOUS_COLUMN_CHANGE_LEAD = "selectPreviousColumnChangeLead"; private static final String SELECT_NEXT_COLUMN = "selectNextColumn"; private static final String SELECT_NEXT_COLUMN_EXTEND = "selectNextColumnExtendSelection"; private static final String SELECT_NEXT_COLUMN_CHANGE_LEAD = "selectNextColumnChangeLead"; private static final String SELECT_PREVIOUS_ROW = "selectPreviousRow"; private static final String SELECT_PREVIOUS_ROW_EXTEND = "selectPreviousRowExtendSelection"; private static final String SELECT_PREVIOUS_ROW_CHANGE_LEAD = "selectPreviousRowChangeLead"; private static final String SELECT_NEXT_ROW = "selectNextRow"; private static final String SELECT_NEXT_ROW_EXTEND = "selectNextRowExtendSelection"; private static final String SELECT_NEXT_ROW_CHANGE_LEAD = "selectNextRowChangeLead"; private static final String SELECT_FIRST_ROW = "selectFirstRow"; private static final String SELECT_FIRST_ROW_EXTEND = "selectFirstRowExtendSelection"; private static final String SELECT_FIRST_ROW_CHANGE_LEAD = "selectFirstRowChangeLead"; private static final String SELECT_LAST_ROW = "selectLastRow"; private static final String SELECT_LAST_ROW_EXTEND = "selectLastRowExtendSelection"; private static final String SELECT_LAST_ROW_CHANGE_LEAD = "selectLastRowChangeLead"; private static final String SCROLL_UP = "scrollUp"; private static final String SCROLL_UP_EXTEND = "scrollUpExtendSelection"; private static final String SCROLL_UP_CHANGE_LEAD = "scrollUpChangeLead"; private static final String SCROLL_DOWN = "scrollDown"; private static final String SCROLL_DOWN_EXTEND = "scrollDownExtendSelection"; private static final String SCROLL_DOWN_CHANGE_LEAD = "scrollDownChangeLead"; private static final String SELECT_ALL = "selectAll"; private static final String CLEAR_SELECTION = "clearSelection"; // add the lead item to the selection without changing lead or anchor private static final String ADD_TO_SELECTION = "addToSelection"; // toggle the selected state of the lead item and move the anchor to it private static final String TOGGLE_AND_ANCHOR = "toggleAndAnchor"; // extend the selection to the lead item private static final String EXTEND_TO = "extendTo"; // move the anchor to the lead and ensure only that item is selected private static final String MOVE_SELECTION_TO = "moveSelectionTo"; Actions(String name) { super(name); } public void actionPerformed(ActionEvent e) { String name = getName(); JList list = (JList)e.getSource(); BasicListUI ui = (BasicListUI)BasicLookAndFeel.getUIOfType( list.getUI(), BasicListUI.class); if (name == SELECT_PREVIOUS_COLUMN) { changeSelection(list, CHANGE_SELECTION, getNextColumnIndex(list, ui, -1), -1); } else if (name == SELECT_PREVIOUS_COLUMN_EXTEND) { changeSelection(list, EXTEND_SELECTION, getNextColumnIndex(list, ui, -1), -1); } else if (name == SELECT_PREVIOUS_COLUMN_CHANGE_LEAD) { changeSelection(list, CHANGE_LEAD, getNextColumnIndex(list, ui, -1), -1); } else if (name == SELECT_NEXT_COLUMN) { changeSelection(list, CHANGE_SELECTION, getNextColumnIndex(list, ui, 1), 1); } else if (name == SELECT_NEXT_COLUMN_EXTEND) { changeSelection(list, EXTEND_SELECTION, getNextColumnIndex(list, ui, 1), 1); } else if (name == SELECT_NEXT_COLUMN_CHANGE_LEAD) { changeSelection(list, CHANGE_LEAD, getNextColumnIndex(list, ui, 1), 1); } else if (name == SELECT_PREVIOUS_ROW) { changeSelection(list, CHANGE_SELECTION, getNextIndex(list, ui, -1), -1); } else if (name == SELECT_PREVIOUS_ROW_EXTEND) { changeSelection(list, EXTEND_SELECTION, getNextIndex(list, ui, -1), -1); } else if (name == SELECT_PREVIOUS_ROW_CHANGE_LEAD) { changeSelection(list, CHANGE_LEAD, getNextIndex(list, ui, -1), -1); } else if (name == SELECT_NEXT_ROW) { changeSelection(list, CHANGE_SELECTION, getNextIndex(list, ui, 1), 1); } else if (name == SELECT_NE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -