GNU Classpath (0.20) | |
Frames | No Frames |
1: /* AbstractCellEditor.java -- 2: Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package javax.swing; 40: 41: import java.io.Serializable; 42: import java.util.EventObject; 43: 44: import javax.swing.event.CellEditorListener; 45: import javax.swing.event.ChangeEvent; 46: import javax.swing.event.EventListenerList; 47: 48: /** 49: * An abstract superclass for table and tree cell editors. This provides some 50: * common shared functionality. 51: * 52: * @author Andrew Selkirk 53: */ 54: public abstract class AbstractCellEditor 55: implements CellEditor, Serializable 56: { 57: private static final long serialVersionUID = -1048006551406220959L; 58: 59: /** 60: * Our Swing event listeners. 61: */ 62: protected EventListenerList listenerList; 63: 64: /** 65: * The cached ChangeEvent. 66: */ 67: protected transient ChangeEvent changeEvent; 68: 69: /** 70: * Creates a new instance of AbstractCellEditor. 71: */ 72: public AbstractCellEditor() { 73: listenerList = new EventListenerList(); 74: changeEvent = new ChangeEvent(this); 75: } // AbstractCellEditor() 76: 77: /** 78: * Returns <code>true</code> if the cell is editable using 79: * <code>event</code>, <code>false</code> 80: * if it's not. The default behaviour is to return <code>true</code>. 81: * 82: * @param event an event 83: * 84: * @return <code>true</code> if the cell is editable using 85: * <code>event</code>, <code>false</code> if it's not 86: */ 87: public boolean isCellEditable(EventObject event) { 88: return true; 89: } // isCellEditable() 90: 91: /** 92: * Returns <code>true</code> if the editing cell should be selected, 93: * <code>false</code> otherwise. This is usually returning <code>true</code>, 94: * but in some special cases it might be useful not to switch cell selection 95: * when editing one cell. 96: * 97: * @param event an event 98: * 99: * @return <code>true</code> if the editing cell should be selected, 100: * <code>false</code> otherwise 101: */ 102: public boolean shouldSelectCell(EventObject event) { 103: return true; 104: } // shouldSelectCell() 105: 106: /** 107: * Stop editing the cell and accept any partial value that has been entered 108: * into the cell. 109: * 110: * @returns <code>true</code> if editing has been stopped successfully, 111: * <code>false</code>otherwise 112: */ 113: public boolean stopCellEditing() { 114: fireEditingStopped(); 115: return true; 116: } // stopCellEditing() 117: 118: /** 119: * Stop editing the cell and do not accept any partial value that has 120: * been entered into the cell. 121: */ 122: public void cancelCellEditing() { 123: fireEditingCanceled(); 124: } // cancelCellEditing() 125: 126: /** 127: * Adds a CellEditorListener to the list of CellEditorListeners of this 128: * CellEditor. 129: * 130: * @param listener the CellEditorListener to add 131: */ 132: public void addCellEditorListener (CellEditorListener listener) 133: { 134: listenerList.add (CellEditorListener.class, listener); 135: } 136: 137: /** 138: * Removes the specified CellEditorListener from the list of the 139: * CellEditorListeners of this CellEditor. 140: * 141: * @param listener the CellEditorListener to remove 142: */ 143: public void removeCellEditorListener (CellEditorListener listener) 144: { 145: listenerList.remove (CellEditorListener.class, listener); 146: } 147: 148: /** 149: * Returns the list of CellEditorListeners that have been registered 150: * in this CellEditor. 151: * 152: * @return the list of CellEditorListeners that have been registered 153: * in this CellEditor 154: * 155: * @since 1.4 156: */ 157: public CellEditorListener[] getCellEditorListeners() 158: { 159: return (CellEditorListener[]) listenerList.getListeners 160: (CellEditorListener.class); 161: } 162: 163: /** 164: * Notifies all registered listeners that the editing of the cell has has been 165: * stopped. 166: */ 167: protected void fireEditingStopped() 168: { 169: CellEditorListener[] listeners = getCellEditorListeners(); 170: 171: for (int index = 0; index < listeners.length; index++) 172: { 173: listeners[index].editingStopped(changeEvent); 174: } 175: } 176: 177: /** 178: * Notifies all registered listeners that the editing of the cell has 179: * has been canceled. 180: */ 181: protected void fireEditingCanceled() 182: { 183: CellEditorListener[] listeners = getCellEditorListeners(); 184: 185: for (int index = 0; index < listeners.length; index++) 186: { 187: listeners[index].editingCanceled(changeEvent); 188: } 189: } 190: }
GNU Classpath (0.20) |