KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > categoryexplorer > CategoryAbstractCellEditor


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.log4j.lf5.viewer.categoryexplorer;
17
18 import javax.swing.*;
19 import javax.swing.event.CellEditorListener JavaDoc;
20 import javax.swing.event.ChangeEvent JavaDoc;
21 import javax.swing.event.EventListenerList JavaDoc;
22 import javax.swing.table.TableCellEditor JavaDoc;
23 import javax.swing.tree.TreeCellEditor JavaDoc;
24 import java.awt.*;
25 import java.awt.event.MouseEvent JavaDoc;
26 import java.util.EventObject JavaDoc;
27
28 /**
29  * CategoryAbstractCellEditor. Base class to handle the some common
30  * details of cell editing.
31  *
32  * @author Michael J. Sikorsky
33  * @author Robert Shaw
34  */

35
36 // Contributed by ThoughtWorks Inc.
37

38 public class CategoryAbstractCellEditor implements TableCellEditor JavaDoc, TreeCellEditor JavaDoc {
39   //--------------------------------------------------------------------------
40
// Constants:
41
//--------------------------------------------------------------------------
42

43   //--------------------------------------------------------------------------
44
// Protected Variables:
45
//--------------------------------------------------------------------------
46
protected EventListenerList JavaDoc _listenerList = new EventListenerList JavaDoc();
47   protected Object JavaDoc _value;
48   protected ChangeEvent JavaDoc _changeEvent = null;
49   protected int _clickCountToStart = 1;
50
51   //--------------------------------------------------------------------------
52
// Private Variables:
53
//--------------------------------------------------------------------------
54

55   //--------------------------------------------------------------------------
56
// Constructors:
57
//--------------------------------------------------------------------------
58

59   //--------------------------------------------------------------------------
60
// Public Methods:
61
//--------------------------------------------------------------------------
62

63   public Object JavaDoc getCellEditorValue() {
64     return _value;
65   }
66
67   public void setCellEditorValue(Object JavaDoc value) {
68     _value = value;
69   }
70
71   public void setClickCountToStart(int count) {
72     _clickCountToStart = count;
73   }
74
75   public int getClickCountToStart() {
76     return _clickCountToStart;
77   }
78
79   public boolean isCellEditable(EventObject JavaDoc anEvent) {
80     if (anEvent instanceof MouseEvent JavaDoc) {
81       if (((MouseEvent JavaDoc) anEvent).getClickCount() < _clickCountToStart) {
82         return false;
83       }
84     }
85     return true;
86   }
87
88   public boolean shouldSelectCell(EventObject JavaDoc anEvent) {
89     if (this.isCellEditable(anEvent)) {
90       if (anEvent == null ||
91           ((MouseEvent JavaDoc) anEvent).getClickCount() >= _clickCountToStart) {
92         return true;
93       }
94     }
95     return false;
96   }
97
98   public boolean stopCellEditing() {
99     fireEditingStopped();
100     return true;
101   }
102
103   public void cancelCellEditing() {
104     fireEditingCanceled();
105   }
106
107   public void addCellEditorListener(CellEditorListener JavaDoc l) {
108     _listenerList.add(CellEditorListener JavaDoc.class, l);
109   }
110
111   public void removeCellEditorListener(CellEditorListener JavaDoc l) {
112     _listenerList.remove(CellEditorListener JavaDoc.class, l);
113   }
114
115   public Component getTreeCellEditorComponent(
116       JTree tree, Object JavaDoc value,
117       boolean isSelected,
118       boolean expanded,
119       boolean leaf, int row) {
120     return null;
121   }
122
123   public Component getTableCellEditorComponent(
124       JTable table, Object JavaDoc value,
125       boolean isSelected,
126       int row, int column) {
127     return null;
128   }
129
130   //--------------------------------------------------------------------------
131
// Protected Methods:
132
//--------------------------------------------------------------------------
133
protected void fireEditingStopped() {
134     Object JavaDoc[] listeners = _listenerList.getListenerList();
135
136     for (int i = listeners.length - 2; i >= 0; i -= 2) {
137       if (listeners[i] == CellEditorListener JavaDoc.class) {
138         if (_changeEvent == null) {
139           _changeEvent = new ChangeEvent JavaDoc(this);
140         }
141
142         ((CellEditorListener JavaDoc) listeners[i + 1]).editingStopped(_changeEvent);
143       }
144     }
145   }
146
147   protected void fireEditingCanceled() {
148     Object JavaDoc[] listeners = _listenerList.getListenerList();
149
150     for (int i = listeners.length - 2; i >= 0; i -= 2) {
151       if (listeners[i] == CellEditorListener JavaDoc.class) {
152         if (_changeEvent == null) {
153           _changeEvent = new ChangeEvent JavaDoc(this);
154         }
155
156         ((CellEditorListener JavaDoc) listeners[i + 1]).editingCanceled(_changeEvent);
157       }
158     }
159   }
160
161   //--------------------------------------------------------------------------
162
// Private Methods:
163
//--------------------------------------------------------------------------
164

165   //--------------------------------------------------------------------------
166
// Nested Top-Level Classes or Interfaces:
167
//--------------------------------------------------------------------------
168

169 }
170
Popular Tags