diff options
Diffstat (limited to 'libjava/classpath/javax/swing/table')
11 files changed, 3426 insertions, 0 deletions
diff --git a/libjava/classpath/javax/swing/table/AbstractTableModel.java b/libjava/classpath/javax/swing/table/AbstractTableModel.java new file mode 100644 index 0000000..3e9f6e9 --- /dev/null +++ b/libjava/classpath/javax/swing/table/AbstractTableModel.java @@ -0,0 +1,301 @@ +/* AbstractTableModel.java -- + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.io.Serializable; +import java.util.EventListener; + +import javax.swing.event.EventListenerList; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; + +/** + * A base class that can be used to create implementations of the + * {@link TableModel} interface. + * + * @author Andrew Selkirk + */ +public abstract class AbstractTableModel implements TableModel, Serializable +{ + static final long serialVersionUID = -5798593159423650347L; + + /** + * Storage for the listeners registered with this model. + */ + protected EventListenerList listenerList = new EventListenerList(); + + /** + * Creates a default instance. + */ + public AbstractTableModel() + { + // no setup required here + } + + /** + * Returns the name of the specified column. This method generates default + * names in a sequence (starting with column 0): A, B, C, ..., Z, AA, AB, + * AC, ..., AZ, BA, BB, BC, and so on. Subclasses may override this method + * to allow column names to be specified on some other basis. + * + * @param columnIndex the column index. + * + * @return The name of the column. + */ + public String getColumnName(int columnIndex) + { + StringBuffer buffer = new StringBuffer(); + while (columnIndex >= 0) + { + buffer.insert (0, (char) ('A' + columnIndex % 26)); + columnIndex = columnIndex / 26 - 1; + } + return buffer.toString(); + } + + /** + * Return the index of the specified column, or <code>-1</code> if there is + * no column with the specified name. + * + * @param columnName the name of the column (<code>null</code> not permitted). + * + * @return The index of the column, -1 if not found. + * + * @see #getColumnName(int) + * @throws NullPointerException if <code>columnName</code> is + * <code>null</code>. + */ + public int findColumn(String columnName) + { + int count = getColumnCount(); + + for (int index = 0; index < count; index++) + { + String name = getColumnName(index); + + if (columnName.equals(name)) + return index; + } + + // Unable to locate. + return -1; + } + + /** + * Returns the <code>Class</code> for all <code>Object</code> instances + * in the specified column. + * + * @param columnIndex the column index. + * + * @return The class. + */ + public Class getColumnClass(int columnIndex) + { + return Object.class; + } + + /** + * Returns <code>true</code> if the specified cell is editable, and + * <code>false</code> if it is not. This implementation returns + * <code>false</code> for all arguments, subclasses should override the + * method if necessary. + * + * @param rowIndex the row index of the cell. + * @param columnIndex the column index of the cell. + * + * @return <code>false</code>. + */ + public boolean isCellEditable(int rowIndex, int columnIndex) + { + return false; + } + + /** + * Sets the value of the given cell. This implementation ignores all + * arguments and does nothing, subclasses should override the + * method if necessary. + * + * @param value the new value (<code>null</code> permitted). + * @param rowIndex the row index of the cell. + * @param columnIndex the column index of the cell. + */ + public void setValueAt(Object value, int rowIndex, int columnIndex) + { + // Do nothing... + } + + /** + * Adds a listener to the table model. The listener will receive notification + * of all changes to the table model. + * + * @param listener the listener. + */ + public void addTableModelListener(TableModelListener listener) + { + listenerList.add(TableModelListener.class, listener); + } + + /** + * Removes a listener from the table model so that it will no longer receive + * notification of changes to the table model. + * + * @param listener the listener to remove. + */ + public void removeTableModelListener(TableModelListener listener) + { + listenerList.remove(TableModelListener.class, listener); + } + + /** + * Returns an array containing the listeners that have been added to the + * table model. + * + * @return Array of {@link TableModelListener} objects. + * + * @since 1.4 + */ + public TableModelListener[] getTableModelListeners() + { + return (TableModelListener[]) + listenerList.getListeners(TableModelListener.class); + } + + /** + * Sends a {@link TableModelEvent} to all registered listeners to inform + * them that the table data has changed. + */ + public void fireTableDataChanged() + { + fireTableChanged(new TableModelEvent(this, 0, Integer.MAX_VALUE)); + } + + /** + * Sends a {@link TableModelEvent} to all registered listeners to inform + * them that the table structure has changed. + */ + public void fireTableStructureChanged() + { + fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW)); + } + + /** + * Sends a {@link TableModelEvent} to all registered listeners to inform + * them that some rows have been inserted into the model. + * + * @param firstRow the index of the first row. + * @param lastRow the index of the last row. + */ + public void fireTableRowsInserted (int firstRow, int lastRow) + { + fireTableChanged(new TableModelEvent(this, firstRow, lastRow, + TableModelEvent.ALL_COLUMNS, + TableModelEvent.INSERT)); + } + + /** + * Sends a {@link TableModelEvent} to all registered listeners to inform + * them that some rows have been updated. + * + * @param firstRow the index of the first row. + * @param lastRow the index of the last row. + */ + public void fireTableRowsUpdated (int firstRow, int lastRow) + { + fireTableChanged(new TableModelEvent(this, firstRow, lastRow, + TableModelEvent.ALL_COLUMNS, + TableModelEvent.UPDATE)); + } + + /** + * Sends a {@link TableModelEvent} to all registered listeners to inform + * them that some rows have been deleted from the model. + * + * @param firstRow the index of the first row. + * @param lastRow the index of the last row. + */ + public void fireTableRowsDeleted(int firstRow, int lastRow) + { + fireTableChanged(new TableModelEvent(this, firstRow, lastRow, + TableModelEvent.ALL_COLUMNS, + TableModelEvent.DELETE)); + } + + /** + * Sends a {@link TableModelEvent} to all registered listeners to inform + * them that a single cell has been updated. + * + * @param row the row index. + * @param column the column index. + */ + public void fireTableCellUpdated (int row, int column) + { + fireTableChanged(new TableModelEvent(this, row, row, column)); + } + + /** + * Sends the specified event to all registered listeners. + * + * @param event the event to send. + */ + public void fireTableChanged(TableModelEvent event) + { + int index; + TableModelListener listener; + Object[] list = listenerList.getListenerList(); + + for (index = 0; index < list.length; index += 2) + { + listener = (TableModelListener) list [index + 1]; + listener.tableChanged (event); + } + } + + /** + * Returns an array of listeners of the given type that are registered with + * this model. + * + * @param listenerType the listener class. + * + * @return An array of listeners (possibly empty). + */ + public EventListener[] getListeners(Class listenerType) + { + return listenerList.getListeners(listenerType); + } +} diff --git a/libjava/classpath/javax/swing/table/DefaultTableCellRenderer.java b/libjava/classpath/javax/swing/table/DefaultTableCellRenderer.java new file mode 100644 index 0000000..02e9fd7 --- /dev/null +++ b/libjava/classpath/javax/swing/table/DefaultTableCellRenderer.java @@ -0,0 +1,234 @@ +/* DefaultTableCellRenderer.java -- + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Rectangle; +import java.io.Serializable; + +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; + +/** + * Class to display every cells. + */ +public class DefaultTableCellRenderer extends JLabel + implements TableCellRenderer, Serializable +{ + static final long serialVersionUID = 7878911414715528324L; + + protected static Border noFocusBorder = new EmptyBorder(0, 0, 0, 0); + + public static class UIResource extends DefaultTableCellRenderer + implements javax.swing.plaf.UIResource + { + public UIResource() + { + } + } + + /** + * Creates a default table cell renderer with an empty border. + */ + public DefaultTableCellRenderer() + { + super(); + } + + /** + * Assign the unselected-foreground. + * + * @param c the color to assign + */ + public void setForeground(Color c) + { + super.setForeground(c); + } + + /** + * Assign the unselected-background. + * + * @param c the color to assign + */ + public void setBackground(Color c) + { + super.setBackground(c); + } + + /** + * Look and feel has changed. + * + * <p>Replaces the current UI object with the latest version from + * the UIManager.</p> + */ + public void updateUI() + { + super.updateUI(); + } + + /** + * Get the string value of the object and pass it to setText(). + * + * @param table the JTable + * @param value the value of the object + * @param isSelected is the cell selected? + * @param hasFocus has the cell the focus? + * @param row the row to render + * @param column the cell to render + * + * @return this component (the default table cell renderer) + */ + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, + boolean hasFocus, + int row, int column) + { + if (value != null) + super.setText(value.toString()); + + setOpaque(true); + + if (table == null) + return this; + + if (isSelected) + { + setBackground(table.getSelectionBackground()); + setForeground(table.getSelectionForeground()); + } + else + { + setBackground(table.getBackground()); + setForeground(table.getForeground()); + } + + setEnabled(table.isEnabled()); + setFont(table.getFont()); + return this; + } + + /** + * Overriden for performance. + * + * <p>This method needs to be overridden in a subclass to actually + * do something.</p> + * + * @return always true + */ + public boolean isOpaque() + { + return true; + } + + /** + * Overriden for performance. + * + * <p>This method needs to be overridden in a subclass to actually + * do something.</p> + */ + public void validate() + { + // Does nothing. + } + + public void revalidate() + { + // Does nothing. + } + + /** + * Overriden for performance. + * + * <p>This method needs to be overridden in a subclass to actually + * do something.</p> + */ + public void repaint(long tm, int x, int y, int width, int height) + { + // Does nothing. + } + + /** + * Overriden for performance. + * + * <p>This method needs to be overridden in a subclass to actually + * do something.</p> + */ + public void repaint(Rectangle r) + { + // Does nothing. + } + + /** + * Overriden for performance. + * + * <p>This method needs to be overridden in a subclass to actually + * do something.</p> + */ + protected void firePropertyChange(String propertyName, Object oldValue, + Object newValue) + { + // Does nothing. + } + + /** + * Overriden for performance. + * + * <p>This method needs to be overridden in a subclass to actually + * do something.</p> + */ + public void firePropertyChange(String propertyName, boolean oldValue, + boolean newValue) + { + // Does nothing. + } + + /** + * Sets the String for this cell. + * + * @param value the string value for this cell; if value is null it + * sets the text value to an empty string + */ + protected void setValue(Object value) + { + super.setText((value!=null) ? value.toString() : ""); + } +} diff --git a/libjava/classpath/javax/swing/table/DefaultTableColumnModel.java b/libjava/classpath/javax/swing/table/DefaultTableColumnModel.java new file mode 100644 index 0000000..1087177 --- /dev/null +++ b/libjava/classpath/javax/swing/table/DefaultTableColumnModel.java @@ -0,0 +1,563 @@ +/* DefaultTableColumnModel.java -- + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.util.Enumeration; +import java.util.EventListener; +import java.util.Vector; + +import javax.swing.DefaultListSelectionModel; +import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.EventListenerList; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableColumnModelEvent; +import javax.swing.event.TableColumnModelListener; + +/** + * DefaultTableColumnModel + * @author Andrew Selkirk + * @version 1.0 + */ +public class DefaultTableColumnModel + implements TableColumnModel, PropertyChangeListener, ListSelectionListener, + Serializable +{ + private static final long serialVersionUID = 6580012493508960512L; + + /** + * Columns that this model keeps track of. + */ + protected Vector tableColumns; + + /** + * Selection Model that keeps track of columns selection + */ + protected ListSelectionModel selectionModel; + + /** + * Space between two columns. By default it is set to 1 + */ + protected int columnMargin; + + /** + * listenerList keeps track of all listeners registered with this model + */ + protected EventListenerList listenerList = new EventListenerList(); + + /** + * changeEvent is fired when change occurs in one of the columns properties + */ + protected transient ChangeEvent changeEvent = new ChangeEvent(this); + + /** + * Indicates whether columns can be selected + */ + protected boolean columnSelectionAllowed; + + /** + * Total width of all the columns in this model + */ + protected int totalColumnWidth; + + /** + * Constructor DefaultTableColumnModel + */ + public DefaultTableColumnModel() + { + tableColumns = new Vector(); + setSelectionModel(createSelectionModel()); + columnMargin = 1; + columnSelectionAllowed = false; + } + + /** + * addColumn adds column to the model. This method fires ColumnAdded + * event to model's registered TableColumnModelListeners. + * + * @param col column to add + */ + public void addColumn(TableColumn col) + { + if (col == null) + throw new IllegalArgumentException("Null 'col' argument."); + tableColumns.add(col); + invalidateWidthCache(); + fireColumnAdded(new TableColumnModelEvent(this, 0, tableColumns.size() - 1)); + } + + /** + * removeColumn removes table column from the model. This method fires + * ColumnRemoved event to model's registered TableColumnModelListeners. + * + * @param col column to be removed + */ + public void removeColumn(TableColumn col) + { + int index = this.tableColumns.indexOf(col); + if (index < 0) + return; + fireColumnRemoved(new TableColumnModelEvent(this, index, 0)); + tableColumns.remove(col); + invalidateWidthCache(); + } + + /** + * moveColumn moves column at index i to index j. This method fires + * ColumnMoved event to model's registered TableColumnModelListeners. + * + * @param i index of the column that will be moved + * @param j index of column's new location + */ + public void moveColumn(int i, int j) + { + int columnCount = getColumnCount(); + if (i < 0 || i >= columnCount) + throw new IllegalArgumentException("Index 'i' out of range."); + if (j < 0 || j >= columnCount) + throw new IllegalArgumentException("Index 'j' out of range."); + Object column = tableColumns.remove(i); + tableColumns.add(j, column); + fireColumnAdded(new TableColumnModelEvent(this, i, j)); + } + + /** + * setColumnMargin sets margin of the columns. + * @param m new column margin + */ + public void setColumnMargin(int m) + { + columnMargin = m; + fireColumnMarginChanged(); + } + + /** + * getColumnCount returns number of columns in the model + * @return int number of columns in the model + */ + public int getColumnCount() + { + return tableColumns.size(); + } + + /** + * getColumns + * @return Enumeration + */ + public Enumeration getColumns() + { + return tableColumns.elements(); + } + + /** + * Returns the index of the {@link TableColumn} with the given identifier. + * + * @param identifier the identifier (<code>null</code> not permitted). + * + * @return The index of the {@link TableColumn} with the given identifier. + * + * @throws IllegalArgumentException if <code>identifier</code> is + * <code>null</code> or there is no column with that identifier. + */ + public int getColumnIndex(Object identifier) + { + if (identifier == null) + throw new IllegalArgumentException("Null identifier."); + int columnCount = tableColumns.size(); + for (int i = 0; i < columnCount; i++) + { + TableColumn tc = (TableColumn) tableColumns.get(i); + if (identifier.equals(tc.getIdentifier())) + return i; + } + throw new IllegalArgumentException("No TableColumn with that identifier."); + } + + /** + * getColumn returns column at the specified index + * @param i index of the column + * @return TableColumn column at the specified index + */ + public TableColumn getColumn(int i) + { + return (TableColumn) tableColumns.get(i); + } + + /** + * getColumnMargin returns column margin + * @return int column margin + */ + public int getColumnMargin() + { + return columnMargin; + } + + /** + * getColumnIndexAtX returns column that contains specified x-coordinate. + * @param x x-coordinate that column should contain + * @return int index of the column that contains specified x-coordinate relative + * to this column model + */ + public int getColumnIndexAtX(int x) + { + for (int i = 0; i < tableColumns.size(); ++i) + { + int w = ((TableColumn)tableColumns.get(i)).getWidth(); + if (0 <= x && x < w) + return i; + else + x -= w; + } + return -1; + } + + /** + * getTotalColumnWidth returns total width of all the columns including + * column's margins. + * + * @return total width of all the columns + */ + public int getTotalColumnWidth() + { + if (totalColumnWidth == -1) + recalcWidthCache(); + return totalColumnWidth; + } + + /** + * setSelectionModel sets selection model that will be used by this ColumnTableModel + * to keep track of currently selected columns + * + * @param model new selection model + * @exception IllegalArgumentException if model is null + */ + public void setSelectionModel(ListSelectionModel model) + { + if (model == null) + throw new IllegalArgumentException(); + + selectionModel = model; + selectionModel.addListSelectionListener(this); + } + + /** + * getSelectionModel returns selection model + * @return ListSelectionModel selection model + */ + public ListSelectionModel getSelectionModel() + { + return selectionModel; + } + + /** + * setColumnSelectionAllowed sets whether column selection is allowed + * or not. + * + * @param flag true if column selection is allowed and false otherwise + */ + public void setColumnSelectionAllowed(boolean flag) + { + columnSelectionAllowed = flag; + } + + /** + * getColumnSelectionAllowed indicates whether column selection is + * allowed or not. + * + * @return boolean true if column selection is allowed and false otherwise. + */ + public boolean getColumnSelectionAllowed() + { + return columnSelectionAllowed; + } + + /** + * getSelectedColumns returns array containing indexes of currently + * selected columns + * + * @return int[] array containing indexes of currently selected columns + */ + public int[] getSelectedColumns() + { + // FIXME: Implementation of this method was taken from private method + // JTable.getSelections(), which is used in various places in JTable + // including selected row calculations and cannot be simply removed. + // This design should be improved to illuminate duplication of code. + + ListSelectionModel lsm = this.selectionModel; + int sz = getSelectedColumnCount(); + int [] ret = new int[sz]; + + int lo = lsm.getMinSelectionIndex(); + int hi = lsm.getMaxSelectionIndex(); + int j = 0; + java.util.ArrayList ls = new java.util.ArrayList(); + if (lo != -1 && hi != -1) + { + switch (lsm.getSelectionMode()) + { + case ListSelectionModel.SINGLE_SELECTION: + ret[0] = lo; + break; + + case ListSelectionModel.SINGLE_INTERVAL_SELECTION: + for (int i = lo; i <= hi; ++i) + ret[j++] = i; + break; + + case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION: + for (int i = lo; i <= hi; ++i) + if (lsm.isSelectedIndex(i)) + ret[j++] = i; + break; + } + } + return ret; + } + + /** + * getSelectedColumnCount returns number of currently selected columns + * @return int number of currently selected columns + */ + public int getSelectedColumnCount() + { + // FIXME: Implementation of this method was taken from private method + // JTable.countSelections(), which is used in various places in JTable + // including selected row calculations and cannot be simply removed. + // This design should be improved to illuminate duplication of code. + + ListSelectionModel lsm = this.selectionModel; + int lo = lsm.getMinSelectionIndex(); + int hi = lsm.getMaxSelectionIndex(); + int sum = 0; + + if (lo != -1 && hi != -1) + { + switch (lsm.getSelectionMode()) + { + case ListSelectionModel.SINGLE_SELECTION: + sum = 1; + break; + + case ListSelectionModel.SINGLE_INTERVAL_SELECTION: + sum = hi - lo + 1; + break; + + case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION: + for (int i = lo; i <= hi; ++i) + if (lsm.isSelectedIndex(i)) + ++sum; + break; + } + } + + return sum; + } + + /** + * addColumnModelListener adds specified listener to the model's + * listener list + * + * @param listener the listener to add + */ + public void addColumnModelListener(TableColumnModelListener listener) + { + listenerList.add(TableColumnModelListener.class, listener); + } + + /** + * removeColumnModelListener removes specified listener from the model's + * listener list. + * + * @param listener the listener to remove + */ + public void removeColumnModelListener(TableColumnModelListener listener) + { + listenerList.remove(TableColumnModelListener.class, listener); + } + + /** + * @since 1.4 + */ + public TableColumnModelListener[] getColumnModelListeners() + { + return (TableColumnModelListener[]) + listenerList.getListeners(TableColumnModelListener.class); + } + + /** + * fireColumnAdded fires TableColumnModelEvent to registered + * TableColumnModelListeners to indicate that column was added + * + * @param e TableColumnModelEvent + */ + protected void fireColumnAdded(TableColumnModelEvent e) + { + TableColumnModelListener[] listeners = getColumnModelListeners(); + + for (int i=0; i< listeners.length; i++) + listeners[i].columnAdded(e); + } + + /** + * fireColumnAdded fires TableColumnModelEvent to registered + * TableColumnModelListeners to indicate that column was removed + * + * @param e TableColumnModelEvent + */ + protected void fireColumnRemoved(TableColumnModelEvent e) + { + TableColumnModelListener[] listeners = getColumnModelListeners(); + + for (int i=0; i< listeners.length; i++) + listeners[i].columnRemoved(e); + } + + /** + * fireColumnAdded fires TableColumnModelEvent to registered + * TableColumnModelListeners to indicate that column was moved + * + * @param e TableColumnModelEvent + */ + protected void fireColumnMoved(TableColumnModelEvent e) + { + TableColumnModelListener[] listeners = getColumnModelListeners(); + + for (int i=0; i< listeners.length; i++) + listeners[i].columnMoved(e); + } + + /** + * fireColumnSelectionChanged fires TableColumnModelEvent to model's + * registered TableColumnModelListeners to indicate that different column + * was selected. + * + * @param evt ListSelectionEvent + */ + protected void fireColumnSelectionChanged(ListSelectionEvent evt) + { + EventListener [] listeners = getListeners(TableColumnModelListener.class); + for (int i = 0; i < listeners.length; ++i) + ((TableColumnModelListener)listeners[i]).columnSelectionChanged(evt); + } + + /** + * fireColumnMarginChanged fires TableColumnModelEvent to model's + * registered TableColumnModelListeners to indicate that column margin + * was changed. + */ + protected void fireColumnMarginChanged() + { + EventListener [] listeners = getListeners(TableColumnModelListener.class); + for (int i = 0; i < listeners.length; ++i) + ((TableColumnModelListener)listeners[i]).columnMarginChanged(changeEvent); + } + + /** + * getListeners returns currently registered listeners with this model. + * @param listenerType type of listeners to return + * + * @return EventListener[] array of model's listeners of the specified type + */ + public EventListener[] getListeners(Class listenerType) + { + return listenerList.getListeners(listenerType); + } + + /** + * propertyChange handles changes occuring in the properties of the + * model's columns. + * + * @param evt PropertyChangeEvent + */ + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals(TableColumn.COLUMN_WIDTH_PROPERTY)) + invalidateWidthCache(); + } + + /** + * valueChanged handles changes in the selectionModel. + * @param e ListSelectionEvent + */ + public void valueChanged(ListSelectionEvent e) + { + fireColumnSelectionChanged(e); + } + + /** + * createSelectionModel creates selection model that will keep track + * of currently selected column(s) + * + * @return ListSelectionModel selection model of the columns + */ + protected ListSelectionModel createSelectionModel() + { + return new DefaultListSelectionModel(); + } + + /** + * recalcWidthCache calculates total width of the columns. + * If the current cache of the total width is in invalidated state, + * then width is recalculated. Otherwise nothing is done. + */ + protected void recalcWidthCache() + { + if (totalColumnWidth == -1) + { + totalColumnWidth = 0; + for (int i = 0; i < tableColumns.size(); ++i) + { + totalColumnWidth += ((TableColumn)tableColumns.get(i)).getWidth(); + } + } + } + + /** + * invalidateWidthCache + */ + private void invalidateWidthCache() + { + totalColumnWidth = -1; + } +} diff --git a/libjava/classpath/javax/swing/table/DefaultTableModel.java b/libjava/classpath/javax/swing/table/DefaultTableModel.java new file mode 100644 index 0000000..6844f2a --- /dev/null +++ b/libjava/classpath/javax/swing/table/DefaultTableModel.java @@ -0,0 +1,588 @@ +/* DefaultTableModel.java -- + Copyright (C) 2002, 2004, 2005, Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.io.Serializable; +import java.util.Vector; + +import javax.swing.event.TableModelEvent; + +/** + * A two dimensional data structure used to store <code>Object</code> + * instances, usually for display in a <code>JTable</code> component. + * + * @author Andrew Selkirk + */ +public class DefaultTableModel extends AbstractTableModel + implements Serializable +{ + static final long serialVersionUID = 6680042567037222321L; + + /** + * Storage for the rows in the table (each row is itself + * a <code>Vector</code>). + */ + protected Vector dataVector; + + /** + * Storage for the column identifiers. + */ + protected Vector columnIdentifiers; + + /** + * Creates an empty table with zero rows and zero columns. + */ + public DefaultTableModel() + { + this(0, 0); + } + + /** + * Creates a new table with the specified number of rows and columns. + * All cells in the table are initially empty (set to <code>null</code>). + * + * @param numRows the number of rows. + * @param numColumns the number of columns. + */ + public DefaultTableModel(int numRows, int numColumns) + { + Vector defaultNames = new Vector(numColumns); + Vector data = new Vector(numRows); + for (int i = 0; i < numColumns; i++) + { + defaultNames.add(super.getColumnName(i)); + } + for (int r = 0; r < numRows; r++) + { + Vector tmp = new Vector(numColumns); + tmp.setSize(numColumns); + data.add(tmp); + } + setDataVector(data, defaultNames); + } + + /** + * Creates a new table with the specified column names and number of + * rows. The number of columns is determined by the number of column + * names supplied. + * + * @param columnNames the column names. + * @param numRows the number of rows. + */ + public DefaultTableModel(Vector columnNames, int numRows) + { + if (numRows < 0) + throw new IllegalArgumentException("numRows < 0"); + Vector data = new Vector(); + int numColumns = 0; + + if (columnNames != null) + numColumns = columnNames.size(); + + while (0 < numRows--) + { + Vector rowData = new Vector(); + rowData.setSize(numColumns); + data.add(rowData); + } + setDataVector(data, columnNames); + } + + /** + * Creates a new table with the specified column names and row count. + * + * @param columnNames the column names. + * @param numRows the number of rows. + */ + public DefaultTableModel(Object[] columnNames, int numRows) + { + this(convertToVector(columnNames), numRows); + } + + /** + * Creates a new table with the specified data values and column names. + * + * @param data the data values. + * @param columnNames the column names. + */ + public DefaultTableModel(Vector data, Vector columnNames) + { + setDataVector(data, columnNames); + } + + /** + * Creates a new table with the specified data values and column names. + * + * @param data the data values. + * @param columnNames the column names. + */ + public DefaultTableModel(Object[][] data, Object[] columnNames) + { + this(convertToVector(data), convertToVector(columnNames)); + } + + /** + * Returns the vector containing the row data for the table. + * + * @return The data vector. + */ + public Vector getDataVector() + { + return dataVector; + } + + /** + * Sets the data and column identifiers for the table. The data vector + * contains a <code>Vector</code> for each row in the table - if the + * number of objects in each row does not match the number of column + * names specified, the row data is truncated or expanded (by adding + * <code>null</code> values) as required. + * + * @param data the data for the table (a vector of row vectors). + * @param columnNames the column names. + * + * @throws NullPointerException if either argument is <code>null</code>. + */ + public void setDataVector(Vector data, Vector columnNames) + { + if (data == null) + dataVector = new Vector(); + else + dataVector = data; + setColumnIdentifiers(columnNames); + } + + /** + * Sets the data and column identifiers for the table. + * + * @param data the data for the table. + * @param columnNames the column names. + * + * @throws NullPointerException if either argument is <code>null</code>. + */ + public void setDataVector(Object[][] data, Object[] columnNames) + { + setDataVector(convertToVector(data), + convertToVector(columnNames)); + } + + /** + * Sends the specified <code>event</code> to all registered listeners. + * This method is equivalent to + * {@link AbstractTableModel#fireTableChanged(TableModelEvent)}. + * + * @param event the event. + */ + public void newDataAvailable(TableModelEvent event) + { + fireTableChanged(event); + } + + /** + * Sends the specified <code>event</code> to all registered listeners. + * This method is equivalent to + * {@link AbstractTableModel#fireTableChanged(TableModelEvent)}. + * + * @param event the event. + */ + public void newRowsAdded(TableModelEvent event) + { + fireTableChanged(event); + } + + /** + * Sends the specified <code>event</code> to all registered listeners. + * This method is equivalent to + * {@link AbstractTableModel#fireTableChanged(TableModelEvent)}. + * + * @param event the event. + */ + public void rowsRemoved(TableModelEvent event) + { + fireTableChanged(event); + } + + /** + * Sets the column identifiers, updates the data rows (truncating + * or padding each row with <code>null</code> values) to match the + * number of columns, and sends a {@link TableModelEvent} to all + * registered listeners. + * + * @param columnIdentifiers the column identifiers. + */ + public void setColumnIdentifiers(Vector columnIdentifiers) + { + this.columnIdentifiers = columnIdentifiers; + setColumnCount((columnIdentifiers == null ? 0 : columnIdentifiers.size())); + } + + /** + * Sets the column identifiers, updates the data rows (truncating + * or padding each row with <code>null</code> values) to match the + * number of columns, and sends a {@link TableModelEvent} to all + * registered listeners. + * + * @param columnIdentifiers the column identifiers. + */ + public void setColumnIdentifiers(Object[] columnIdentifiers) + { + setColumnIdentifiers(convertToVector(columnIdentifiers)); + } + + /** + * This method is obsolete, use {@link #setRowCount(int)} instead. + * + * @param numRows the number of rows. + */ + public void setNumRows(int numRows) + { + setRowCount(numRows); + } + + /** + * Sets the number of rows in the table. If <code>rowCount</code> is less + * than the current number of rows in the table, rows are discarded. + * If <code>rowCount</code> is greater than the current number of rows in + * the table, new (empty) rows are added. + * + * @param rowCount the row count. + */ + public void setRowCount(int rowCount) + { + int existingRowCount = dataVector.size(); + if (rowCount < existingRowCount) + { + dataVector.setSize(rowCount); + fireTableRowsDeleted(rowCount,existingRowCount-1); + } + else + { + int rowsToAdd = rowCount - existingRowCount; + for (int i = 0; i < rowsToAdd; i++) + { + Vector tmp = new Vector(); + tmp.setSize(columnIdentifiers.size()); + dataVector.add(tmp); + } + fireTableRowsInserted(existingRowCount,rowCount-1); + } + } + + /** + * Sets the number of columns in the table. Existing rows are truncated + * or padded with <code>null</code> values to match the new column count. + * A {@link TableModelEvent} is sent to all registered listeners. + * + * @param columnCount the column count. + */ + public void setColumnCount(int columnCount) + { + for (int i = 0; i < dataVector.size(); ++i) + { + ((Vector) dataVector.get(i)).setSize(columnCount); + } + if (columnIdentifiers != null) + columnIdentifiers.setSize(columnCount); + fireTableStructureChanged(); + } + + /** + * Adds a column with the specified name to the table. All cell values + * for the column are initially set to <code>null</code>. + * + * @param columnName the column name (<code>null</code> permitted). + */ + public void addColumn(Object columnName) + { + addColumn(columnName, (Object[]) null); + } + + /** + * Adds a column with the specified name and data values to the table. + * + * @param columnName the column name (<code>null</code> permitted). + * @param columnData the column data. + */ + public void addColumn(Object columnName, Vector columnData) + { + Object[] dataArray = null; + if (columnData != null) + { + int rowCount = dataVector.size(); + if (columnData.size() < rowCount) + columnData.setSize(rowCount); + dataArray = columnData.toArray(); + } + addColumn(columnName, dataArray); + } + + /** + * Adds a column with the specified name and data values to the table. + * + * @param columnName the column name (<code>null</code> permitted). + * @param columnData the column data. + */ + public void addColumn(Object columnName, Object[] columnData) { + if (columnData != null) + { + // check columnData array for cases where the number of items + // doesn't match the number of rows in the existing table + if (columnData.length > dataVector.size()) + { + int rowsToAdd = columnData.length - dataVector.size(); + for (int i = 0; i < rowsToAdd; i++) + { + Vector tmp = new Vector(); + tmp.setSize(columnIdentifiers.size()); + dataVector.add(tmp); + } + } + else if (columnData.length < dataVector.size()) + { + Object[] tmp = new Object[dataVector.size()]; + System.arraycopy(columnData, 0, tmp, 0, columnData.length); + columnData = tmp; + } + } + for (int i = 0; i < dataVector.size(); ++i) + { + ((Vector) dataVector.get(i)).add(columnData == null ? null : columnData[i]); + } + columnIdentifiers.add(columnName); + fireTableStructureChanged(); + } + + /** + * Adds a new row containing the specified data to the table and sends a + * {@link TableModelEvent} to all registered listeners. + * + * @param rowData the row data (<code>null</code> permitted). + */ + public void addRow(Vector rowData) { + int rowIndex = dataVector.size(); + dataVector.add(rowData); + newRowsAdded(new TableModelEvent( + this, rowIndex, rowIndex, -1, TableModelEvent.INSERT) + ); + } + + /** + * Adds a new row containing the specified data to the table and sends a + * {@link TableModelEvent} to all registered listeners. + * + * @param rowData the row data (<code>null</code> permitted). + */ + public void addRow(Object[] rowData) { + addRow(convertToVector(rowData)); + } + + /** + * Inserts a new row into the table. + * + * @param row the row index. + * @param rowData the row data. + */ + public void insertRow(int row, Vector rowData) { + dataVector.add(row, rowData); + fireTableRowsInserted(row,row); + } + + /** + * Inserts a new row into the table. + * + * @param row the row index. + * @param rowData the row data. + */ + public void insertRow(int row, Object[] rowData) { + insertRow(row, convertToVector(rowData)); + } + + /** + * Moves the rows from <code>startIndex</code> to <code>endIndex</code> + * (inclusive) to the specified row. + * + * @param startIndex the start row. + * @param endIndex the end row. + * @param toIndex the row to move to. + */ + public void moveRow(int startIndex, int endIndex, int toIndex) { + Vector removed = new Vector(); + for (int i = endIndex; i >= startIndex; i--) + { + removed.add(this.dataVector.remove(i)); + } + for (int i = 0; i <= endIndex - startIndex; i++) + { + dataVector.insertElementAt(removed.get(i), toIndex); + } + int firstRow = Math.min(startIndex, toIndex); + int lastRow = Math.max(endIndex, toIndex + (endIndex - startIndex)); + fireTableRowsUpdated(firstRow, lastRow); + } + + /** + * Removes a row from the table and sends a {@link TableModelEvent} to + * all registered listeners. + * + * @param row the row index. + */ + public void removeRow(int row) { + dataVector.remove(row); + fireTableRowsDeleted(row,row); + } + + /** + * Returns the number of rows in the model. + * + * @return The row count. + */ + public int getRowCount() { + return dataVector.size(); + } + + /** + * Returns the number of columns in the model. + * + * @return The column count. + */ + public int getColumnCount() { + return (columnIdentifiers == null ? 0 : columnIdentifiers.size()); + } + + /** + * Returns the name of the specified column. + * + * @param column the column index. + * + * @return The column name. + */ + public String getColumnName(int column) { + String result = ""; + if (columnIdentifiers == null) + result = super.getColumnName(column); + else + { + if (column < getColumnCount()) + { + Object id = columnIdentifiers.get(column); + if (id != null) + result = id.toString(); + else + result = super.getColumnName(column); + } + else + result = super.getColumnName(column); + } + return result; + } + + /** + * Returns <code>true</code> if the specified cell can be modified, and + * <code>false</code> otherwise. For this implementation, the method + * always returns <code>true</code>. + * + * @param row the row index. + * @param column the column index. + * + * @return <code>true</code> in all cases. + */ + public boolean isCellEditable(int row, int column) { + return true; + } + + /** + * Returns the value at the specified cell in the table. + * + * @param row the row index. + * @param column the column index. + * + * @return The value (<code>Object</code>, possibly <code>null</code>) at + * the specified cell in the table. + */ + public Object getValueAt(int row, int column) { + return ((Vector) dataVector.get(row)).get(column); + } + + /** + * Sets the value for the specified cell in the table and sends a + * {@link TableModelEvent} to all registered listeners. + * + * @param value the value (<code>Object</code>, <code>null</code> permitted). + * @param row the row index. + * @param column the column index. + */ + public void setValueAt(Object value, int row, int column) { + ((Vector) dataVector.get(row)).set(column, value); + fireTableCellUpdated(row,column); + } + + /** + * Converts the data array to a <code>Vector</code>. + * + * @param data the data array (<code>null</code> permitted). + * + * @return A vector (or <code>null</code> if the data array + * is <code>null</code>). + */ + protected static Vector convertToVector(Object[] data) { + if (data == null) + return null; + Vector vector = new Vector(data.length); + for (int i = 0; i < data.length; i++) + vector.add(data[i]); + return vector; + } + + /** + * Converts the data array to a <code>Vector</code> of rows. + * + * @param data the data array (<code>null</code> permitted). + * + * @return A vector (or <code>null</code> if the data array + * is <code>null</code>. + */ + protected static Vector convertToVector(Object[][] data) { + if (data == null) + return null; + Vector vector = new Vector(data.length); + for (int i = 0; i < data.length; i++) + vector.add(convertToVector(data[i])); + return vector; + } +} diff --git a/libjava/classpath/javax/swing/table/JTableHeader.java b/libjava/classpath/javax/swing/table/JTableHeader.java new file mode 100644 index 0000000..45586da --- /dev/null +++ b/libjava/classpath/javax/swing/table/JTableHeader.java @@ -0,0 +1,668 @@ +/* JTableHeader.java -- + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.FocusListener; +import java.beans.PropertyChangeListener; +import java.util.Locale; + +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleAction; +import javax.accessibility.AccessibleComponent; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleSelection; +import javax.accessibility.AccessibleStateSet; +import javax.accessibility.AccessibleText; +import javax.accessibility.AccessibleValue; +import javax.swing.JComponent; +import javax.swing.JTable; +import javax.swing.UIManager; +import javax.swing.plaf.TableHeaderUI; + +public class JTableHeader extends JComponent +{ + protected class AccessibleJTableHeader extends AccessibleJComponent + { + protected class AccessibleJTableHeaderEntry extends AccessibleContext + implements Accessible, AccessibleComponent + { + public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t) + { + throw new Error("not implemented"); + } + + public void addFocusListener(FocusListener l) + { + throw new Error("not implemented"); + } + + public void addPropertyChangeListener(PropertyChangeListener l) + { + throw new Error("not implemented"); + } + + public boolean contains(Point p) + { + throw new Error("not implemented"); + } + + public AccessibleAction getAccessibleAction() + { + throw new Error("not implemented"); + } + + public Accessible getAccessibleAt(Point p) + { + throw new Error("not implemented"); + } + + public Accessible getAccessibleChild(int i) + { + throw new Error("not implemented"); + } + + public int getAccessibleChildrenCount() + { + throw new Error("not implemented"); + } + + public AccessibleComponent getAccessibleComponent() + { + throw new Error("not implemented"); + } + + public AccessibleContext getAccessibleContext() + { + throw new Error("not implemented"); + } + + public String getAccessibleDescription() + { + throw new Error("not implemented"); + } + + public int getAccessibleIndexInParent() + { + throw new Error("not implemented"); + } + + public String getAccessibleName() + { + throw new Error("not implemented"); + } + + public AccessibleRole getAccessibleRole() + { + throw new Error("not implemented"); + } + + public AccessibleSelection getAccessibleSelection() + { + throw new Error("not implemented"); + } + + public AccessibleStateSet getAccessibleStateSet() + { + throw new Error("not implemented"); + } + + public AccessibleText getAccessibleText() + { + throw new Error("not implemented"); + } + + public AccessibleValue getAccessibleValue() + { + throw new Error("not implemented"); + } + + public Color getBackground() + { + throw new Error("not implemented"); + } + + public Rectangle getBounds() + { + throw new Error("not implemented"); + } + + public Cursor getCursor() + { + throw new Error("not implemented"); + } + + public Font getFont() + { + throw new Error("not implemented"); + } + + public FontMetrics getFontMetrics(Font f) + { + throw new Error("not implemented"); + } + + public Color getForeground() + { + throw new Error("not implemented"); + } + + public Locale getLocale() + { + throw new Error("not implemented"); + } + + public Point getLocation() + { + throw new Error("not implemented"); + } + + public Point getLocationOnScreen() + { + throw new Error("not implemented"); + } + + public Dimension getSize() + { + throw new Error("not implemented"); + } + + public boolean isEnabled() + { + throw new Error("not implemented"); + } + + public boolean isFocusTraversable() + { + throw new Error("not implemented"); + } + + public boolean isShowing() + { + throw new Error("not implemented"); + } + + public boolean isVisible() + { + throw new Error("not implemented"); + } + + public void removeFocusListener(FocusListener l) + { + throw new Error("not implemented"); + } + + public void removePropertyChangeListener(PropertyChangeListener l) + { + throw new Error("not implemented"); + } + + public void requestFocus() + { + throw new Error("not implemented"); + } + + public void setAccessibleDescription(String s) + { + throw new Error("not implemented"); + } + + public void setAccessibleName(String s) + { + throw new Error("not implemented"); + } + + public void setBackground(Color c) + { + throw new Error("not implemented"); + } + + public void setBounds(Rectangle r) + { + throw new Error("not implemented"); + } + + public void setCursor(Cursor c) + { + throw new Error("not implemented"); + } + + public void setEnabled(boolean b) + { + throw new Error("not implemented"); + } + + public void setFont(Font f) + { + throw new Error("not implemented"); + } + + public void setForeground(Color c) + { + throw new Error("not implemented"); + } + + public void setLocation(Point p) + { + throw new Error("not implemented"); + } + + public void setSize(Dimension d) + { + throw new Error("not implemented"); + } + + public void setVisible(boolean b) + { + throw new Error("not implemented"); + } + }; + } + + private static final long serialVersionUID = 5144633983372967710L; + + /** + * The accessibleContext property. + */ + AccessibleContext accessibleContext; + + /** + * The columnModel property. + */ + protected TableColumnModel columnModel; + + /** + * The draggedColumn property. + */ + protected TableColumn draggedColumn; + + /** + * The draggedDistance property. + */ + protected int draggedDistance; + + /** + * The opaque property. + */ + boolean opaque; + + /** + * The reorderingAllowed property. + */ + protected boolean reorderingAllowed; + + /** + * The resizingAllowed property. + */ + protected boolean resizingAllowed = true; + + /** + * The resizingColumn property. + */ + protected TableColumn resizingColumn; + + /** + * The table property. + */ + protected JTable table; + + /** + * The updateTableInRealTime property. + */ + protected boolean updateTableInRealTime; + + TableCellRenderer cellRenderer; + + /** + * Creates a new default instance. + */ + public JTableHeader() + { + this(null); + } + + /** + * Creates a new header. If <code>cm</code> is <code>null</code>, a new + * table column model is created by calling + * {@link #createDefaultColumnModel()}. + * + * @param cm the table column model (<code>null</code> permitted). + */ + public JTableHeader(TableColumnModel cm) + { + accessibleContext = new AccessibleJTableHeader(); + columnModel = cm == null ? createDefaultColumnModel() : cm; + draggedColumn = null; + draggedDistance = 0; + opaque = true; + reorderingAllowed = true; + resizingAllowed = true; + resizingColumn = null; + table = null; + updateTableInRealTime = true; + cellRenderer = createDefaultRenderer(); + updateUI(); + } + + /** + * Creates a default table column model. + * + * @return A default table column model. + */ + protected TableColumnModel createDefaultColumnModel() + { + return new DefaultTableColumnModel(); + } + + /** + * Get the value of the {@link #accessibleContext} property. + * + * @return The current value of the property + */ + public AccessibleContext getAccessibleContext() + { + return accessibleContext; + } + + /** + * Get the value of the {@link #columnModel} property. + * + * @return The current value of the property + */ + public TableColumnModel getColumnModel() + { + return columnModel; + } + + /** + * Get the value of the {@link #draggedColumn} property. + * + * @return The current value of the property + */ + public TableColumn getDraggedColumn() + { + return draggedColumn; + } + + /** + * Get the value of the {@link #draggedDistance} property. + * + * @return The current value of the property + */ + public int getDraggedDistance() + { + return draggedDistance; + } + + /** + * Get the value of the {@link #reorderingAllowed} property. + * + * @return The current value of the property + */ + public boolean getReorderingAllowed() + { + return reorderingAllowed; + } + + /** + * Get the value of the {@link #resizingAllowed} property. + * + * @return The current value of the property + */ + public boolean getResizingAllowed() + { + return resizingAllowed; + } + + /** + * Get the value of the {@link #resizingColumn} property. + * + * @return The current value of the property + */ + public TableColumn getResizingColumn() + { + return resizingColumn; + } + + /** + * Get the value of the {@link #table} property. + * + * @return The current value of the property + */ + public JTable getTable() + { + return table; + } + + /** + * Get the value of the {@link #updateTableInRealTime} property. + * + * @return The current value of the property + */ + public boolean getUpdateTableInRealTime() + { + return updateTableInRealTime; + } + + /** + * Get the value of the {@link #opaque} property. + * + * @return The current value of the property + */ + public boolean isOpaque() + { + return opaque; + } + + /** + * Set the value of the {@link #columnModel} property. + * + * @param c The new value of the property + */ + public void setColumnModel(TableColumnModel c) + { + columnModel = c; + } + + /** + * Set the value of the {@link #draggedColumn} property. + * + * @param d The new value of the property + */ + public void setDraggedColumn(TableColumn d) + { + draggedColumn = d; + } + + /** + * Set the value of the {@link #draggedDistance} property. + * + * @param d The new value of the property + */ + public void setDraggedDistance(int d) + { + draggedDistance = d; + } + + /** + * Set the value of the {@link #opaque} property. + * + * @param o The new value of the property + */ + public void setOpaque(boolean o) + { + opaque = o; + } + + /** + * Set the value of the {@link #reorderingAllowed} property. + * + * @param r The new value of the property + */ + public void setReorderingAllowed(boolean r) + { + reorderingAllowed = r; + } + + /** + * Set the value of the {@link #resizingAllowed} property. + * + * @param r The new value of the property + */ + public void setResizingAllowed(boolean r) + { + resizingAllowed = r; + } + + /** + * Set the value of the {@link #resizingColumn} property. + * + * @param r The new value of the property + */ + public void setResizingColumn(TableColumn r) + { + resizingColumn = r; + } + + /** + * Set the value of the {@link #table} property. + * + * @param t The new value of the property + */ + public void setTable(JTable t) + { + table = t; + } + + /** + * Set the value of the {@link #updateTableInRealTime} property. + * + * @param u The new value of the property + */ + public void setUpdateTableInRealTime(boolean u) + { + updateTableInRealTime = u; + } + + /** + * Creates a default renderer. + * + * @return A default renderer. + */ + protected TableCellRenderer createDefaultRenderer() + { + return new DefaultTableCellRenderer(); + } + + /** + * Returns the default table cell renderer. + * + * @return The default table cell renderer. + */ + public TableCellRenderer getDefaultRenderer() + { + return cellRenderer; + } + + /** + * Sets the default table cell renderer. + * + * @param cellRenderer the renderer. + */ + public void setDefaultRenderer(TableCellRenderer cellRenderer) + { + this.cellRenderer = cellRenderer; + } + + public Rectangle getHeaderRect(int column) + { + Rectangle r = getTable().getCellRect(-1, column, true); + r.height = getHeight(); + return r; + } + + protected String paramString() + { + return "JTableHeader"; + } + + // UI support + + public String getUIClassID() + { + return "TableHeaderUI"; + } + + public TableHeaderUI getUI() + { + return (TableHeaderUI) ui; + } + + public void setUI(TableHeaderUI u) + { + super.setUI(u); + } + + public void updateUI() + { + setUI((TableHeaderUI) UIManager.getUI(this)); + } + + /** + * Returns the index of the column at the specified point. + * + * @param point the point. + * + * @return The column index, or -1. + */ + public int columnAtPoint(Point point) + { + if (getBounds().contains(point)) + return columnModel.getColumnIndexAtX(point.x); + + return -1; + } +} diff --git a/libjava/classpath/javax/swing/table/TableCellEditor.java b/libjava/classpath/javax/swing/table/TableCellEditor.java new file mode 100644 index 0000000..b355311 --- /dev/null +++ b/libjava/classpath/javax/swing/table/TableCellEditor.java @@ -0,0 +1,65 @@ +/* TableCellEditor.java -- + Copyright (C) 2002, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.awt.Component; + +import javax.swing.CellEditor; +import javax.swing.JTable; + +/** + * TableCellEditor public interface + * @author Andrew Selkirk + */ +public interface TableCellEditor extends CellEditor { + + /** + * Get table cell editor component + * @param table JTable + * @param value Value of cell + * @param isSelected Cell selected + * @param row Row of cell + * @param column Column of cell + * @returns Component + */ + Component getTableCellEditorComponent(JTable table, + Object value, boolean isSelected, int row, int column); + + +} // TableCellEditor diff --git a/libjava/classpath/javax/swing/table/TableCellRenderer.java b/libjava/classpath/javax/swing/table/TableCellRenderer.java new file mode 100644 index 0000000..639b4b9 --- /dev/null +++ b/libjava/classpath/javax/swing/table/TableCellRenderer.java @@ -0,0 +1,66 @@ +/* TableCellRenderer.java -- + Copyright (C) 2002, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.awt.Component; + +import javax.swing.JTable; + +/** + * TableCellRenderer public interface + * @author Andrew Selkirk + */ +public interface TableCellRenderer { + + /** + * Get table cell renderer component + * @param table JTable + * @param value Value of cell + * @param isSelected Cell selected + * @param hasFocus Cell has focus + * @param row Row of cell + * @param column Column of cell + * @returns Component + */ + Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, + int row, int column); + + +} // TableCellRenderer diff --git a/libjava/classpath/javax/swing/table/TableColumn.java b/libjava/classpath/javax/swing/table/TableColumn.java new file mode 100644 index 0000000..9c36bb0 --- /dev/null +++ b/libjava/classpath/javax/swing/table/TableColumn.java @@ -0,0 +1,573 @@ +/* TableColumn.java -- + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; + +import javax.swing.event.SwingPropertyChangeSupport; + +/** + * Represents the attributes of a column in a table, including the column index, + * width, minimum width, preferred width and maximum width. + * + * @author Andrew Selkirk + * @version 1.0 + */ +public class TableColumn + implements Serializable +{ + static final long serialVersionUID = -6113660025878112608L; + + /** + * The name for the <code>columnWidth</code> property. Note that the typo + * in the name value is deliberate, to match the specification. + */ + public static final String COLUMN_WIDTH_PROPERTY = "columWidth"; + + /** + * The name for the <code>headerValue</code> property. + */ + public static final String HEADER_VALUE_PROPERTY = "headerValue"; + + /** + * The name for the <code>headerRenderer</code> property. + */ + public static final String HEADER_RENDERER_PROPERTY = "headerRenderer"; + + /** + * The name for the <code>cellRenderer</code> property. + */ + public static final String CELL_RENDERER_PROPERTY = "cellRenderer"; + + /** + * The index of the corresponding column in the table model. + */ + protected int modelIndex; + + /** + * The identifier for the column. + */ + protected Object identifier; + + /** + * The width. + */ + protected int width; + + /** + * The minimum width. + */ + protected int minWidth = 15; + + /** + * The preferred width. + */ + private int preferredWidth; + + /** + * The maximum width. + */ + protected int maxWidth = Integer.MAX_VALUE; + + /** + * headerRenderer + */ + protected TableCellRenderer headerRenderer; + + /** + * The header value. + */ + protected Object headerValue; + + /** + * cellRenderer + */ + protected TableCellRenderer cellRenderer; + + /** + * cellEditor + */ + protected TableCellEditor cellEditor; + + /** + * isResizable + */ + protected boolean isResizable = true; + + /** + * resizedPostingDisableCount + * + * @deprecated 1.3 + */ + protected transient int resizedPostingDisableCount; + + /** + * changeSupport + */ + private SwingPropertyChangeSupport changeSupport = + new SwingPropertyChangeSupport(this); + + /** + * Creates a new <code>TableColumn</code> that maps to column 0 in the + * related table model. The default width is <code>75</code> units. + */ + public TableColumn() + { + this(0, 75, null, null); + } + + /** + * Creates a new <code>TableColumn</code> that maps to the specified column + * in the related table model. The default width is <code>75</code> units. + * + * @param modelIndex the index of the column in the model + */ + public TableColumn(int modelIndex) + { + this(modelIndex, 75, null, null); + } + + /** + * Creates a new <code>TableColumn</code> that maps to the specified column + * in the related table model, and has the specified <code>width</code>. + * + * @param modelIndex the index of the column in the model + * @param width the width + */ + public TableColumn(int modelIndex, int width) + { + this(modelIndex, width, null, null); + } + + /** + * Creates a new <code>TableColumn</code> that maps to the specified column + * in the related table model, and has the specified <code>width</code>, + * <code>cellRenderer</code> and <code>cellEditor</code>. + * + * @param modelIndex the index of the column in the model + * @param width the width + * @param cellRenderer the cell renderer (<code>null</code> permitted). + * @param cellEditor the cell editor (<code>null</code> permitted). + */ + public TableColumn(int modelIndex, int width, + TableCellRenderer cellRenderer, TableCellEditor cellEditor) + { + this.modelIndex = modelIndex; + this.width = width; + this.preferredWidth = width; + this.cellRenderer = cellRenderer; + this.cellEditor = cellEditor; + this.headerValue = null; + this.identifier = null; + } + + /** + * firePropertyChange + * + * @param property the name of the property + * @param oldValue the old value + * @param newValue the new value + */ + private void firePropertyChange(String property, Object oldValue, + Object newValue) + { + changeSupport.firePropertyChange(property, oldValue, newValue); + } + + /** + * firePropertyChange + * + * @param property the name of the property + * @param oldValue the old value + * @param newValue the new value + */ + private void firePropertyChange(String property, int oldValue, int newValue) + { + firePropertyChange(property, new Integer(oldValue), new Integer(newValue)); + } + + /** + * firePropertyChange + * + * @param property the name of the property + * @param oldValue the old value + * @param newValue the new value + */ + private void firePropertyChange(String property, boolean oldValue, + boolean newValue) + { + firePropertyChange(property, Boolean.valueOf(oldValue), + Boolean.valueOf(newValue)); + } + + /** + * Sets the index of the column in the related {@link TableModel} that this + * <code>TableColumn</code> maps to. + * + * @param modelIndex the column index in the model. + */ + public void setModelIndex(int modelIndex) + { + this.modelIndex = modelIndex; + } + + /** + * Returns the index of the column in the related {@link TableModel} that + * this <code>TableColumn</code> maps to. + * + * @return the model index + */ + public int getModelIndex() + { + return modelIndex; + } + + /** + * Sets the identifier for the column. + * + * @param identifier the identifier + */ + public void setIdentifier(Object identifier) + { + this.identifier = identifier; + } + + /** + * Returns the identifier for the column, or {@link #getHeaderValue()} if the + * identifier is <code>null</code>. + * + * @return The identifier (or {@link #getHeaderValue()} if the identifier is + * <code>null</code>). + */ + public Object getIdentifier() + { + if (identifier == null) + return getHeaderValue(); + return identifier; + } + + /** + * Sets the header value and sends a {@link PropertyChangeEvent} to all + * registered listeners. The header value property uses the name + * {@link #HEADER_VALUE_PROPERTY}. + * + * @param headerValue the value of the header + */ + public void setHeaderValue(Object headerValue) + { + if (this.headerValue == headerValue) + return; + + Object oldValue = this.headerValue; + this.headerValue = headerValue; + firePropertyChange(HEADER_VALUE_PROPERTY, oldValue, headerValue); + } + + /** + * Returns the header value. + * + * @return the value of the header + */ + public Object getHeaderValue() + { + return headerValue; + } + + /** + * setHeaderRenderer + * + * @param renderer the renderer to use + */ + public void setHeaderRenderer(TableCellRenderer renderer) + { + if (headerRenderer == renderer) + return; + + TableCellRenderer oldRenderer = headerRenderer; + headerRenderer = renderer; + firePropertyChange(HEADER_RENDERER_PROPERTY, + oldRenderer, headerRenderer); + } + + /** + * getHeaderRenderer + * @return TableCellRenderer + */ + public TableCellRenderer getHeaderRenderer() + { + return headerRenderer; + } + + /** + * Sets the renderer for cells in this column and sends a + * {@link PropertyChangeEvent} to all registered listeners. + * + * @param renderer the cell renderer (<code>null</code> permitted). + */ + public void setCellRenderer(TableCellRenderer renderer) + { + if (cellRenderer == renderer) + return; + + TableCellRenderer oldRenderer = cellRenderer; + cellRenderer = renderer; + firePropertyChange(CELL_RENDERER_PROPERTY, + oldRenderer, cellRenderer); + } + + /** + * Returns the renderer for the table cells in this column. + * + * @return The cell renderer. + */ + public TableCellRenderer getCellRenderer() + { + return cellRenderer; + } + + /** + * setCellEditor + * + * @param cellEditor the cell editor + */ + public void setCellEditor(TableCellEditor cellEditor) + { + this.cellEditor = cellEditor; + } + + /** + * getCellEditor + * + * @return the cell editor + */ + public TableCellEditor getCellEditor() + { + return cellEditor; + } + + /** + * setWidth + * + * @param newWidth the width + */ + public void setWidth(int newWidth) + { + int oldWidth = width; + + if (newWidth < minWidth) + width = minWidth; + else if (newWidth > maxWidth) + width = maxWidth; + else + width = newWidth; + + if (width == oldWidth) + return; + + firePropertyChange(COLUMN_WIDTH_PROPERTY, oldWidth, width); + } + + /** + * getWidth + * + * @return int + */ + public int getWidth() + { + return width; + } + + /** + * setPreferredWidth + * + * @param preferredWidth the preferred width + */ + public void setPreferredWidth(int preferredWidth) + { + if (preferredWidth < minWidth) + this.preferredWidth = minWidth; + else if (preferredWidth > maxWidth) + this.preferredWidth = maxWidth; + else + this.preferredWidth = preferredWidth; + } + + /** + * getPreferredWidth + * + * @return the preferred width + */ + public int getPreferredWidth() + { + return preferredWidth; + } + + /** + * Sets the minimum width for the column and, if necessary, updates the + * <code>width</code> and <code>preferredWidth</code>. + * + * @param minWidth the minimum width + */ + public void setMinWidth(int minWidth) + { + this.minWidth = minWidth; + setWidth(getWidth()); + setPreferredWidth(getPreferredWidth()); + } + + /** + * Returns the <code>TableColumn</code>'s minimum width. + * + * @return The minimum width. + */ + public int getMinWidth() + { + return minWidth; + } + + /** + * Sets the maximum width and, if necessary, updates the <code>width</code> + * and <code>preferredWidth</code>. + * + * @param maxWidth the maximum width + */ + public void setMaxWidth(int maxWidth) + { + this.maxWidth = maxWidth; + setWidth(getWidth()); + setPreferredWidth(getPreferredWidth()); + } + + /** + * Returns the maximum width. + * + * @return The maximum width. + */ + public int getMaxWidth() + { + return maxWidth; + } + + /** + * setResizable + * + * @param isResizable <code>true</code> if this column is resizable, + * <code>false</code> otherwise + */ + public void setResizable(boolean isResizable) + { + this.isResizable = isResizable; + } + + /** + * getResizable + * + * @return <code>true</code> if this column is resizable, + * <code>false</code> otherwise + */ + public boolean getResizable() + { + return isResizable; + } + + /** + * sizeWidthToFit + */ + public void sizeWidthToFit() + { + // TODO + } + + /** + * This method is empty, unused and deprecated. + * @deprecated 1.3 + */ + public void disableResizedPosting() + { + // Does nothing + } + + /** + * This method is empty, unused and deprecated. + * @deprecated 1.3 + */ + public void enableResizedPosting() + { + // Does nothing + } + + /** + * Adds a property change listener. + * + * @param listener the listener to add + */ + public synchronized void addPropertyChangeListener(PropertyChangeListener listener) + { + changeSupport.addPropertyChangeListener(listener); + } + + /** + * removePropertyChangeListener + * @param listener the listener to remove + */ + public synchronized void removePropertyChangeListener(PropertyChangeListener listener) + { + changeSupport.removePropertyChangeListener(listener); + } + + /** + * Returns the property change listeners for this <code>TableColumn</code>. + * @since 1.4 + */ + public PropertyChangeListener[] getPropertyChangeListeners() + { + return changeSupport.getPropertyChangeListeners(); + } + + /** + * createDefaultHeaderRenderer + * @return TableCellRenderer + */ + protected TableCellRenderer createDefaultHeaderRenderer() + { + return new DefaultTableCellRenderer(); + } +} diff --git a/libjava/classpath/javax/swing/table/TableColumnModel.java b/libjava/classpath/javax/swing/table/TableColumnModel.java new file mode 100644 index 0000000..76a1456 --- /dev/null +++ b/libjava/classpath/javax/swing/table/TableColumnModel.java @@ -0,0 +1,187 @@ +/* TableColumnModel.java -- + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.table; + +import java.util.Enumeration; + +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.TableColumnModelListener; + +/** + * The interface used by {@link JTable} to access the columns in the table + * view. + * + * @author Andrew Selkirk + */ +public interface TableColumnModel +{ + /** + * Adds a column to the model. + * + * @param column the new column (<code>null</code> not permitted). + * + * @throws IllegalArgumentException if <code>column</code> is + * <code>null</code>. + */ + void addColumn(TableColumn column); + + /** + * Removes a column from the model. If <code>column</code> is not defined + * in the model, this method does nothing. + * + * @param column TableColumn + */ + void removeColumn(TableColumn column); + + /** + * Moves a column. + * + * @param columnIndex Index of column to move + * @param newIndex New index of column + */ + void moveColumn(int columnIndex, int newIndex); + + /** + * setColumnMargin + * @param margin Margin of column + */ + void setColumnMargin(int margin); + + /** + * Returns the number of columns in the model. + * + * @return The column count + */ + int getColumnCount(); + + /** + * getColumns + * @return Enumeration of columns + */ + Enumeration getColumns(); + + /** + * Returns the index of the {@link TableColumn} with the given identifier. + * + * @param identifier the identifier (<code>null</code> not permitted). + * + * @return The index of the {@link TableColumn} with the given identifier. + * + * @throws IllegalArgumentException if <code>identifier</code> is + * <code>null</code> or there is no column with that identifier. + */ + int getColumnIndex(Object columnIdentifier); + + /** + * Returns the <code>TableColumn</code> at the specified index. + * + * @param columnIndex the column index. + * + * @return The table column. + */ + TableColumn getColumn(int columnIndex); + + /** + * Returns the column margin. + * + * @return The column margin. + */ + int getColumnMargin(); + + /** + * getColumnIndexAtX + * @return Column index as position x + */ + int getColumnIndexAtX(int xPosition); + + /** + * getTotalColumnWidth + * @return Total column width + */ + int getTotalColumnWidth(); + + /** + * setColumnSelectionAllowed + * @param value Set column selection + */ + void setColumnSelectionAllowed(boolean value); + + /** + * getColumnSelectionAllowed + * @return true if column selection allowed, false otherwise + */ + boolean getColumnSelectionAllowed(); + + /** + * getSelectedColumns + * @return Selected columns + */ + int[] getSelectedColumns(); + + /** + * getSelectedColumnCount + * @return Count of selected columns + */ + int getSelectedColumnCount(); + + /** + * setSelectionModel + * @param model ListSelectionModel + */ + void setSelectionModel(ListSelectionModel model); + + /** + * getSelectionModel + * @param column TableColumn + */ + ListSelectionModel getSelectionModel(); + + /** + * addColumnModelListener + * @param listener TableColumnModelListener + */ + void addColumnModelListener(TableColumnModelListener listener); + + /** + * removeColumnModelListener + * @param listener TableColumnModelListener + */ + void removeColumnModelListener(TableColumnModelListener listener); +} diff --git a/libjava/classpath/javax/swing/table/TableModel.java b/libjava/classpath/javax/swing/table/TableModel.java new file mode 100644 index 0000000..016ae17 --- /dev/null +++ b/libjava/classpath/javax/swing/table/TableModel.java @@ -0,0 +1,134 @@ +/* TableModel.java -- + Copyright (C) 2002, 2005, Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.table; + +import javax.swing.event.TableModelListener; + +/** + * A <code>TableModel</code> is a two dimensional data structure that + * can store arbitrary <code>Object</code> instances, usually for the + * purpose of display in a {@link javax.swing.JTable} component. Individual + * objects can be accessed by specifying the row index and column index for + * the object. Each column in the model has a name associated with it. + * <p> + * The {@link DefaultTableModel} class provides one implementation of + * this interface. + * + * @author Andrew Selkirk + */ +public interface TableModel +{ + /** + * Returns the number of rows in the model. + * + * @return The row count. + */ + int getRowCount(); + + /** + * Returns the number of columns in the model. + * + * @return The column count + */ + int getColumnCount(); + + /** + * Returns the name of a column in the model. + * + * @param columnIndex the column index. + * + * @return The column name. + */ + String getColumnName(int columnIndex); + + /** + * Returns the <code>Class</code> for all <code>Object</code> instances + * in the specified column. + * + * @param columnIndex the column index. + * + * @return The class. + */ + Class getColumnClass(int columnIndex); + + /** + * Returns <code>true</code> if the cell is editable, and <code>false</code> + * otherwise. + * + * @param rowIndex the row index. + * @param columnIndex the column index. + * + * @return <code>true</code> if editable, <code>false</code> otherwise. + */ + boolean isCellEditable(int rowIndex, int columnIndex); + + /** + * Returns the value (<code>Object</code>) at a particular cell in the + * table. + * + * @param rowIndex the row index. + * @param columnIndex the column index. + * + * @return The value at the specified cell. + */ + Object getValueAt(int rowIndex, int columnIndex); + + /** + * Sets the value at a particular cell in the table. + * + * @param aValue the value (<code>null</code> permitted). + * @param rowIndex the row index. + * @param columnIndex the column index. + */ + void setValueAt(Object aValue, int rowIndex, int columnIndex); + + /** + * Adds a listener to the model. The listener will receive notification + * of updates to the model. + * + * @param listener the listener. + */ + void addTableModelListener(TableModelListener listener); + + /** + * Removes a listener from the model. + * + * @param listener the listener. + */ + void removeTableModelListener(TableModelListener listener); +} diff --git a/libjava/classpath/javax/swing/table/package.html b/libjava/classpath/javax/swing/table/package.html new file mode 100644 index 0000000..84e6f1a --- /dev/null +++ b/libjava/classpath/javax/swing/table/package.html @@ -0,0 +1,47 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<!-- package.html - describes classes in javax.swing.table package. + Copyright (C) 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. --> + +<html> +<head><title>GNU Classpath - javax.swing.table</title></head> + +<body> +<p>Interfaces and classes that support the {@link javax.swing.JTable} +component.</p> + +</body> +</html> |