author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 55 | 5ecee29e98d8 |
child 5506 | 202f599c92aa |
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 |
// java import |
|
29 |
import javax.swing.*; |
|
30 |
||
31 |
// |
|
32 |
||
33 |
// java import |
|
34 |
import java.io.*; |
|
35 |
import java.awt.*; |
|
36 |
import java.awt.dnd.*; |
|
37 |
import java.awt.datatransfer.*; |
|
38 |
import java.net.*; |
|
39 |
// |
|
40 |
||
41 |
||
42 |
/** |
|
43 |
* This provides a wrapper to the Object class to allow it to be |
|
44 |
displayed/manipulated as a GUI object. |
|
45 |
*/ |
|
46 |
@SuppressWarnings("serial") |
|
47 |
public class XObject extends JLabel { |
|
48 |
private Object object; |
|
49 |
private static boolean useHashCodeRepresentation = true; |
|
50 |
public final static XObject NULL_OBJECT = new XObject("null"); |
|
51 |
public XObject (Object object, Icon icon) { |
|
52 |
this(object); |
|
53 |
setIcon(icon); |
|
54 |
} |
|
55 |
||
56 |
public XObject (Object object) { |
|
57 |
setObject(object); |
|
58 |
setHorizontalAlignment(SwingConstants.LEFT); |
|
59 |
} |
|
60 |
||
61 |
public boolean equals(Object o) { |
|
62 |
try { |
|
63 |
if (o instanceof XObject) { |
|
64 |
return object.equals(((XObject)o).getObject()); |
|
65 |
} |
|
66 |
} |
|
67 |
catch (Throwable t) { |
|
68 |
System.out.println("Error comparing XObjects"+ |
|
69 |
t.getMessage()); |
|
70 |
} |
|
71 |
return false; |
|
72 |
} |
|
73 |
||
74 |
||
75 |
public Object getObject() { |
|
76 |
return object; |
|
77 |
} |
|
78 |
||
79 |
//if true the the object.hashcode is added to the label |
|
80 |
public static void |
|
81 |
useHashCodeRepresentation(boolean useHashCodeRepresentation) { |
|
82 |
XObject.useHashCodeRepresentation = useHashCodeRepresentation; |
|
83 |
} |
|
84 |
||
85 |
public static boolean hashCodeRepresentation() { |
|
86 |
return useHashCodeRepresentation; |
|
87 |
} |
|
88 |
||
89 |
public void setObject(Object object) { |
|
90 |
this.object = object; |
|
91 |
// if the object is not a swing component, |
|
92 |
// use default icon |
|
93 |
try { |
|
94 |
String text = null; |
|
95 |
if (object instanceof JLabel) { |
|
96 |
setIcon(((JLabel)object).getIcon()); |
|
97 |
if (getText() != null) { |
|
98 |
text = ((JLabel)object).getText(); |
|
99 |
||
100 |
} |
|
101 |
} |
|
102 |
else if (object instanceof JButton) { |
|
103 |
setIcon(((JButton)object).getIcon()); |
|
104 |
if (getText() != null) { |
|
105 |
text = ((JButton)object).getText(); |
|
106 |
} |
|
107 |
} |
|
108 |
else if (getText() != null) { |
|
109 |
text = object.toString(); |
|
110 |
setIcon(IconManager.DEFAULT_XOBJECT); |
|
111 |
} |
|
112 |
if (text != null) { |
|
113 |
if (useHashCodeRepresentation && (this != NULL_OBJECT)) { |
|
114 |
text = text + " ("+object.hashCode()+")"; |
|
115 |
} |
|
116 |
setText(text); |
|
117 |
} |
|
118 |
} |
|
119 |
catch (Exception e) { |
|
120 |
System.out.println("Error setting XObject object :"+ |
|
121 |
e.getMessage()); |
|
122 |
} |
|
123 |
} |
|
124 |
} |