/** Creates a new instance of BaseTable. */ public BaseTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) { super(dm, cm, sm); //set single selection mode getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setSurrendersFocusOnKeystroke(true); setCellSelectionEnabled(false); setRowSelectionAllowed(true); setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); //See the sources for JTable for what these do putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); //NOI18N putClientProperty("terminateEditOnFocusLost", PropUtils.psCommitOnFocusLoss ? Boolean.FALSE : Boolean.TRUE); //NOI18N //create a listener for dragging the grid center line to resize columns dragListener = new LineDragListener(); addMouseListener(dragListener); addMouseMotionListener(dragListener); //If we are not focus cycle root, when an editor is removed, focus //will get set to a random component which is usually not the property //sheet setFocusCycleRoot(true); enableEvents(AWTEvent.FOCUS_EVENT_MASK); //JDK 1.5 if (getClass() != SheetTable.class) { throw new NoClassDefFoundError("Only SheetTable may subclass BaseTable, for good reasons"); //NOI18N } }
/** Paint the table. After the super.paint() call, calls paintMargin() to fill * in the left edge with the appropriate color, and then calls paintExpandableSets() * to paint the property sets, which are not painted by the default painting * methods because they need to be painted across two rows. */ public void paint(Graphics g) { if (needCalcRowHeight) { calcRowHeight(g); return; } super.paint(g); }
private void reverseSearch(String txt) { if ((txt == null) || (txt.length() == 0)) { return; } int max = getRowCount(); int pos = getSelectedRow(); if (pos < 1) { pos = max - 1; } for (int i = pos - 1; i >= 0; i--) { boolean match = matchText(BaseTable.this.getValueAt(i, 0), txt); if (match) { changeSelection(i, 0, false, false); //Set renderers can overpaint it, so repaint repaint(); break; } } }
enterEditRequest(); if (e instanceof MouseEvent) { if (PropUtils.isLoggable(BaseTable.class)) { if (!requestFocusInWindow()) { requestFocus(); boolean wasEditing = isEditing(); PropUtils.log(BaseTable.class, " was already editing, removing the editor"); //NOI18N removeEditor(); int prevSel = getSelectedRow(); changeSelection(row, col, false, false); final boolean editorChange = wasEditing && isCellEditable(row,col); if (editorChange) { enterEditorChangeRequest(); if (!isKnownComponent(c)) { exitEditRequest(); } finally { if (editorChange) { exitEditorChangeRequest();
public void actionPerformed(ActionEvent e) { int next = getSelectedRow() + (direction ? 1 : (-1)); if ((next >= getRowCount()) || (next < 0)) { if (!(BaseTable.this.getTopLevelAncestor() instanceof Dialog)) { next = (next >= getRowCount()) ? 0 : (getRowCount() - 1); } else if ((next >= getRowCount()) || (next < 0)) { Container ancestor = getFocusCycleRootAncestor(); ? ancestor.getFocusTraversalPolicy().getComponentAfter(ancestor, BaseTable.this.getParent()) : ancestor.getFocusTraversalPolicy().getComponentBefore(ancestor, BaseTable.this); JRootPane rp = getRootPane(); JButton jb = rp.getDefaultButton(); if (sibling == BaseTable.this) { changeSelection( direction ? 0 : (getRowCount() - 1), direction ? 0 : (getColumnCount() - 1), false, false ); changeSelection(next, getSelectedColumn(), false, false); if( getSelectionModel().getAnchorSelectionIndex() < 0 ) getSelectionModel().setAnchorSelectionIndex(next); getSelectionModel().setLeadSelectionIndex(next);
/** Overridden to add the entire row that was being edited to RepaintManager * as a dirty region */ public void removeEditor() { enterEditorRemoveRequest(); try { int i = editingRow; if (editorComp != null) { editorComp.removeFocusListener(this); } if (PropUtils.isLoggable(BaseTable.class)) { PropUtils.log(BaseTable.class, " removing editor"); //NOI18N } super.removeEditor(); if (i != -1) { //Do schedule a repaint for the row just in case paintRow(i); } } finally { exitEditorRemoveRequest(); } }
public void processKeyEvent(KeyEvent ke) { if (!isShowing()) { super.processKeyEvent(ke); return; } //override the default handling so that //the parent will never receive the escape key and //close a modal dialog if (ke.getKeyCode() == ke.VK_ESCAPE) { //The focus request will hide the field without focus getting //lost to somewhere else in the main window first. BaseTable.this.changeSelection(selectionBeforeLastShow, 0, false, false); BaseTable.this.requestFocus(); ke.consume(); } else if ((ke.getKeyCode() == ke.VK_UP) && (ke.getID() == ke.KEY_PRESSED)) { reverseSearch(getText()); } else if ((ke.getKeyCode() == ke.VK_DOWN) && (ke.getID() == ke.KEY_PRESSED)) { forwardSearch(getText()); } else { super.processKeyEvent(ke); if ((ke.getKeyCode() != ke.VK_UP) && (ke.getKeyCode() != ke.VK_DOWN)) { processSearchText(getText()); } } }
/** Overridden to clear the focus event countdown */ @Override public void changeSelection(int row, int col, boolean a, boolean b) { countDown = -1; super.changeSelection(row, col, a, b); }
/** Overridden to check if the edit failed, and if so, set a focus event * countdown for re-initiating editing */ public void editingStopped(ChangeEvent e) { super.editingStopped(e); //Po Ting's request for Rave - if commit on focus loss is on, all //edits look like failures and trigger a new call to editCellAt() if(!PropUtils.psCommitOnFocusLoss && !getEditor().isLastUpdateSuccessful()) { //The last update failed, we're two focus events away from really //having focus again - we'll get one, then the error dialog will //steal focus. On the second one we've got focus back. countDown = 2; } }
try { result = super.editCellAt (row, column, e); } finally { exitEditRequest();
enterEditRequest(); if (!requestFocusInWindow()) { requestFocus(); boolean wasEditing = isEditing(); removeEditor(); int prevSel = getSelectedRow(); changeSelection(row, col, false, false); final boolean editorChange = wasEditing && isCellEditable(row, col); enterEditorChangeRequest(); exitEditRequest(); } finally { if (editorChange) { exitEditorChangeRequest();
public void actionPerformed(ActionEvent e) { int next = getSelectedRow() + (direction ? 1 : -1); if (next >= getRowCount() || next < 0) { if (!(BaseTable.this.getTopLevelAncestor() instanceof Dialog)) { next = next >= getRowCount() ? 0 : getRowCount() - 1; } else if (next >= getRowCount() || next < 0) { Container ancestor = getFocusCycleRootAncestor(); BaseTable.this.getParent()) : ancestor.getFocusTraversalPolicy().getComponentBefore(ancestor, BaseTable.this); JRootPane rp = getRootPane(); JButton jb = rp.getDefaultButton(); if (jb != null) { if (sibling == BaseTable.this) { changeSelection(direction ? 0 : getRowCount()-1, direction ? 0 : getColumnCount()-1,false,false); } else { changeSelection(next, getSelectedColumn(), false, false); getSelectionModel().setLeadSelectionIndex(next);
/** Overridden to add the entire row that was being edited to RepaintManager * as a dirty region */ public void removeEditor() { enterEditorRemoveRequest(); try { int i = editingRow; if (editorComp != null) { editorComp.removeFocusListener(this); } if (PropUtils.isLoggable(BaseTable.class)) { PropUtils.log(BaseTable.class, " removing editor"); //NOI18N } super.removeEditor(); if (i != -1) { //Do schedule a repaint for the row just in case paintRow(i); } } finally { exitEditorRemoveRequest(); } }
public void processKeyEvent(KeyEvent ke) { if (!isShowing()) { super.processKeyEvent(ke); return; } //override the default handling so that //the parent will never receive the escape key and //close a modal dialog if (ke.getKeyCode() == ke.VK_ESCAPE) { //The focus request will hide the field without focus getting //lost to somewhere else in the main window first. BaseTable.this.changeSelection (selectionBeforeLastShow, 0, false, false); BaseTable.this.requestFocus(); ke.consume(); } else if (ke.getKeyCode() == ke.VK_UP && ke.getID() == ke.KEY_PRESSED) { reverseSearch(getText()); } else if (ke.getKeyCode() == ke.VK_DOWN && ke.getID() == ke.KEY_PRESSED) { forwardSearch(getText()); } else { super.processKeyEvent(ke); if (ke.getKeyCode() != ke.VK_UP && ke.getKeyCode() != ke.VK_DOWN) { processSearchText(getText()); } } }
/** Overridden to clear the focus event countdown */ public void changeSelection (int row, int col, boolean a, boolean b) { countDown = -1; super.changeSelection(row, col, a, b); }
/** Overridden to check if the edit failed, and if so, set a focus event * countdown for re-initiating editing */ public void editingStopped(ChangeEvent e) { super.editingStopped(e); //Po Ting's request for Rave - if commit on focus loss is on, all //edits look like failures and trigger a new call to editCellAt() if(!PropUtils.psCommitOnFocusLoss && !getEditor().isLastUpdateSuccessful()) { //The last update failed, we're two focus events away from really //having focus again - we'll get one, then the error dialog will //steal focus. On the second one we've got focus back. countDown = 2; } }
result = super.editCellAt(row, column, e); } finally { exitEditRequest();
enterEditRequest(); if (e instanceof MouseEvent) { if (PropUtils.isLoggable(BaseTable.class)) { if (!requestFocusInWindow()) { requestFocus(); boolean wasEditing = isEditing(); PropUtils.log(BaseTable.class, " was already editing, removing the editor"); //NOI18N removeEditor(); int prevSel = getSelectedRow(); changeSelection(row, col, false, false); final boolean editorChange = wasEditing && isCellEditable(row,col); if (editorChange) { enterEditorChangeRequest(); if (!isKnownComponent(c)) { exitEditRequest(); } finally { if (editorChange) { exitEditorChangeRequest();
super(dm, cm, sm); getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION); setSurrendersFocusOnKeystroke(true); setCellSelectionEnabled(false); setRowSelectionAllowed(true); setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); //NOI18N putClientProperty("terminateEditOnFocusLost", PropUtils.psCommitOnFocusLoss ? Boolean.FALSE : Boolean.TRUE); //NOI18N addMouseListener(dragListener); addMouseMotionListener(dragListener); setFocusCycleRoot(true); enableEvents(AWTEvent.FOCUS_EVENT_MASK); //JDK 1.5 if (getClass() != SheetTable.class) { throw new NoClassDefFoundError(
public void actionPerformed(ActionEvent e) { int next = getSelectedRow() + (direction ? 1 : -1); if (next >= getRowCount() || next < 0) { if (!(BaseTable.this.getTopLevelAncestor() instanceof Dialog)) { next = next >= getRowCount() ? 0 : getRowCount() - 1; } else if (next >= getRowCount() || next < 0) { Container ancestor = getFocusCycleRootAncestor(); BaseTable.this.getParent()) : ancestor.getFocusTraversalPolicy().getComponentBefore(ancestor, BaseTable.this); JRootPane rp = getRootPane(); JButton jb = rp.getDefaultButton(); if (jb != null) { if (sibling == BaseTable.this) { changeSelection(direction ? 0 : getRowCount()-1, direction ? 0 : getColumnCount()-1,false,false); } else { changeSelection(next, getSelectedColumn(), false, false); getSelectionModel().setLeadSelectionIndex(next);