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

📄 basictableui.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                } else if (leadColumn < minX) {                    leadColumn = maxX;                    leadRow--;                    if (leadRow < minY) {                        leadRow = maxY;                    }                }            } else {                leadRow += dy;                if (leadRow > maxY) {                    leadRow = minY;                    leadColumn++;                    if (leadColumn > maxX) {                        leadColumn = minX;                    }                } else if (leadRow < minY) {                    leadRow = maxY;                    leadColumn--;                    if (leadColumn < minX) {                        leadColumn = maxX;                    }                }            }        }        public void actionPerformed(ActionEvent e) {            String key = getName();            JTable table = (JTable)e.getSource();            ListSelectionModel rsm = table.getSelectionModel();            leadRow = getAdjustedLead(table, true, rsm);            ListSelectionModel csm = table.getColumnModel().getSelectionModel();            leadColumn = getAdjustedLead(table, false, csm);            if (!table.getComponentOrientation().isLeftToRight()) {                if (key == SCROLL_LEFT_CHANGE_SELECTION ||                        key == SCROLL_LEFT_EXTEND_SELECTION) {                    forwards = true;                } else if (key == SCROLL_RIGHT_CHANGE_SELECTION ||                        key == SCROLL_RIGHT_EXTEND_SELECTION) {                    forwards = false;                }            }            if (key == SCROLL_LEFT_CHANGE_SELECTION ||        // Paging Actions                    key == SCROLL_LEFT_EXTEND_SELECTION ||                    key == SCROLL_RIGHT_CHANGE_SELECTION ||                    key == SCROLL_RIGHT_EXTEND_SELECTION ||	            key == SCROLL_UP_CHANGE_SELECTION ||                    key == SCROLL_UP_EXTEND_SELECTION ||                    key == SCROLL_DOWN_CHANGE_SELECTION ||                    key == SCROLL_DOWN_EXTEND_SELECTION ||                    key == FIRST_COLUMN ||                    key == FIRST_COLUMN_EXTEND_SELECTION ||                    key == FIRST_ROW ||                    key == FIRST_ROW_EXTEND_SELECTION ||                    key == LAST_COLUMN ||                    key == LAST_COLUMN_EXTEND_SELECTION ||                    key == LAST_ROW ||                    key == LAST_ROW_EXTEND_SELECTION) {                if (toLimit) {                    if (vertically) {                        int rowCount = table.getRowCount();                        this.dx = 0;                        this.dy = forwards ? rowCount : -rowCount;                    }                    else {                        int colCount = table.getColumnCount();                        this.dx = forwards ? colCount : -colCount;                        this.dy = 0;                    }                }                else {                    if (!(table.getParent().getParent() instanceof                            JScrollPane)) {                        return;                    }                        Dimension delta = table.getParent().getSize();                    if (vertically) {                        Rectangle r = table.getCellRect(leadRow, 0, true);                        r.y += forwards ? delta.height : -delta.height;                        this.dx = 0;                        int newRow = table.rowAtPoint(r.getLocation());                        if (newRow == -1 && forwards) {                            newRow = table.getRowCount();                        }                        this.dy = newRow - leadRow;                    }                    else {                        Rectangle r = table.getCellRect(0, leadColumn, true);                        r.x += forwards ? delta.width : -delta.width;                        int newColumn = table.columnAtPoint(r.getLocation());                        if (newColumn == -1 && forwards) {                            newColumn = table.getColumnCount();                        }                        this.dx = newColumn - leadColumn;                        this.dy = 0;                    }                }            }            if (key == NEXT_ROW ||  // Navigate Actions                    key == NEXT_ROW_CELL ||                    key == NEXT_ROW_EXTEND_SELECTION ||                    key == NEXT_ROW_CHANGE_LEAD ||                    key == NEXT_COLUMN ||                    key == NEXT_COLUMN_CELL ||                    key == NEXT_COLUMN_EXTEND_SELECTION ||                    key == NEXT_COLUMN_CHANGE_LEAD ||                    key == PREVIOUS_ROW ||                    key == PREVIOUS_ROW_CELL ||                    key == PREVIOUS_ROW_EXTEND_SELECTION ||                    key == PREVIOUS_ROW_CHANGE_LEAD ||                    key == PREVIOUS_COLUMN ||                    key == PREVIOUS_COLUMN_CELL ||                    key == PREVIOUS_COLUMN_EXTEND_SELECTION ||                    key == PREVIOUS_COLUMN_CHANGE_LEAD ||                    // Paging Actions.                    key == SCROLL_LEFT_CHANGE_SELECTION ||                    key == SCROLL_LEFT_EXTEND_SELECTION ||                    key == SCROLL_RIGHT_CHANGE_SELECTION ||                    key == SCROLL_RIGHT_EXTEND_SELECTION ||	            key == SCROLL_UP_CHANGE_SELECTION ||                    key == SCROLL_UP_EXTEND_SELECTION ||                    key == SCROLL_DOWN_CHANGE_SELECTION ||                    key == SCROLL_DOWN_EXTEND_SELECTION ||                    key == FIRST_COLUMN ||                    key == FIRST_COLUMN_EXTEND_SELECTION ||                    key == FIRST_ROW ||                    key == FIRST_ROW_EXTEND_SELECTION ||                    key == LAST_COLUMN ||                    key == LAST_COLUMN_EXTEND_SELECTION ||                    key == LAST_ROW ||                    key == LAST_ROW_EXTEND_SELECTION) {                if (table.isEditing() &&                        !table.getCellEditor().stopCellEditing()) {                    return;                }                    // Unfortunately, this strategy introduces bugs because                // of the asynchronous nature of requestFocus() call below.                // Introducing a delay with invokeLater() makes this work                // in the typical case though race conditions then allow                // focus to disappear altogether. The right solution appears                // to be to fix requestFocus() so that it queues a request                // for the focus regardless of who owns the focus at the                // time the call to requestFocus() is made. The optimisation                // to ignore the call to requestFocus() when the component                // already has focus may ligitimately be made as the                // request focus event is dequeued, not before.                    // boolean wasEditingWithFocus = table.isEditing() &&                // table.getEditorComponent().isFocusOwner();                boolean changeLead = false;                if (key == NEXT_ROW_CHANGE_LEAD || key == PREVIOUS_ROW_CHANGE_LEAD) {                    changeLead = (rsm.getSelectionMode()                                     == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);                } else if (key == NEXT_COLUMN_CHANGE_LEAD || key == PREVIOUS_COLUMN_CHANGE_LEAD) {                    changeLead = (csm.getSelectionMode()                                     == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);                }                if (changeLead) {                    moveWithinTableRange(table, dx, dy);                    if (dy != 0) {                        // casting should be safe since the action is only enabled                        // for DefaultListSelectionModel                        ((DefaultListSelectionModel)rsm).moveLeadSelectionIndex(leadRow);                        if (getAdjustedLead(table, false, csm) == -1                                && table.getColumnCount() > 0) {                            ((DefaultListSelectionModel)csm).moveLeadSelectionIndex(0);                        }                    } else {                        // casting should be safe since the action is only enabled                        // for DefaultListSelectionModel                        ((DefaultListSelectionModel)csm).moveLeadSelectionIndex(leadColumn);                        if (getAdjustedLead(table, true, rsm) == -1                                && table.getRowCount() > 0) {                            ((DefaultListSelectionModel)rsm).moveLeadSelectionIndex(0);                        }                    }                    Rectangle cellRect = table.getCellRect(leadRow, leadColumn, false);                    if (cellRect != null) {                        table.scrollRectToVisible(cellRect);                    }                } else if (!inSelection) {                    moveWithinTableRange(table, dx, dy);                    table.changeSelection(leadRow, leadColumn, false, extend);                }                else {                    if (table.getRowCount() <= 0 || table.getColumnCount() <= 0) {                        // bail - don't try to move selection on an empty table                        return;                    }                    if (moveWithinSelectedRange(table, dx, dy, rsm, csm)) {                        // this is the only way we have to set both the lead                        // and the anchor without changing the selection                        if (rsm.isSelectedIndex(leadRow)) {                            rsm.addSelectionInterval(leadRow, leadRow);                        } else {                            rsm.removeSelectionInterval(leadRow, leadRow);                        }                        if (csm.isSelectedIndex(leadColumn)) {                            csm.addSelectionInterval(leadColumn, leadColumn);                        } else {                            csm.removeSelectionInterval(leadColumn, leadColumn);                        }                        Rectangle cellRect = table.getCellRect(leadRow, leadColumn, false);                        if (cellRect != null) {                            table.scrollRectToVisible(cellRect);                        }                    }                    else {                        table.changeSelection(leadRow, leadColumn,                                false, false);                    }                }                    /*                if (wasEditingWithFocus) {                    table.editCellAt(leadRow, leadColumn);                    final Component editorComp = table.getEditorComponent();                    if (editorComp != null) {                        SwingUtilities.invokeLater(new Runnable() {                            public void run() {                                editorComp.requestFocus();                            }                        });                    }                }                */            } else if (key == CANCEL_EDITING) {                table.removeEditor();            } else if (key == SELECT_ALL) {                table.selectAll();            } else if (key == CLEAR_SELECTION) {                table.clearSelection();            } else if (key == START_EDITING) {                if (!table.hasFocus()) {                    CellEditor cellEditor = table.getCellEditor();                    if (cellEditor != null && !cellEditor.stopCellEditing()) {                        return;                    }                    table.requestFocus();                    return;                }                table.editCellAt(leadRow, leadColumn, e);                Component editorComp = table.getEditorComponent();                if (editorComp != null) {                    editorComp.requestFocus();                }            } else if (key == ADD_TO_SELECTION) {                if (!table.isCellSelected(leadRow, leadColumn)) {                    int oldAnchorRow = rsm.getAnchorSelectionIndex();                    int oldAnchorColumn = csm.getAnchorSelectionIndex();                    rsm.setValueIsAdjusting(true);                    csm.setValueIsAdjusting(true);                    table.changeSelection(leadRow, leadColumn, true, false);                    rsm.setAnchorSelectionIndex(oldAnchorRow);                    csm.setAnchorSelectionIndex(oldAnchorColumn);                    rsm.setValueIsAdjusting(false);                    csm.setValueIsAdjusting(false);                }            } else if (key == TOGGLE_AND_ANCHOR) {                table.changeSelection(leadRow, leadColumn, true, false);            } else if (key == EXTEND_TO) {                table.changeSelection(leadRow, leadColumn, false, true);            } else if (key == MOVE_SELECTION_TO) {                table.changeSelection(leadRow, leadColumn, false, false);            } else if (key == FOCUS_HEADER) {                JTableHeader th = table.getTableHeader();                if (th != null) {                    //Set the header's selected column to match the table.                    int col = table.getSelectedColumn();                    if (col >= 0) {                        TableHeaderUI thUI = th.getUI();                        if (thUI instanceof BasicTableHeaderUI) {                            ((BasicTableHeaderUI)thUI).selectColumn(col);                        }                    }                                        //Then give the header the focus.                    th.requestFocusInWindow();                }            }        }        public boolean isEnabled(Object sender) {            String key = getName();            if (sender instanceof JTable &&                Boolean.TRUE.equals(((JTable)sender).getClientProperty("Table.isFileList"))) {                if (key == NEXT_COLUMN ||                        key == NEXT_COLUMN_CELL ||                        key == NEXT_COLUMN_EXTEND_SELECTION ||                        key == NEXT_COLUMN_CHANGE_LEAD ||                        key == PREVIOUS_COLUMN ||                        key == PREVIOUS_COLUMN_CELL ||                        key == PREVIOUS_COLUMN_EXTEND_SELECTION ||                        key == PREVIOUS_COLUMN_CHANGE_LEAD ||                        key == SCROLL_LEFT_CHANGE_SELECTION ||                        key == SCROLL_LEFT_EXTEND_SELECTION ||                        key == SCROLL_RIGHT_CHANGE_SELECTION ||                        key == SCROLL_RIGHT_EXTEND_SELECTION ||                        key == FIRST_COLUMN ||                        key == FIRST_COLUMN_EXTEND_SELECTION ||                        key == LAST_COLUMN ||                        key == LAST_COLUMN_EXTEND_SELECTION ||                        key == NEXT_ROW_CELL ||                        key == PREVIOUS_ROW_CELL) {                    return false;                }            }            if (key == CANCEL_EDITING && sender instanceof JTable) {                return ((JTable)sender).isEditing();            } else if (key == NEXT_ROW_CHANGE_LEAD ||                       key == PREVIOUS_ROW_CHANGE_LEAD) {                // discontinuous selection actions are only enabled for                // DefaultListSelectionModel                return sender != null &&                       ((JTable)sender).getSelectionModel()                           instanceof DefaultListSelectionModel;            } else if (key == NEXT_COLUMN_CHANGE_LEAD ||                       key == PREVIOUS_COLUMN_CHANGE_LEAD) {                // discontinuous selection actions are only enabled for

⌨️ 快捷键说明

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