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