KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > idltree > AbstractCellEditor


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 /***************************************************************************/
25 package org.coach.idltree;
26
27 import java.awt.*;
28 import javax.swing.*;
29 import javax.swing.event.*;
30 import javax.swing.tree.*;
31 import java.awt.event.*;
32 import java.util.*;
33
34 public abstract class AbstractCellEditor implements TreeCellEditor {
35     protected EventListenerList listenerList = new EventListenerList();
36     protected Object JavaDoc value;
37     protected ChangeEvent changeEvent = null;
38     protected int clickCountToStart = 2;
39
40     public void addCellEditorListener(CellEditorListener l) {
41         listenerList.add(CellEditorListener.class, l);
42     }
43
44     public void removeCellEditorListener(CellEditorListener l) {
45         listenerList.remove(CellEditorListener.class, l);
46     }
47
48     protected void fireEditingStopped() {
49         Object JavaDoc[] listeners = listenerList.getListenerList();
50         for (int i = listeners.length - 2; i >= 0; i -= 2) {
51             if (listeners[i] == CellEditorListener.class) {
52                 if (changeEvent == null) {
53                     changeEvent = new ChangeEvent(this);
54                 }
55                 ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);
56             }
57         }
58     }
59
60     protected void fireEditingCanceled() {
61         Object JavaDoc[] listeners = listenerList.getListenerList();
62         for (int i = listeners.length - 2; i >= 0; i -= 2) {
63             if (listeners[i] == CellEditorListener.class) {
64                 if (changeEvent == null) {
65                     changeEvent = new ChangeEvent(this);
66                 }
67                 ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);
68             }
69         }
70     }
71
72     public Object JavaDoc getCellEditorValue() {
73         return value;
74     }
75
76     public void setClickCountToStart(int count) {
77         clickCountToStart = count;
78     }
79
80     public int getClickCountToStart() {
81         return clickCountToStart;
82     }
83
84     public boolean isCellEditable(EventObject e) {
85         if (e instanceof MouseEvent) {
86             if (((MouseEvent)e).getClickCount() < clickCountToStart) {
87                 return false;
88             }
89         }
90         return true;
91     }
92
93     public boolean shouldSelectCell(EventObject e) {
94         return true;
95     }
96
97     public boolean stopCellEditing() {
98         fireEditingStopped();
99         return true;
100     }
101
102     public void cancelCellEditing() {
103         fireEditingCanceled();
104     }
105 }
106
Popular Tags