2006-05-23 Audrius Meskauskas <[EMAIL PROTECTED]>
PR 27680
* javax/swing/JTable.java (booleanInvertingEditor): New field.
(defaultEditorsByColumnClass, defaultRenderersByColumnClass):
Initialise in constructor. (columnMoved): Cancel editing.
(createDefaultEditors): Rewritten. (editCellAt):
Just invert the value if this is a boolean cell.
(initialiseLocalVars): Do not initialise renderer and editor tables.
(setUI): Create editors and renderers here.
Index: JTable.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.107
diff -u -r1.107 JTable.java
--- JTable.java 23 May 2006 10:34:02 -0000 1.107
+++ JTable.java 23 May 2006 12:47:21 -0000
@@ -1368,14 +1368,14 @@
* [EMAIL PROTECTED] TableCellEditor} objects. This table is consulted by the
* FIXME
*/
- protected Hashtable defaultEditorsByColumnClass;
+ protected Hashtable defaultEditorsByColumnClass = new Hashtable();
/**
* A table mapping [EMAIL PROTECTED] java.lang.Class} objects to
* [EMAIL PROTECTED] TableCellEditor} objects. This table is consulted by the
* FIXME
*/
- protected Hashtable defaultRenderersByColumnClass;
+ protected Hashtable defaultRenderersByColumnClass = new Hashtable();
/**
* The column that is edited, -1 if the table is not edited currently.
@@ -1634,7 +1634,13 @@
* @see #setRowHeight(int, int)
*/
private SizeSequence rowHeights;
-
+
+ /**
+ * This editor serves just a marker that the value must be simply changed to
+ * the opposite one instead of starting the editing session.
+ */
+ private transient TableCellEditor booleanInvertingEditor;
+
/**
* Creates a new <code>JTable</code> instance.
*/
@@ -1767,12 +1773,6 @@
if (autoCreateColumnsFromModel)
createDefaultColumnsFromModel();
this.columnModel.addColumnModelListener(this);
-
- this.defaultRenderersByColumnClass = new Hashtable();
- createDefaultRenderers();
-
- this.defaultEditorsByColumnClass = new Hashtable();
- createDefaultEditors();
this.autoResizeMode = AUTO_RESIZE_SUBSEQUENT_COLUMNS;
setRowHeight(16);
@@ -1821,7 +1821,10 @@
protected void createDefaultEditors()
{
JCheckBox box = new BooleanCellRenderer().getCheckBox();
- setDefaultEditor(Boolean.class, new DefaultCellEditor(box));
+ box.setBorder(BorderFactory.createLineBorder(getGridColor(), 2));
+ box.setBorderPainted(true);
+ booleanInvertingEditor = new DefaultCellEditor(box);
+ setDefaultEditor(Boolean.class, booleanInvertingEditor);
}
/**
@@ -1919,6 +1922,8 @@
*/
public void columnMoved (TableColumnModelEvent event)
{
+ if (isEditing())
+ editingCanceled(null);
revalidate();
repaint();
}
@@ -3494,6 +3499,10 @@
public void setUI(TableUI ui)
{
super.setUI(ui);
+ // The editors and renderers must be recreated because they constructors
+ // may use the look and feel properties.
+ createDefaultEditors();
+ createDefaultRenderers();
}
public void updateUI()
@@ -3859,30 +3868,45 @@
/**
* Programmatically starts editing the specified cell.
- *
+ *
* @param row the row of the cell to edit.
* @param column the column of the cell to edit.
*/
- public boolean editCellAt (int row, int column)
+ public boolean editCellAt(int row, int column)
{
// Complete the previous editing session, if still active.
if (isEditing())
editingStopped(new ChangeEvent("editingStopped"));
-
- editingRow = row;
- editingColumn = column;
- setCellEditor(getCellEditor(row, column));
- editorComp = prepareEditor(cellEditor, row, column);
+ TableCellEditor editor = getCellEditor(row, column);
- // Remove the previous editor components, if present. Only one
- // editor component at time is allowed in the table.
- removeAll();
- add(editorComp);
- moveToCellBeingEdited(editorComp);
- scrollRectToVisible(editorComp.getBounds());
- editorComp.requestFocusInWindow();
- return true;
+ // The boolean values are inverted by the single click without the
+ // real editing session.
+ if (editor == booleanInvertingEditor && isCellEditable(row, column))
+ {
+ if (Boolean.TRUE.equals(getValueAt(row, column)))
+ setValueAt(Boolean.FALSE, row, column);
+ else
+ setValueAt(Boolean.TRUE, row, column);
+ return false;
+ }
+ else
+ {
+ editingRow = row;
+ editingColumn = column;
+
+ setCellEditor(editor);
+ editorComp = prepareEditor(cellEditor, row, column);
+
+ // Remove the previous editor components, if present. Only one
+ // editor component at time is allowed in the table.
+ removeAll();
+ add(editorComp);
+ moveToCellBeingEdited(editorComp);
+ scrollRectToVisible(editorComp.getBounds());
+ editorComp.requestFocusInWindow();
+ return true;
+ }
}
/**