1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.lf5.viewer.categoryexplorer;
18
19 import java.awt.Component;
20 import java.awt.event.MouseEvent;
21 import java.util.EventObject;
22
23 import javax.swing.JTable;
24 import javax.swing.JTree;
25 import javax.swing.event.CellEditorListener;
26 import javax.swing.event.ChangeEvent;
27 import javax.swing.event.EventListenerList;
28 import javax.swing.table.TableCellEditor;
29 import javax.swing.tree.TreeCellEditor;
30
31
32
33
34
35
36
37
38
39
40
41 public class CategoryAbstractCellEditor implements TableCellEditor, TreeCellEditor {
42
43
44
45
46
47
48
49 protected EventListenerList _listenerList = new EventListenerList();
50 protected Object _value;
51 protected ChangeEvent _changeEvent = null;
52 protected int _clickCountToStart = 1;
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public Object getCellEditorValue() {
67 return _value;
68 }
69
70 public void setCellEditorValue(Object value) {
71 _value = value;
72 }
73
74 public void setClickCountToStart(int count) {
75 _clickCountToStart = count;
76 }
77
78 public int getClickCountToStart() {
79 return _clickCountToStart;
80 }
81
82 public boolean isCellEditable(EventObject anEvent) {
83 if (anEvent instanceof MouseEvent) {
84 if (((MouseEvent) anEvent).getClickCount() < _clickCountToStart) {
85 return false;
86 }
87 }
88 return true;
89 }
90
91 public boolean shouldSelectCell(EventObject anEvent) {
92 if (this.isCellEditable(anEvent)) {
93 if (anEvent == null ||
94 ((MouseEvent) anEvent).getClickCount() >= _clickCountToStart) {
95 return true;
96 }
97 }
98 return false;
99 }
100
101 public boolean stopCellEditing() {
102 fireEditingStopped();
103 return true;
104 }
105
106 public void cancelCellEditing() {
107 fireEditingCanceled();
108 }
109
110 public void addCellEditorListener(CellEditorListener l) {
111 _listenerList.add(CellEditorListener.class, l);
112 }
113
114 public void removeCellEditorListener(CellEditorListener l) {
115 _listenerList.remove(CellEditorListener.class, l);
116 }
117
118 public Component getTreeCellEditorComponent(
119 JTree tree, Object value,
120 boolean isSelected,
121 boolean expanded,
122 boolean leaf, int row) {
123 return null;
124 }
125
126 public Component getTableCellEditorComponent(
127 JTable table, Object value,
128 boolean isSelected,
129 int row, int column) {
130 return null;
131 }
132
133
134
135
136 protected void fireEditingStopped() {
137 Object[] listeners = _listenerList.getListenerList();
138
139 for (int i = listeners.length - 2; i >= 0; i -= 2) {
140 if (listeners[i] == CellEditorListener.class) {
141 if (_changeEvent == null) {
142 _changeEvent = new ChangeEvent(this);
143 }
144
145 ((CellEditorListener) listeners[i + 1]).editingStopped(_changeEvent);
146 }
147 }
148 }
149
150 protected void fireEditingCanceled() {
151 Object[] listeners = _listenerList.getListenerList();
152
153 for (int i = listeners.length - 2; i >= 0; i -= 2) {
154 if (listeners[i] == CellEditorListener.class) {
155 if (_changeEvent == null) {
156 _changeEvent = new ChangeEvent(this);
157 }
158
159 ((CellEditorListener) listeners[i + 1]).editingCanceled(_changeEvent);
160 }
161 }
162 }
163
164
165
166
167
168
169
170
171
172 }