This patch add the multi-editor support for JTable. The table now
supports the two editors: text and boolean. The boolean values are
rendered and edited using JCheckBox.
I add the more complicated table example to the Swing demo to show the
table with header, multiple data types (text and boolean at the moment)
and placed int the scroll window. The editing seems working as expected
but the attempt to scroll transiently displays the old (unedited)
values. As any forced repainting (resizing, temporary obstruction with
other window) displays the updated values again, this may be the problem
somewhere in the JScrollPane.
2006-01-19 Audrius Meskauskas [EMAIL PROTECTED]
* javax/swing/JTable.java (editingStopped, editingCancelled):
Repaint the edited cell.
(setValueAt): Do not add the value object to this container.
(editorTimer, rowBeingEdited, columnBeingEdited, oldCellValue): Removed.
(editingStopped): Use editingRow, editingColumn and not
rowBeingEdited, columnBeingEdited. (editValueAt): rewritten.
(doLayout): Move the editor component, if present, into the new
location and call repaint(). (moveToCellBeingEdited): new method.
(TableTextField): new inner class.
(getDefaultEditor): Instantiante TableTextField, not JTextField.
(setValueAt): Repaint the changed segment.
(createDefaultEditors): Implemented.
(BooleanCellRenderer): Center the checkbox and use the default
foreground
and background colors.
* javax/swing/plaf/basic/BasicTableUI.java
(paintCell): Do not paint the caret here. Do not accept unused
parameters.
(paint): No need to allocate rectangle for each cell.
* javax/swing/DefaultCellEditor.java: Rewritten.
* examples/gnu/classpath/examples/swing/Demo.java (mkTable):
Use TableDemo.java table example.
* examples/gnu/classpath/examples/swing/TableDemo.java: New file.
Index: javax/swing/DefaultCellEditor.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/DefaultCellEditor.java,v
retrieving revision 1.17
diff -u -r1.17 DefaultCellEditor.java
--- javax/swing/DefaultCellEditor.java 16 Jan 2006 12:36:50 - 1.17
+++ javax/swing/DefaultCellEditor.java 19 Jan 2006 12:13:08 -
@@ -59,8 +59,7 @@
* some standard object types.
*
* @author Andrew Selkirk
- *
- * @status mostly unimplemented
+ * @author Audrius Meskauskas
*/
public class DefaultCellEditor
extends AbstractCellEditor
@@ -76,10 +75,13 @@
protected class EditorDelegate
implements ActionListener, ItemListener, Serializable
{
+/**
+ * Use the serial version UID for interoperability.
+ */
private static final long serialVersionUID = -1420007406015481933L;
/**
- * value
+ * The object value (updated when getting and setting the value).
*/
protected Object value;
@@ -90,28 +92,30 @@
{
// Nothing to do here.
}
-
+
/**
- * setValue
+ * Set the value for the editor component. This method is normally
+ * overridden to set the value in the way, specific for the text
+ * component, check box or combo box.
*
- * @param value TODO
+ * @param aValue the value to set (String, Boolean or Number).
*/
-public void setValue(Object value)
+public void setValue(Object aValue)
{
- // TODO: should be setting the value in the editorComp
- this.value = value;
+ value = aValue;
}
- /**
- * getCellEditorValue
- *
- * @returns Object
+/**
+ * Get the value for the editor component. This method is normally
+ * overridden to obtain the value in the way, specific for the text
+ * component, check box or combo box.
+ *
+ * @return value the value of the component (String, Boolean or Number).
*/
public Object getCellEditorValue()
{
- // TODO: should be getting the updated value from the editorComp
return value;
-} // getCellEditorValue()
+}
/**
* isCellEditable
@@ -208,16 +212,132 @@
listeners[index].editingCanceled(changeEvent);
}
} // EditorDelegate
+
+ /**
+ * Provides getter and setter methods to work with the text component.
+ *
+ * @author Audrius Meskauskas ([EMAIL PROTECTED])
+ */
+ private class JTextFieldDelegate extends EditorDelegate
+ {
+/**
+ * Use the serial version UID for interoperability.
+ */
+private static final long serialVersionUID = 1;
+
+/**
+ * Set the value for the editor component.
+ *
+ * @param aValue the value to set (toString() will be called).
+ */
+public void setValue(Object aValue)
+{
+ value = aValue;
+ JTextField f = (JTextField) editorComponent;
+ if (value == null)
+f.setText();
+ else
+f.setText(value.toString());
+}
- /**
+/**
+ * Get the value for the editor component.