001: ////////////////////////////////////////////////////////////////////////////////
002: // checkstyle: Checks Java source code for adherence to a set of rules.
003: // Copyright (C) 2001-2002 Oliver Burn
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: ////////////////////////////////////////////////////////////////////////////////
019:
020: package com.puppycrawl.tools.checkstyle.gui;
021:
022: import java.util.EventObject;
023: import javax.swing.CellEditor;
024: import javax.swing.event.CellEditorListener;
025: import javax.swing.event.ChangeEvent;
026: import javax.swing.event.EventListenerList;
027:
028: /**
029: * Abstract implementation of a CellEditor.
030: *
031: * @author http://java.sun.com/products/jfc/tsc/articles/treetable2
032: */
033: public class AbstractCellEditor implements CellEditor {
034: private final EventListenerList mListenerList = new EventListenerList();
035:
036: /** @see CellEditor */
037: public Object getCellEditorValue() {
038: return null;
039: }
040:
041: /** @see CellEditor */
042: public boolean isCellEditable(EventObject e) {
043: return true;
044: }
045:
046: /** @see CellEditor */
047: public boolean shouldSelectCell(EventObject anEvent) {
048: return false;
049: }
050:
051: /** @see CellEditor */
052: public boolean stopCellEditing() {
053: return true;
054: }
055:
056: /** @see CellEditor */
057: public void cancelCellEditing() {
058: }
059:
060: /** @see CellEditor */
061: public void addCellEditorListener(CellEditorListener l) {
062: mListenerList.add(CellEditorListener.class, l);
063: }
064:
065: /** @see CellEditor */
066: public void removeCellEditorListener(CellEditorListener l) {
067: mListenerList.remove(CellEditorListener.class, l);
068: }
069:
070: /*
071: * Notify all listeners that have registered interest for
072: * notification on this event type.
073: * @see EventListenerList
074: */
075: protected void fireEditingStopped() {
076: // Guaranteed to return a non-null array
077: final Object[] listeners = mListenerList.getListenerList();
078: // Process the listeners last to first, notifying
079: // those that are interested in this event
080: for (int i = listeners.length - 2; i >= 0; i -= 2) {
081: if (listeners[i] == CellEditorListener.class) {
082: ((CellEditorListener) listeners[i + 1])
083: .editingStopped(new ChangeEvent(this ));
084: }
085: }
086: }
087:
088: /*
089: * Notify all listeners that have registered interest for
090: * notification on this event type.
091: * @see EventListenerList
092: */
093: protected void fireEditingCanceled() {
094: // Guaranteed to return a non-null array
095: final Object[] listeners = mListenerList.getListenerList();
096: // Process the listeners last to first, notifying
097: // those that are interested in this event
098: for (int i = listeners.length - 2; i >= 0; i -= 2) {
099: if (listeners[i] == CellEditorListener.class) {
100: ((CellEditorListener) listeners[i + 1])
101: .editingCanceled(new ChangeEvent(this));
102: }
103: }
104: }
105: }
|