43 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
44 |
import java.awt.event.ItemEvent; |
import java.awt.event.ItemEvent; |
45 |
import java.awt.event.ItemListener; |
import java.awt.event.ItemListener; |
46 |
|
import java.awt.event.MouseEvent; |
47 |
import java.io.Serializable; |
import java.io.Serializable; |
48 |
import java.util.EventObject; |
import java.util.EventObject; |
49 |
|
|
50 |
|
import javax.swing.JTable; |
51 |
|
import javax.swing.JTextField; |
52 |
|
import javax.swing.event.CellEditorListener; |
53 |
import javax.swing.table.TableCellEditor; |
import javax.swing.table.TableCellEditor; |
54 |
import javax.swing.tree.TreeCellEditor; |
import javax.swing.tree.TreeCellEditor; |
55 |
|
|
95 |
* |
* |
96 |
* @param event TODO |
* @param event TODO |
97 |
*/ |
*/ |
98 |
public void setValue(Object event) |
public void setValue(Object value) |
99 |
{ |
{ |
100 |
|
// TODO: should be setting the value in the editorComp |
101 |
|
this.value = value; |
102 |
} |
} |
103 |
|
|
104 |
/** |
/** |
108 |
*/ |
*/ |
109 |
public Object getCellEditorValue() |
public Object getCellEditorValue() |
110 |
{ |
{ |
111 |
return null; // TODO |
// TODO: should be getting the updated value from the editorComp |
112 |
|
return value; |
113 |
} // getCellEditorValue() |
} // getCellEditorValue() |
114 |
|
|
115 |
/** |
/** |
121 |
*/ |
*/ |
122 |
public boolean isCellEditable(EventObject event) |
public boolean isCellEditable(EventObject event) |
123 |
{ |
{ |
124 |
return false; // TODO |
if (!(event instanceof MouseEvent)) |
125 |
|
return true; |
126 |
|
|
127 |
|
//Todo: if the right number of clicks has occured, return true; |
128 |
|
return false; |
129 |
} // isCellEditable() |
} // isCellEditable() |
130 |
|
|
131 |
/** |
/** |
137 |
*/ |
*/ |
138 |
public boolean shouldSelectCell(EventObject event) |
public boolean shouldSelectCell(EventObject event) |
139 |
{ |
{ |
140 |
return false; // TODO |
// return true to indicate that the editing cell may be selected |
141 |
|
return true; |
142 |
} // shouldSelectCell() |
} // shouldSelectCell() |
143 |
|
|
144 |
/** |
/** |
148 |
*/ |
*/ |
149 |
public boolean stopCellEditing() |
public boolean stopCellEditing() |
150 |
{ |
{ |
151 |
return false; // TODO |
fireEditingStopped(); |
152 |
|
return true; |
153 |
} // stopCellEditing() |
} // stopCellEditing() |
154 |
|
|
155 |
/** |
/** |
157 |
*/ |
*/ |
158 |
public void cancelCellEditing() |
public void cancelCellEditing() |
159 |
{ |
{ |
160 |
// TODO |
fireEditingCanceled(); |
161 |
} // cancelCellEditing() |
} // cancelCellEditing() |
162 |
|
|
163 |
/** |
/** |
169 |
*/ |
*/ |
170 |
public boolean startCellEditing(EventObject event) |
public boolean startCellEditing(EventObject event) |
171 |
{ |
{ |
172 |
return false; // TODO |
// return true to indicate that editing has begun |
173 |
|
return true; |
174 |
} // startCellEditing() |
} // startCellEditing() |
175 |
|
|
176 |
/** |
/** |
180 |
*/ |
*/ |
181 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
182 |
{ |
{ |
183 |
// TODO |
stopCellEditing(); |
184 |
} // actionPerformed() |
} // actionPerformed() |
185 |
|
|
186 |
/** |
/** |
190 |
*/ |
*/ |
191 |
public void itemStateChanged(ItemEvent event) |
public void itemStateChanged(ItemEvent event) |
192 |
{ |
{ |
193 |
// TODO |
stopCellEditing(); |
194 |
} // itemStateChanged() |
} // itemStateChanged() |
195 |
|
|
196 |
|
void fireEditingStopped() |
197 |
|
{ |
198 |
|
CellEditorListener[] listeners = getCellEditorListeners(); |
199 |
|
for (int index = 0; index < listeners.length; index++) |
200 |
|
listeners[index].editingStopped(changeEvent); |
201 |
|
|
202 |
|
} |
203 |
|
|
204 |
|
void fireEditingCanceled() |
205 |
|
{ |
206 |
|
CellEditorListener[] listeners = getCellEditorListeners(); |
207 |
|
for (int index = 0; index < listeners.length; index++) |
208 |
|
listeners[index].editingCanceled(changeEvent); |
209 |
|
} |
210 |
} // EditorDelegate |
} // EditorDelegate |
211 |
|
|
212 |
/** |
/** |
231 |
*/ |
*/ |
232 |
public DefaultCellEditor(JTextField textfield) |
public DefaultCellEditor(JTextField textfield) |
233 |
{ |
{ |
234 |
// TODO |
editorComponent = textfield; |
235 |
|
clickCountToStart = 2; |
236 |
} // DefaultCellEditor() |
} // DefaultCellEditor() |
237 |
|
|
238 |
/** |
/** |
242 |
*/ |
*/ |
243 |
public DefaultCellEditor(JCheckBox checkbox) |
public DefaultCellEditor(JCheckBox checkbox) |
244 |
{ |
{ |
245 |
// TODO |
editorComponent = checkbox; |
246 |
|
clickCountToStart = 1; |
247 |
} // DefaultCellEditor() |
} // DefaultCellEditor() |
248 |
|
|
249 |
/** |
/** |
253 |
*/ |
*/ |
254 |
public DefaultCellEditor(JComboBox combobox) |
public DefaultCellEditor(JComboBox combobox) |
255 |
{ |
{ |
256 |
// TODO |
editorComponent = combobox; |
257 |
|
clickCountToStart = 1; |
258 |
} // DefaultCellEditor() |
} // DefaultCellEditor() |
259 |
|
|
260 |
/** |
/** |
264 |
*/ |
*/ |
265 |
public Component getComponent() |
public Component getComponent() |
266 |
{ |
{ |
267 |
return null; // TODO |
return editorComponent; |
268 |
} // getComponent() |
} // getComponent() |
269 |
|
|
270 |
/** |
/** |
274 |
*/ |
*/ |
275 |
public int getClickCountToStart() |
public int getClickCountToStart() |
276 |
{ |
{ |
277 |
return 0; // TODO |
return clickCountToStart; |
278 |
} // getClickCountToStart() |
} // getClickCountToStart() |
279 |
|
|
280 |
/** |
/** |
284 |
*/ |
*/ |
285 |
public void setClickCountToStart(int count) |
public void setClickCountToStart(int count) |
286 |
{ |
{ |
287 |
// TODO |
clickCountToStart = count; |
288 |
} // setClickCountToStart() |
} // setClickCountToStart() |
289 |
|
|
290 |
/** |
/** |
294 |
*/ |
*/ |
295 |
public Object getCellEditorValue() |
public Object getCellEditorValue() |
296 |
{ |
{ |
297 |
return null; // TODO |
return delegate.getCellEditorValue(); |
298 |
} // getCellEditorValue() |
} // getCellEditorValue() |
299 |
|
|
300 |
/** |
/** |
306 |
*/ |
*/ |
307 |
public boolean isCellEditable(EventObject event) |
public boolean isCellEditable(EventObject event) |
308 |
{ |
{ |
309 |
return false; // TODO |
return delegate.isCellEditable(event); |
310 |
} // isCellEditable() |
} // isCellEditable() |
311 |
|
|
312 |
/** |
/** |
318 |
*/ |
*/ |
319 |
public boolean shouldSelectCell(EventObject event) |
public boolean shouldSelectCell(EventObject event) |
320 |
{ |
{ |
321 |
return false; // TODO |
return delegate.shouldSelectCell(event); |
322 |
} // shouldSelectCell() |
} // shouldSelectCell() |
323 |
|
|
324 |
/** |
/** |
328 |
*/ |
*/ |
329 |
public boolean stopCellEditing() |
public boolean stopCellEditing() |
330 |
{ |
{ |
331 |
return false; // TODO |
return delegate.stopCellEditing(); |
332 |
} // stopCellEditing() |
} // stopCellEditing() |
333 |
|
|
334 |
/** |
/** |
336 |
*/ |
*/ |
337 |
public void cancelCellEditing() |
public void cancelCellEditing() |
338 |
{ |
{ |
339 |
// TODO |
delegate.cancelCellEditing(); |
340 |
} // cancelCellEditing() |
} // cancelCellEditing() |
341 |
|
|
342 |
/** |
/** |
370 |
* |
* |
371 |
* @returns Component |
* @returns Component |
372 |
*/ |
*/ |
373 |
public Component getTableCellEditorComponent(JTable tree, Object value, |
public Component getTableCellEditorComponent(JTable table, Object value, |
374 |
boolean isSelected, int row, |
boolean isSelected, int row, |
375 |
int column) |
int column) |
376 |
{ |
{ |
377 |
return null; // TODO |
// NOTE: as specified by Sun, we don't call new() everytime, we return |
378 |
|
// editorComponent on each call to getTableCellEditorComponent or |
379 |
|
// getTreeCellEditorComponent. However, currently JTextFields have a |
380 |
|
// problem with getting rid of old text, so without calling new() there |
381 |
|
// are some strange results. If you edit more than one cell in the table |
382 |
|
// text from previously edited cells may unexpectedly show up in the |
383 |
|
// cell you are currently editing. This will be fixed automatically |
384 |
|
// when JTextField is fixed. |
385 |
|
if (editorComponent instanceof JTextField) |
386 |
|
{ |
387 |
|
((JTextField)editorComponent).setText(value.toString()); |
388 |
|
delegate = new EditorDelegate(); |
389 |
|
((JTextField)editorComponent).addActionListener(delegate); |
390 |
|
} |
391 |
|
else |
392 |
|
{ |
393 |
|
// TODO |
394 |
|
} |
395 |
|
return editorComponent; |
396 |
} // getTableCellEditorComponent() |
} // getTableCellEditorComponent() |
397 |
|
|
398 |
|
|
399 |
} |
} |