⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basictableui.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                table.changeSelection(row, column, ctrl, !ctrl && e.isShiftDown());            }        }        public void mouseReleased(MouseEvent e) {	    if (selectedOnPress) {		if (shouldIgnore0(e)) {		    return;		}		repostEvent(e);		dispatchComponent = null;		setValueIsAdjusting(false);	    } else {		adjustFocusAndSelection(e);	    }        }        public void mouseEntered(MouseEvent e) {}        public void mouseExited(MouseEvent e) {}        public void mouseMoved(MouseEvent e) {}        public void mouseDragged(MouseEvent e) {	    if (shouldIgnore0(e)) {	        return;	    }            mouseDraggedImpl(e);        }        protected void mouseDraggedImpl(MouseEvent e) {            repostEvent(e);            // Check isFileList:            // Until we support drag-selection, dragging should not change            // the selection (act like single-select).            if (isFileList || table.isEditing()) {                return;            }            Point p = e.getPoint();            int row = table.rowAtPoint(p);            int column = table.columnAtPoint(p);	    // The autoscroller can generate drag events outside the            // table's range.            if ((column == -1) || (row == -1)) {                return;            }            if (e.isControlDown()) {                ListSelectionModel cm = table.getColumnModel().getSelectionModel();                ListSelectionModel rm = table.getSelectionModel();                int colAnchor = cm.getAnchorSelectionIndex();                int rowAnchor = rm.getAnchorSelectionIndex();                boolean selected = true;                if (rowAnchor == -1 || rowAnchor >= table.getRowCount()) {                    rowAnchor = 0;                    selected = false;                }                if (colAnchor == -1 || colAnchor >= table.getColumnCount()) {                    colAnchor = 0;                    selected = false;                }                selected = selected && table.isCellSelected(rowAnchor, colAnchor);                changeSelectionModel(cm, colAnchor, selected, column);                changeSelectionModel(rm, rowAnchor, selected, row);                // From JTable.changeSelection():                // Scroll after changing the selection as blit scrolling is immediate,                // so that if we cause the repaint after the scroll we end up painting                // everything!                if (table.getAutoscrolls()) {                    Rectangle cellRect = table.getCellRect(row, column, false);                    if (cellRect != null) {                        table.scrollRectToVisible(cellRect);                    }                }            } else {                table.changeSelection(row, column, false, true);            }        }        private void changeSelectionModel(ListSelectionModel sm,                                          int anchorIndex,                                          boolean anchorSelected,                                          int index) {            if (anchorSelected) {                sm.addSelectionInterval(anchorIndex, index);            } else {                sm.removeSelectionInterval(anchorIndex, index);            }        }        // PropertyChangeListener	public void propertyChange(PropertyChangeEvent event) {	    String changeName = event.getPropertyName();	    if ("componentOrientation" == changeName) {		JTableHeader header = table.getTableHeader();		if (header != null) {		    header.setComponentOrientation(                            (ComponentOrientation)event.getNewValue());		}            } else if ("transferHandler" == changeName) {                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                    }                }            } else if ("Table.isFileList" == changeName) {                isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList"));                table.revalidate();                table.repaint();            }	}    }    private class DragFixHandler extends Handler implements ListSelectionListener,                                                            ActionListener,                                                            BeforeDrag {        // The row and column where the press occurred and the        // press event itself        private int pressedRow;        private int pressedCol;        private MouseEvent pressedEvent;        // Whether or not the mouse press (which is being considered as part        // of a drag sequence) also caused the selection change to be fully        // processed.        private boolean dragPressDidSelection;                // Set to true when a drag gesture has been fully recognized and DnD        // begins. Use this to ignore further mouse events which could be        // delivered if DnD is cancelled (via ESCAPE for example)        private boolean dragStarted;        // Whether or not we should start the editing timer on release        private boolean shouldStartTimer;        // To cache the return value of pointOutsidePrefSize since we use        // it multiple times.        private boolean outsidePrefSize;        // Used to delay the start of editing.        private Timer timer = null;        private boolean canStartDrag() {            if (pressedRow == -1 || pressedCol == -1) {                return false;            }            if (isFileList) {                return !outsidePrefSize;            }            // if this is a single selection table            if ((table.getSelectionModel().getSelectionMode() ==                     ListSelectionModel.SINGLE_SELECTION) &&                (table.getColumnModel().getSelectionModel().getSelectionMode() ==                     ListSelectionModel.SINGLE_SELECTION)) {                return true;            }            return table.isCellSelected(pressedRow, pressedCol);        }        public void mousePressed(MouseEvent e) {            if (SwingUtilities2.shouldIgnore(e, table)) {                return;            }            if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {                Component editorComponent = table.getEditorComponent();                if (editorComponent != null && !editorComponent.hasFocus()) {                    BasicLookAndFeel.compositeRequestFocus(editorComponent);                }                return;            }            Point p = e.getPoint();            pressedRow = table.rowAtPoint(p);            pressedCol = table.columnAtPoint(p);            outsidePrefSize = pointOutsidePrefSize(table, pressedRow, pressedCol, p);            if (isFileList) {                shouldStartTimer =                    table.isCellSelected(pressedRow, pressedCol) &&                    !e.isShiftDown() &&                    !e.isControlDown() &&                    !outsidePrefSize;            }            if (table.getDragEnabled()) {                mousePressedDND(e);            } else {                SwingUtilities2.adjustFocus(table);                if (!isFileList) {                    setValueIsAdjusting(true);                }                adjustSelection(e);            }        }        private void mousePressedDND(MouseEvent e) {            pressedEvent = e;            boolean grabFocus = true;            dragStarted = false;            if (canStartDrag() && DragRecognitionSupport.mousePressed(e)) {                dragPressDidSelection = false;                if (e.isControlDown() && isFileList) {                    // do nothing for control - will be handled on release                    // or when drag starts                    return;                } else if (!e.isShiftDown() && table.isCellSelected(pressedRow, pressedCol)) {                    // clicking on something that's already selected                    // and need to make it the lead now                    table.getSelectionModel().addSelectionInterval(pressedRow,                                                                   pressedRow);                    table.getColumnModel().getSelectionModel().                        addSelectionInterval(pressedCol, pressedCol);                    return;                }                dragPressDidSelection = true;                // could be a drag initiating event - don't grab focus                grabFocus = false;            } else if (!isFileList) {                // When drag can't happen, mouse drags might change the selection in the table                // so we want the isAdjusting flag to be set                setValueIsAdjusting(true);            }            if (grabFocus) {                SwingUtilities2.adjustFocus(table);            }            adjustSelection(e);        }        private void adjustSelection(MouseEvent e) {            // Fix for 4835633            if (outsidePrefSize) {                // If shift is down in multi-select, we should just return.                // For single select or non-shift-click, clear the selection                if (e.getID() ==  MouseEvent.MOUSE_PRESSED &&                    (!e.isShiftDown() ||                     table.getSelectionModel().getSelectionMode() ==                     ListSelectionModel.SINGLE_SELECTION)) {                    table.clearSelection();                    TableCellEditor tce = table.getCellEditor();                    if (tce != null) {                        tce.stopCellEditing();                    }                }                return;            }            // The autoscroller can generate drag events outside the            // table's range.            if ((pressedCol == -1) || (pressedRow == -1)) {                return;            }            boolean dragEnabled = table.getDragEnabled();            if (!dragEnabled && !isFileList && table.editCellAt(pressedRow, pressedCol, e)) {                setDispatchComponent(e);                repostEvent(e);            }            CellEditor editor = table.getCellEditor();            if (dragEnabled || editor == null || editor.shouldSelectCell(e)) {                makeSelectionChange(pressedRow, pressedCol, e);            }        }        public void valueChanged(ListSelectionEvent e) {            if (timer != null) {                timer.stop();                timer = null;            }        }        public void actionPerformed(ActionEvent ae) {            table.editCellAt(pressedRow, pressedCol, null);            Component editorComponent = table.getEditorComponent();            if (editorComponent != null && !editorComponent.hasFocus()) {                BasicLookAndFeel.compositeRequestFocus(editorComponent);            }            return;        }        private void maybeStartTimer() {            if (!shouldStartTimer) {                return;            }            if (timer == null) {                timer = new Timer(1200, this);                timer.setRepeats(false);            }            timer.start();        }        public void mouseReleased(MouseEvent e) {            if (SwingUtilities2.shouldIgnore(e, table)) {                return;            }            if (table.getDragEnabled()) {                mouseReleasedDND(e);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -