📄 basictableui.java
字号:
} else { if (isFileList) { maybeStartTimer(); } } pressedEvent = null; repostEvent(e); dispatchComponent = null; setValueIsAdjusting(false); } private void mouseReleasedDND(MouseEvent e) { MouseEvent me = DragRecognitionSupport.mouseReleased(e); if (me != null) { SwingUtilities2.adjustFocus(table); if (!dragPressDidSelection) { adjustSelection(me); } } if (!dragStarted) { if (isFileList) { maybeStartTimer(); return; } Point p = e.getPoint(); if (pressedEvent != null && table.rowAtPoint(p) == pressedRow && table.columnAtPoint(p) == pressedCol && table.editCellAt(pressedRow, pressedCol, pressedEvent)) { setDispatchComponent(pressedEvent); repostEvent(pressedEvent); // This may appear completely odd, but must be done for backward // compatibility reasons. Developers have been known to rely on // a call to shouldSelectCell after editing has begun. CellEditor ce = table.getCellEditor(); if (ce != null) { ce.shouldSelectCell(pressedEvent); } } } } public void dragStarting(MouseEvent me) { dragStarted = true; if (me.isControlDown() && isFileList) { table.getSelectionModel().addSelectionInterval(pressedRow, pressedRow); table.getColumnModel().getSelectionModel(). addSelectionInterval(pressedCol, pressedCol); } pressedEvent = null; } public void mouseDragged(MouseEvent e) { if (SwingUtilities2.shouldIgnore(e, table)) { return; } if (table.getDragEnabled() && (DragRecognitionSupport.mouseDragged(e, this) || dragStarted)) { return; } mouseDraggedImpl(e); } public void propertyChange(PropertyChangeEvent event) { super.propertyChange(event); String changeName = event.getPropertyName(); if ("Table.isFileList" == changeName) { if (isFileList) { table.getSelectionModel().addListSelectionListener(getDragFixHandler()); } else { table.getSelectionModel().removeListSelectionListener(getDragFixHandler()); timer = null; } } else if ("selectionModel" == changeName) { if (isFileList) { ListSelectionModel old = (ListSelectionModel)event.getOldValue(); old.removeListSelectionListener(getDragFixHandler()); table.getSelectionModel().addListSelectionListener(getDragFixHandler()); } } } } /* * Returns true if the given point is outside the preferredSize of the * item at the given row of the table. (Column must be 0). * Returns false if the "Table.isFileList" client property is not set. */ private static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) { if (!Boolean.TRUE.equals(table.getClientProperty("Table.isFileList"))) { return false; } return SwingUtilities2.pointOutsidePrefSize(table, row, column, p); }//// Factory methods for the Listeners// private Handler getHandler() { if (handler == null) { handler = DRAG_FIX ? new DragFixHandler() : new Handler(); } return handler; } private DragFixHandler getDragFixHandler() { // this only called by code that's enabled when DRAG_FIX is on assert DRAG_FIX; return (DragFixHandler)handler; } /** * Creates the key listener for handling keyboard navigation in the JTable. */ protected KeyListener createKeyListener() { return null; } /** * Creates the focus listener for handling keyboard navigation in the JTable. */ protected FocusListener createFocusListener() { return getHandler(); } /** * Creates the mouse listener for the JTable. */ protected MouseInputListener createMouseInputListener() { return getHandler(); }//// The installation/uninstall procedures and support// public static ComponentUI createUI(JComponent c) { return new BasicTableUI(); }// Installation public void installUI(JComponent c) { table = (JTable)c; rendererPane = new CellRendererPane(); table.add(rendererPane); installDefaults(); installDefaults2(); installListeners(); installKeyboardActions(); } /** * Initialize JTable properties, e.g. font, foreground, and background. * The font, foreground, and background properties are only set if their * current value is either null or a UIResource, other properties are set * if the current value is null. * * @see #installUI */ protected void installDefaults() { LookAndFeel.installColorsAndFont(table, "Table.background", "Table.foreground", "Table.font"); // JTable's original row height is 16. To correctly display the // contents on Linux we should have set it to 18, Windows 19 and // Solaris 20. As these values vary so much it's too hard to // be backward compatable and try to update the row height, we're // therefor NOT going to adjust the row height based on font. If the // developer changes the font, it's there responsability to update // the row height. LookAndFeel.installProperty(table, "opaque", Boolean.TRUE); Color sbg = table.getSelectionBackground(); if (sbg == null || sbg instanceof UIResource) { table.setSelectionBackground(UIManager.getColor("Table.selectionBackground")); } Color sfg = table.getSelectionForeground(); if (sfg == null || sfg instanceof UIResource) { table.setSelectionForeground(UIManager.getColor("Table.selectionForeground")); } Color gridColor = table.getGridColor(); if (gridColor == null || gridColor instanceof UIResource) { table.setGridColor(UIManager.getColor("Table.gridColor")); } // install the scrollpane border Container parent = table.getParent(); // should be viewport if (parent != null) { parent = parent.getParent(); // should be the scrollpane if (parent != null && parent instanceof JScrollPane) { LookAndFeel.installBorder((JScrollPane)parent, "Table.scrollPaneBorder"); } } isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList")); } private void installDefaults2() { TransferHandler th = table.getTransferHandler(); if (th == null || th instanceof UIResource) { table.setTransferHandler(defaultTransferHandler); } DropTarget dropTarget = table.getDropTarget(); if (dropTarget instanceof UIResource) { if (defaultDropTargetListener == null) { defaultDropTargetListener = new TableDropTargetListener(); } try { dropTarget.addDropTargetListener(defaultDropTargetListener); } catch (TooManyListenersException tmle) { // should not happen... swing drop target is multicast } } } /** * Attaches listeners to the JTable. */ protected void installListeners() { focusListener = createFocusListener(); keyListener = createKeyListener(); mouseInputListener = createMouseInputListener(); table.addFocusListener(focusListener); table.addKeyListener(keyListener); if (!DRAG_FIX) { table.addMouseListener(defaultDragRecognizer); table.addMouseMotionListener(defaultDragRecognizer); } table.addMouseListener(mouseInputListener); table.addMouseMotionListener(mouseInputListener); table.addPropertyChangeListener(getHandler()); if (DRAG_FIX && isFileList) { table.getSelectionModel().addListSelectionListener(getDragFixHandler()); } } /** * Register all keyboard actions on the JTable. */ protected void installKeyboardActions() { LazyActionMap.installLazyActionMap(table, BasicTableUI.class, "Table.actionMap"); InputMap inputMap = getInputMap(JComponent. WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); SwingUtilities.replaceUIInputMap(table, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); } InputMap getInputMap(int condition) { if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { InputMap keyMap = (InputMap)DefaultLookup.get(table, this, "Table.ancestorInputMap"); return keyMap; } return null; } static void loadActionMap(LazyActionMap map) { // IMPORTANT: There is a very close coupling between the parameters // passed to the Actions constructor. Only certain parameter // combinations are supported. For example, the following Action would // not work as expected: // new Actions(Actions.NEXT_ROW_CELL, 1, 4, false, true) // Actions which move within the selection only (having a true // inSelection parameter) require that one of dx or dy be // zero and the other be -1 or 1. The point of this warning is // that you should be very careful about making sure a particular // combination of parameters is supported before changing or // adding anything here. map.put(new Actions(Actions.NEXT_COLUMN, 1, 0, false, false)); map.put(new Actions(Actions.NEXT_COLUMN_CHANGE_LEAD, 1, 0, false, false)); map.put(new Actions(Actions.PREVIOUS_COLUMN, -1, 0, false, false)); map.put(new Actions(Actions.PREVIOUS_COLUMN_CHANGE_LEAD, -1, 0, false, false)); map.put(new Actions(Actions.NEXT_ROW, 0, 1, false, false)); map.put(new Actions(Actions.NEXT_ROW_CHANGE_LEAD, 0, 1, false, false)); map.put(new Actions(Actions.PREVIOUS_ROW, 0, -1, false, false)); map.put(new Actions(Actions.PREVIOUS_ROW_CHANGE_LEAD, 0, -1, false, false)); map.put(new Actions(Actions.NEXT_COLUMN_EXTEND_SELECTION, 1, 0, true, false)); map.put(new Actions(Actions.PREVIOUS_COLUMN_EXTEND_SELECTION, -1, 0, true, false)); map.put(new Actions(Actions.NEXT_ROW_EXTEND_SELECTION, 0, 1, true, false)); map.put(new Actions(Actions.PREVIOUS_ROW_EXTEND_SELECTION, 0, -1, true, false)); map.put(new Actions(Actions.SCROLL_UP_CHANGE_SELECTION, false, false, true, false)); map.put(new Actions(Actions.SCROLL_DOWN_CHANGE_SELECTION, false, true, true, false)); map.put(new Actions(Actions.FIRST_COLUMN, false, false, false, true)); map.put(new Actions(Actions.LAST_COLUMN, false, true, false, true)); map.put(new Actions(Actions.SCROLL_UP_EXTEND_SELECTION, true, false, true, false)); map.put(new Actions(Actions.SCROLL_DOWN_EXTEND_SELECTION, true, true, true, false)); map.put(new Acti
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -