author | vlivanov |
Thu, 18 Jan 2018 02:25:18 +0300 | |
changeset 48596 | 860326263d1f |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2004, 2008, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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; |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
29 |
import java.awt.event.ActionEvent; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
30 |
import java.awt.event.FocusAdapter; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
31 |
import java.awt.event.FocusEvent; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
32 |
import java.awt.event.FocusListener; |
2 | 33 |
import java.util.EventObject; |
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
34 |
import javax.swing.JMenuItem; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
35 |
import javax.swing.JTable; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
36 |
import javax.swing.JTextField; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
37 |
import javax.swing.event.CellEditorListener; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
38 |
import javax.swing.event.ChangeEvent; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
39 |
import javax.swing.event.EventListenerList; |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
40 |
import javax.swing.table.TableCellEditor; |
2 | 41 |
|
42 |
@SuppressWarnings("serial") |
|
43 |
public class XTextFieldEditor extends XTextField implements TableCellEditor { |
|
44 |
||
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
45 |
protected EventListenerList evtListenerList = new EventListenerList(); |
2 | 46 |
protected ChangeEvent changeEvent = new ChangeEvent(this); |
47 |
||
48 |
private FocusListener editorFocusListener = new FocusAdapter() { |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
49 |
@Override |
2 | 50 |
public void focusLost(FocusEvent e) { |
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
51 |
// fireEditingStopped(); |
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
52 |
// must not call fireEditingStopped() here! |
2 | 53 |
} |
54 |
}; |
|
55 |
||
56 |
public XTextFieldEditor() { |
|
57 |
super(); |
|
58 |
textField.addFocusListener(editorFocusListener); |
|
59 |
} |
|
60 |
||
61 |
//edition stopped ou JMenuItem selection & JTextField selection |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
62 |
@Override |
2 | 63 |
public void actionPerformed(ActionEvent e) { |
64 |
super.actionPerformed(e); |
|
65 |
if ((e.getSource() instanceof JMenuItem) || |
|
66 |
(e.getSource() instanceof JTextField)) { |
|
67 |
fireEditingStopped(); |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
//edition stopped on drag & drop success |
|
72 |
protected void dropSuccess() { |
|
73 |
fireEditingStopped(); |
|
74 |
} |
|
75 |
||
76 |
//TableCellEditor implementation |
|
77 |
||
78 |
public void addCellEditorListener(CellEditorListener listener) { |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
79 |
evtListenerList.add(CellEditorListener.class,listener); |
2 | 80 |
} |
81 |
||
82 |
public void removeCellEditorListener(CellEditorListener listener) { |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
83 |
evtListenerList.remove(CellEditorListener.class, listener); |
2 | 84 |
} |
85 |
||
86 |
protected void fireEditingStopped() { |
|
87 |
CellEditorListener listener; |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
88 |
Object[] listeners = evtListenerList.getListenerList(); |
2 | 89 |
for (int i=0;i< listeners.length;i++) { |
90 |
if (listeners[i] == CellEditorListener.class) { |
|
91 |
listener = (CellEditorListener) listeners[i+1]; |
|
92 |
listener.editingStopped(changeEvent); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
protected void fireEditingCanceled() { |
|
98 |
CellEditorListener listener; |
|
1017
8d24d37ceed8
6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents:
715
diff
changeset
|
99 |
Object[] listeners = evtListenerList.getListenerList(); |
2 | 100 |
for (int i=0;i< listeners.length;i++) { |
101 |
if (listeners[i] == CellEditorListener.class) { |
|
102 |
listener = (CellEditorListener) listeners[i+1]; |
|
103 |
listener.editingCanceled(changeEvent); |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
public void cancelCellEditing() { |
|
109 |
fireEditingCanceled(); |
|
110 |
} |
|
111 |
||
112 |
public boolean stopCellEditing() { |
|
113 |
fireEditingStopped(); |
|
114 |
return true; |
|
115 |
} |
|
116 |
||
117 |
public boolean isCellEditable(EventObject event) { |
|
118 |
return true; |
|
119 |
} |
|
120 |
||
121 |
public boolean shouldSelectCell(EventObject event) { |
|
122 |
return true; |
|
123 |
} |
|
124 |
||
125 |
public Object getCellEditorValue() { |
|
126 |
Object object = getValue(); |
|
127 |
||
128 |
if (object instanceof XObject) { |
|
129 |
return ((XObject) object).getObject(); |
|
130 |
} |
|
131 |
else { |
|
132 |
return object; |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
public Component getTableCellEditorComponent(JTable table, |
|
137 |
Object value, |
|
138 |
boolean isSelected, |
|
139 |
int row, |
|
140 |
int column) { |
|
141 |
String className; |
|
142 |
if (table instanceof XTable) { |
|
143 |
XTable mytable = (XTable) table; |
|
144 |
className = mytable.getClassName(row); |
|
145 |
} else { |
|
146 |
className = String.class.getName(); |
|
147 |
} |
|
148 |
try { |
|
149 |
init(value,Utils.getClass(className)); |
|
150 |
} |
|
151 |
catch(Exception e) {} |
|
152 |
||
153 |
return this; |
|
154 |
} |
|
155 |
||
156 |
} |