author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 55 | 5ecee29e98d8 |
child 1017 | 8d24d37ceed8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
25 |
|
2 | 26 |
package sun.tools.jconsole.inspector; |
27 |
||
28 |
import java.awt.Component; |
|
29 |
import java.util.EventObject; |
|
30 |
import java.awt.event.*; |
|
31 |
import java.awt.dnd.DragSourceDropEvent; |
|
32 |
import javax.swing.*; |
|
33 |
import javax.swing.event.*; |
|
34 |
import javax.swing.table.*; |
|
35 |
||
36 |
@SuppressWarnings("serial") |
|
37 |
public class XTextFieldEditor extends XTextField implements TableCellEditor { |
|
38 |
||
39 |
protected EventListenerList listenerList = new EventListenerList(); |
|
40 |
protected ChangeEvent changeEvent = new ChangeEvent(this); |
|
41 |
||
42 |
private FocusListener editorFocusListener = new FocusAdapter() { |
|
43 |
public void focusLost(FocusEvent e) { |
|
44 |
fireEditingStopped(); |
|
45 |
} |
|
46 |
}; |
|
47 |
||
48 |
public XTextFieldEditor() { |
|
49 |
super(); |
|
50 |
textField.addFocusListener(editorFocusListener); |
|
51 |
} |
|
52 |
||
53 |
//edition stopped ou JMenuItem selection & JTextField selection |
|
54 |
public void actionPerformed(ActionEvent e) { |
|
55 |
super.actionPerformed(e); |
|
56 |
if ((e.getSource() instanceof JMenuItem) || |
|
57 |
(e.getSource() instanceof JTextField)) { |
|
58 |
fireEditingStopped(); |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
//edition stopped on drag & drop success |
|
63 |
protected void dropSuccess() { |
|
64 |
fireEditingStopped(); |
|
65 |
} |
|
66 |
||
67 |
//TableCellEditor implementation |
|
68 |
||
69 |
public void addCellEditorListener(CellEditorListener listener) { |
|
70 |
listenerList.add(CellEditorListener.class,listener); |
|
71 |
} |
|
72 |
||
73 |
public void removeCellEditorListener(CellEditorListener listener) { |
|
74 |
listenerList.remove(CellEditorListener.class, listener); |
|
75 |
} |
|
76 |
||
77 |
protected void fireEditingStopped() { |
|
78 |
CellEditorListener listener; |
|
79 |
Object[] listeners = listenerList.getListenerList(); |
|
80 |
for (int i=0;i< listeners.length;i++) { |
|
81 |
if (listeners[i] == CellEditorListener.class) { |
|
82 |
listener = (CellEditorListener) listeners[i+1]; |
|
83 |
listener.editingStopped(changeEvent); |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
protected void fireEditingCanceled() { |
|
89 |
CellEditorListener listener; |
|
90 |
Object[] listeners = listenerList.getListenerList(); |
|
91 |
for (int i=0;i< listeners.length;i++) { |
|
92 |
if (listeners[i] == CellEditorListener.class) { |
|
93 |
listener = (CellEditorListener) listeners[i+1]; |
|
94 |
listener.editingCanceled(changeEvent); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
public void cancelCellEditing() { |
|
100 |
fireEditingCanceled(); |
|
101 |
} |
|
102 |
||
103 |
public boolean stopCellEditing() { |
|
104 |
fireEditingStopped(); |
|
105 |
return true; |
|
106 |
} |
|
107 |
||
108 |
public boolean isCellEditable(EventObject event) { |
|
109 |
return true; |
|
110 |
} |
|
111 |
||
112 |
public boolean shouldSelectCell(EventObject event) { |
|
113 |
return true; |
|
114 |
} |
|
115 |
||
116 |
public Object getCellEditorValue() { |
|
117 |
Object object = getValue(); |
|
118 |
||
119 |
if (object instanceof XObject) { |
|
120 |
return ((XObject) object).getObject(); |
|
121 |
} |
|
122 |
else { |
|
123 |
return object; |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
public Component getTableCellEditorComponent(JTable table, |
|
128 |
Object value, |
|
129 |
boolean isSelected, |
|
130 |
int row, |
|
131 |
int column) { |
|
132 |
String className; |
|
133 |
if (table instanceof XTable) { |
|
134 |
XTable mytable = (XTable) table; |
|
135 |
className = mytable.getClassName(row); |
|
136 |
} else { |
|
137 |
className = String.class.getName(); |
|
138 |
} |
|
139 |
try { |
|
140 |
init(value,Utils.getClass(className)); |
|
141 |
} |
|
142 |
catch(Exception e) {} |
|
143 |
||
144 |
return this; |
|
145 |
} |
|
146 |
||
147 |
} |