This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[Patch][gui] Fixes to JTable
- From: Olga Rodimina <rodimina at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 22 Dec 2004 13:13:55 -0500
- Subject: [Patch][gui] Fixes to JTable
Hi,
Here is the patch that makes improvements to JTable made my Michael
Koch.
I've added the exception handling for add/set/remove selection interval
methods. I'll be committing this patch to java-gui-branch.
--
Olga Rodimina <rodimina@redhat.com>
? .snprj
? jtable.diff
? libjava.proj
? patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.574
diff -u -r1.2660.2.574 ChangeLog
--- ChangeLog 17 Dec 2004 08:47:05 -0000 1.2660.2.574
+++ ChangeLog 22 Dec 2004 17:57:14 -0000
@@ -1,3 +1,36 @@
+2004-12-22 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JTable.java
+ (editorComp): New field.
+ (JTable): Initialize local variables and call updateUI
+ (selectionBackground): Make protected.
+ (selectionForeground): Likewise.
+ (initializeLocalVars): Create default editors and renderers,
+ initialize editingColumn, editingRow variables.
+ (createDefaultEditors): New Method.
+ (createDefaultRenderers): Likewise.
+ (createDefaultListSelectionModel): Removed
+ (createDefaultSelectionModel): New Method.
+ (createDefaultTableHeader): Likewise
+ (removeColumn): Likewise.
+ (getEditingColumn): Likewise.
+ (setEditingColumn): Likewise.
+ (getEditingRow): Likewise.
+ (setEditingRow): Likewise.
+ (getEditorComponent): Likewise.
+ (isEditing): Likewise.
+ (setDefaultEditor): Likewise.
+ (addColumnSelectionInterval): Likewise.
+ (addRowSelectionInterval): Likewise.
+ (setColumnSelectionInterval): Likewise.
+ (setRowSelectionInterval): Likewise.
+ (removeColumnSelectionInterval): Likewise.
+ (removeRowSelectionInterval): Likewise.
+ (isColumnSelected): Likewise.
+ (isRowSelected): Likewise.
+ (isCellSelected): Likewise.
+ (selectAll): Likewise.
+
2004-12-17 Michael Koch <konqueror@gmx.de>
* javax/swing/JTable.java
Index: javax/swing/JTable.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTable.java,v
retrieving revision 1.4.18.12
diff -u -r1.4.18.12 JTable.java
--- javax/swing/JTable.java 17 Dec 2004 08:47:26 -0000 1.4.18.12
+++ javax/swing/JTable.java 22 Dec 2004 17:57:39 -0000
@@ -42,6 +42,7 @@
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
+import java.util.Date;
import java.util.Hashtable;
import java.util.Vector;
@@ -113,14 +114,35 @@
/**
* A table mapping {@link java.lang.Class} objects to
* {@link TableCellEditor} objects. This table is consulted by the
- *
+ * FIXME
*/
protected Hashtable defaultEditorsByColumnClass;
+
+ /**
+ * A table mapping {@link java.lang.Class} objects to
+ * {@link TableCellEditor} objects. This table is consulted by the
+ * FIXME
+ */
protected Hashtable defaultRenderersByColumnClass;
+
+ /**
+ * The column that is edited, -1 if the table is not edited currently.
+ */
protected int editingColumn;
+
+ /**
+ * The row that is edited, -1 if the table is not edited currently.
+ */
protected int editingRow;
/**
+ * The component that is used for editing.
+ * <code>null</code> if the table is not editing currently.
+ *
+ */
+ protected transient Component editorComp;
+
+ /**
* Whether or not the table should automatically compute a matching
* {@link TableColumnModel} and assign it to the {@link #columnModel}
* property when the {@link #dataModel} property is changed.
@@ -163,8 +185,8 @@
*
* @see #setRowMargin()
* @see #getRowHeight()
- * @see #getInterCellSpacing()
- * @see #setInterCellSpacing()
+ * @see #getIntercellSpacing()
+ * @see #setIntercellSpacing()
* @see TableColumnModel#getColumnMargin()
* @see TableColumnModel#setColumnMargin()
*/
@@ -285,7 +307,7 @@
* @see #setSelectionBackground()
* @see #getSelectionBackground()
*/
- Color selectionBackground;
+ protected Color selectionBackground;
/**
* The name carried in property change events when the {@link
@@ -301,7 +323,7 @@
* @see #setSelectionForeground()
* @see #getSelectionForeground()
*/
- Color selectionForeground;
+ protected Color selectionForeground;
/**
* The name carried in property change events when the
@@ -386,11 +408,17 @@
public JTable (TableModel dm, TableColumnModel cm, ListSelectionModel sm)
{
this.dataModel = dm == null ? createDefaultDataModel() : dm;
- setSelectionModel(sm == null ? createDefaultListSelectionModel() : sm);
+ setSelectionModel(sm == null ? createDefaultSelectionModel() : sm);
this.columnModel = cm;
+ initializeLocalVars();
+ updateUI();
+ }
+
+ protected void initializeLocalVars()
+ {
this.autoCreateColumnsFromModel = false;
- if (cm == null)
+ if (columnModel == null)
{
this.autoCreateColumnsFromModel = true;
createColumnsFromModel();
@@ -398,7 +426,10 @@
this.columnModel.addColumnModelListener(this);
this.defaultRenderersByColumnClass = new Hashtable();
+ createDefaultRenderers();
+
this.defaultEditorsByColumnClass = new Hashtable();
+ createDefaultEditors();
this.autoResizeMode = AUTO_RESIZE_ALL_COLUMNS;
this.rowHeight = 16;
@@ -410,9 +441,10 @@
this.preferredScrollableViewportSize = new Dimension(450,400);
this.showHorizontalLines = true;
this.showVerticalLines = true;
+ this.editingColumn = -1;
+ this.editingRow = -1;
setIntercellSpacing(new Dimension(1,1));
- setTableHeader(new JTableHeader(columnModel));
- updateUI();
+ setTableHeader(createDefaultTableHeader());
}
/**
@@ -436,6 +468,16 @@
columnModel.addColumn(column);
}
+
+ protected void createDefaultEditors()
+ {
+ //FIXME: Create the editor object.
+ }
+
+ protected void createDefaultRenderers()
+ {
+ //FIXME: Create the renderer object.
+ }
/**
* @deprecated 1.0.2, replaced by <code>new JScrollPane(JTable)</code>
@@ -444,7 +486,7 @@
{
return new JScrollPane(table);
}
-
+
protected TableColumnModel createDefaultColumnModel()
{
return new DefaultTableColumnModel();
@@ -455,11 +497,16 @@
return new DefaultTableModel();
}
- protected ListSelectionModel createDefaultListSelectionModel()
+ protected ListSelectionModel createDefaultSelectionModel()
{
return new DefaultListSelectionModel();
}
+ protected JTableHeader createDefaultTableHeader()
+ {
+ return new JTableHeader(columnModel);
+ }
+
private void createColumnsFromModel()
{
if (dataModel == null)
@@ -667,6 +714,7 @@
return (TableCellEditor) defaultEditorsByColumnClass.get(columnClass);
else
{
+ // FIXME: We have at least an editor for Object.class in our defaults.
TableCellEditor r = new DefaultCellEditor(new JTextField());
defaultEditorsByColumnClass.put(columnClass, r);
return r;
@@ -1083,6 +1131,12 @@
return tableHeader;
}
+ public void removeColumn(TableColumn column)
+ {
+ // FIXME: Implement me.
+ throw new Error("not implemented");
+ }
+
/**
* Set the value of the {@link #autoCreateColumnsFromModel} property.
*
@@ -1613,4 +1667,117 @@
{
return dataModel.getColumnName(column);
}
+
+ public int getEditingColumn()
+ {
+ return editingColumn;
+ }
+
+ public void setEditingColumn(int column)
+ {
+ editingColumn = column;
+ }
+
+ public int getEditingRow()
+ {
+ return editingRow;
+ }
+
+ public void setEditingRow(int column)
+ {
+ editingRow = column;
+ }
+
+ public Component getEditorComponent()
+ {
+ return editorComp;
+ }
+
+ public boolean isEditing()
+ {
+ return editorComp != null;
+ }
+
+ public void setDefaultEditor(Class columnClass, TableCellEditor editor)
+ {
+ if (editor != null)
+ defaultEditorsByColumnClass.put(columnClass, editor);
+ else
+ defaultEditorsByColumnClass.remove(columnClass);
+ }
+
+ public void addColumnSelectionInterval(int index0, int index1)
+ {
+ if ((index0 < 0 || index0 > (getColumnCount()-1)
+ || index1 < 0 || index1 > (getColumnCount()-1)))
+ throw new IllegalArgumentException("Column index out of range.");
+
+ getColumnModel().getSelectionModel().addSelectionInterval(index0, index1);
+ }
+
+ public void addRowSelectionInterval(int index0, int index1)
+ {
+ if ((index0 < 0 || index0 > (getRowCount()-1)
+ || index1 < 0 || index1 > (getRowCount()-1)))
+ throw new IllegalArgumentException("Row index out of range.");
+
+ getSelectionModel().addSelectionInterval(index0, index1);
+ }
+
+ public void setColumnSelectionInterval(int index0, int index1)
+ {
+ if ((index0 < 0 || index0 > (getColumnCount()-1)
+ || index1 < 0 || index1 > (getColumnCount()-1)))
+ throw new IllegalArgumentException("Column index out of range.");
+
+ getColumnModel().getSelectionModel().setSelectionInterval(index0, index1);
+ }
+
+ public void setRowSelectionInterval(int index0, int index1)
+ {
+ if ((index0 < 0 || index0 > (getRowCount()-1)
+ || index1 < 0 || index1 > (getRowCount()-1)))
+ throw new IllegalArgumentException("Row index out of range.");
+
+ getSelectionModel().setSelectionInterval(index0, index1);
+ }
+
+ public void removeColumnSelectionInterval(int index0, int index1)
+ {
+ if ((index0 < 0 || index0 > (getColumnCount()-1)
+ || index1 < 0 || index1 > (getColumnCount()-1)))
+ throw new IllegalArgumentException("Column index out of range.");
+
+ getColumnModel().getSelectionModel().removeSelectionInterval(index0, index1);
+ }
+
+ public void removeRowSelectionInterval(int index0, int index1)
+ {
+ if ((index0 < 0 || index0 > (getRowCount()-1)
+ || index1 < 0 || index1 > (getRowCount()-1)))
+ throw new IllegalArgumentException("Row index out of range.");
+
+ getSelectionModel().removeSelectionInterval(index0, index1);
+ }
+
+ public boolean isColumnSelected(int column)
+ {
+ return getColumnModel().getSelectionModel().isSelectedIndex(column);
+ }
+
+ public boolean isRowSelected(int row)
+ {
+ return getSelectionModel().isSelectedIndex(row);
+ }
+
+ public boolean isCellSelected(int row, int column)
+ {
+ return isRowSelected(row) && isColumnSelected(column);
+ }
+
+ public void selectAll()
+ {
+ setColumnSelectionInterval(0, getColumnCount() - 1);
+ setRowSelectionInterval(0, getRowCount() - 1);
+ }
}