Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/javax/swing/AbstractCellEditor.java
41153 views
1
/*
2
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package javax.swing;
27
28
import javax.swing.event.*;
29
import java.util.EventObject;
30
import java.io.Serializable;
31
32
/**
33
*
34
* A base class for <code>CellEditors</code>, providing default
35
* implementations for the methods in the <code>CellEditor</code>
36
* interface except <code>getCellEditorValue()</code>.
37
* Like the other abstract implementations in Swing, also manages a list
38
* of listeners.
39
*
40
* <p>
41
* <strong>Warning:</strong>
42
* Serialized objects of this class will not be compatible with
43
* future Swing releases. The current serialization support is
44
* appropriate for short term storage or RMI between applications running
45
* the same version of Swing. As of 1.4, support for long term storage
46
* of all JavaBeans
47
* has been added to the <code>java.beans</code> package.
48
* Please see {@link java.beans.XMLEncoder}.
49
*
50
* @author Philip Milne
51
* @since 1.3
52
*/
53
@SuppressWarnings("serial") // Same-version serialization only
54
public abstract class AbstractCellEditor implements CellEditor, Serializable {
55
56
/**
57
* The list of listeners.
58
*/
59
protected EventListenerList listenerList = new EventListenerList();
60
/**
61
* The change event.
62
*/
63
protected transient ChangeEvent changeEvent = null;
64
65
/**
66
* Constructor for subclasses to call.
67
*/
68
protected AbstractCellEditor() {}
69
70
// Force this to be implemented.
71
// public Object getCellEditorValue()
72
73
/**
74
* Returns true.
75
* @param e an event object
76
* @return true
77
*/
78
public boolean isCellEditable(EventObject e) {
79
return true;
80
}
81
82
/**
83
* Returns true.
84
* @param anEvent an event object
85
* @return true
86
*/
87
public boolean shouldSelectCell(EventObject anEvent) {
88
return true;
89
}
90
91
/**
92
* Calls <code>fireEditingStopped</code> and returns true.
93
* @return true
94
*/
95
public boolean stopCellEditing() {
96
fireEditingStopped();
97
return true;
98
}
99
100
/**
101
* Calls <code>fireEditingCanceled</code>.
102
*/
103
public void cancelCellEditing() {
104
fireEditingCanceled();
105
}
106
107
/**
108
* Adds a <code>CellEditorListener</code> to the listener list.
109
* @param l the new listener to be added
110
*/
111
public void addCellEditorListener(CellEditorListener l) {
112
listenerList.add(CellEditorListener.class, l);
113
}
114
115
/**
116
* Removes a <code>CellEditorListener</code> from the listener list.
117
* @param l the listener to be removed
118
*/
119
public void removeCellEditorListener(CellEditorListener l) {
120
listenerList.remove(CellEditorListener.class, l);
121
}
122
123
/**
124
* Returns an array of all the <code>CellEditorListener</code>s added
125
* to this AbstractCellEditor with addCellEditorListener().
126
*
127
* @return all of the <code>CellEditorListener</code>s added or an empty
128
* array if no listeners have been added
129
* @since 1.4
130
*/
131
public CellEditorListener[] getCellEditorListeners() {
132
return listenerList.getListeners(CellEditorListener.class);
133
}
134
135
/**
136
* Notifies all listeners that have registered interest for
137
* notification on this event type. The event instance
138
* is created lazily.
139
*
140
* @see EventListenerList
141
*/
142
protected void fireEditingStopped() {
143
// Guaranteed to return a non-null array
144
Object[] listeners = listenerList.getListenerList();
145
// Process the listeners last to first, notifying
146
// those that are interested in this event
147
for (int i = listeners.length-2; i>=0; i-=2) {
148
if (listeners[i]==CellEditorListener.class) {
149
// Lazily create the event:
150
if (changeEvent == null)
151
changeEvent = new ChangeEvent(this);
152
((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);
153
}
154
}
155
}
156
157
/**
158
* Notifies all listeners that have registered interest for
159
* notification on this event type. The event instance
160
* is created lazily.
161
*
162
* @see EventListenerList
163
*/
164
protected void fireEditingCanceled() {
165
// Guaranteed to return a non-null array
166
Object[] listeners = listenerList.getListenerList();
167
// Process the listeners last to first, notifying
168
// those that are interested in this event
169
for (int i = listeners.length-2; i>=0; i-=2) {
170
if (listeners[i]==CellEditorListener.class) {
171
// Lazily create the event:
172
if (changeEvent == null)
173
changeEvent = new ChangeEvent(this);
174
((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);
175
}
176
}
177
}
178
}
179
180