Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/puppycrawl/tools/checkstyle/gui/AbstractCellEditor.java


1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2002  Oliver Burn
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.gui;
21  
22  import java.util.EventObject;
23  import javax.swing.CellEditor;
24  import javax.swing.event.CellEditorListener;
25  import javax.swing.event.ChangeEvent;
26  import javax.swing.event.EventListenerList;
27  
28  /**
29   * Abstract implementation of a CellEditor.
30   *
31   * @author http://java.sun.com/products/jfc/tsc/articles/treetable2
32   */
33  public class AbstractCellEditor implements CellEditor
34  {
35      private EventListenerList mListenerList = new EventListenerList();
36  
37      /** @see CellEditor */
38      public Object getCellEditorValue()
39      {
40          return null;
41      }
42  
43      /** @see CellEditor */
44      public boolean isCellEditable(EventObject e)
45      {
46          return true;
47      }
48  
49      /** @see CellEditor */
50      public boolean shouldSelectCell(EventObject anEvent)
51      {
52          return false;
53      }
54  
55      /** @see CellEditor */
56      public boolean stopCellEditing()
57      {
58          return true;
59      }
60  
61      /** @see CellEditor */
62      public void cancelCellEditing()
63      {
64      }
65  
66      /** @see CellEditor */
67      public void addCellEditorListener(CellEditorListener l)
68      {
69          mListenerList.add(CellEditorListener.class, l);
70      }
71  
72      /** @see CellEditor */
73      public void removeCellEditorListener(CellEditorListener l)
74      {
75          mListenerList.remove(CellEditorListener.class, l);
76      }
77  
78      /*
79       * Notify all listeners that have registered interest for
80       * notification on this event type.
81       * @see EventListenerList
82       */
83      protected void fireEditingStopped()
84      {
85          // Guaranteed to return a non-null array
86          Object[] listeners = mListenerList.getListenerList();
87          // Process the listeners last to first, notifying
88          // those that are interested in this event
89          for (int i = listeners.length - 2; i >= 0; i -= 2) {
90              if (listeners[i] == CellEditorListener.class) {
91                  ((CellEditorListener) listeners[i + 1]).editingStopped(new ChangeEvent(this));
92              }
93          }
94      }
95  
96      /*
97       * Notify all listeners that have registered interest for
98       * notification on this event type.
99       * @see EventListenerList
100      */
101     protected void fireEditingCanceled()
102     {
103         // Guaranteed to return a non-null array
104         Object[] listeners = mListenerList.getListenerList();
105         // Process the listeners last to first, notifying
106         // those that are interested in this event
107         for (int i = listeners.length - 2; i >= 0; i -= 2) {
108             if (listeners[i] == CellEditorListener.class) {
109                 ((CellEditorListener) listeners[i + 1]).editingCanceled(new ChangeEvent(this));
110             }
111         }
112     }
113 }