001: package org.beryl.gui.table;
002:
003: /*
004: * @(#)TableMap.java 1.7 99/04/23
005: *
006: * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: */
032:
033: /**
034: * In a chain of data manipulators some behaviour is common. TableMap
035: * provides most of this behavour and can be subclassed by filters
036: * that only need to override a handful of specific methods. TableMap
037: * implements TableModel by routing all requests to its model, and
038: * TableModelListener by routing all events to its listeners. Inserting
039: * a TableMap which has not been subclassed into a chain of table filters
040: * should have no effect.
041: *
042: * @version 1.7 04/23/99
043: * @author Philip Milne */
044:
045: import javax.swing.event.TableModelEvent;
046: import javax.swing.event.TableModelListener;
047: import javax.swing.table.AbstractTableModel;
048: import javax.swing.table.TableModel;
049:
050: public class TableMap extends AbstractTableModel implements
051: TableModelListener {
052: protected TableModel model;
053:
054: public TableModel getModel() {
055: return model;
056: }
057:
058: public void setModel(TableModel model) {
059: this .model = model;
060: model.addTableModelListener(this );
061: }
062:
063: // By default, Implement TableModel by forwarding all messages
064: // to the model.
065:
066: public Object getValueAt(int aRow, int aColumn) {
067: return model.getValueAt(aRow, aColumn);
068: }
069:
070: public void setValueAt(Object aValue, int aRow, int aColumn) {
071: model.setValueAt(aValue, aRow, aColumn);
072: }
073:
074: public int getRowCount() {
075: return (model == null) ? 0 : model.getRowCount();
076: }
077:
078: public int getColumnCount() {
079: return (model == null) ? 0 : model.getColumnCount();
080: }
081:
082: public String getColumnName(int aColumn) {
083: return model.getColumnName(aColumn);
084: }
085:
086: public Class getColumnClass(int aColumn) {
087: return model.getColumnClass(aColumn);
088: }
089:
090: public boolean isCellEditable(int row, int column) {
091: return model.isCellEditable(row, column);
092: }
093:
094: //
095: // Implementation of the TableModelListener interface,
096: //
097:
098: // By default forward all events to all the listeners.
099: public void tableChanged(TableModelEvent e) {
100: fireTableChanged(e);
101: }
102: }
|