author | martin |
Thu, 30 Oct 2014 07:31:41 -0700 | |
changeset 28059 | e576535359cc |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18292
diff
changeset
|
2 |
* Copyright (c) 2004, 2013, 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 |
// java import |
|
29 |
import javax.swing.*; |
|
18292 | 30 |
import java.util.Objects; |
2 | 31 |
|
32 |
/** |
|
33 |
* This provides a wrapper to the Object class to allow it to be |
|
34 |
displayed/manipulated as a GUI object. |
|
35 |
*/ |
|
36 |
@SuppressWarnings("serial") |
|
37 |
public class XObject extends JLabel { |
|
38 |
private Object object; |
|
39 |
private static boolean useHashCodeRepresentation = true; |
|
40 |
public final static XObject NULL_OBJECT = new XObject("null"); |
|
41 |
public XObject (Object object, Icon icon) { |
|
42 |
this(object); |
|
43 |
setIcon(icon); |
|
44 |
} |
|
45 |
||
46 |
public XObject (Object object) { |
|
47 |
setObject(object); |
|
48 |
setHorizontalAlignment(SwingConstants.LEFT); |
|
49 |
} |
|
50 |
||
51 |
public boolean equals(Object o) { |
|
18292 | 52 |
if (o instanceof XObject) { |
53 |
return Objects.equals(object, ((XObject)o).getObject()); |
|
2 | 54 |
} |
55 |
return false; |
|
56 |
} |
|
57 |
||
18292 | 58 |
@Override |
59 |
public int hashCode() { |
|
60 |
return object.hashCode(); |
|
61 |
} |
|
62 |
||
2 | 63 |
|
64 |
public Object getObject() { |
|
65 |
return object; |
|
66 |
} |
|
67 |
||
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
25859
diff
changeset
|
68 |
//if true the object.hashcode is added to the label |
2 | 69 |
public static void |
70 |
useHashCodeRepresentation(boolean useHashCodeRepresentation) { |
|
71 |
XObject.useHashCodeRepresentation = useHashCodeRepresentation; |
|
72 |
} |
|
73 |
||
74 |
public static boolean hashCodeRepresentation() { |
|
75 |
return useHashCodeRepresentation; |
|
76 |
} |
|
77 |
||
78 |
public void setObject(Object object) { |
|
79 |
this.object = object; |
|
80 |
// if the object is not a swing component, |
|
81 |
// use default icon |
|
82 |
try { |
|
83 |
String text = null; |
|
84 |
if (object instanceof JLabel) { |
|
85 |
setIcon(((JLabel)object).getIcon()); |
|
86 |
if (getText() != null) { |
|
87 |
text = ((JLabel)object).getText(); |
|
88 |
||
89 |
} |
|
90 |
} |
|
91 |
else if (object instanceof JButton) { |
|
92 |
setIcon(((JButton)object).getIcon()); |
|
93 |
if (getText() != null) { |
|
94 |
text = ((JButton)object).getText(); |
|
95 |
} |
|
96 |
} |
|
97 |
else if (getText() != null) { |
|
98 |
text = object.toString(); |
|
99 |
setIcon(IconManager.DEFAULT_XOBJECT); |
|
100 |
} |
|
101 |
if (text != null) { |
|
102 |
if (useHashCodeRepresentation && (this != NULL_OBJECT)) { |
|
103 |
text = text + " ("+object.hashCode()+")"; |
|
104 |
} |
|
105 |
setText(text); |
|
106 |
} |
|
107 |
} |
|
108 |
catch (Exception e) { |
|
109 |
System.out.println("Error setting XObject object :"+ |
|
110 |
e.getMessage()); |
|
111 |
} |
|
112 |
} |
|
113 |
} |