History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/tools/jconsole/inspector/XObject.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/tools/jconsole/inspector/XObject.java+124−0
@@ -0,0 +1,124 @@
1/*
2 * Copyright (c) 2004, 2008, 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
26package sun.tools.jconsole.inspector;
27
28// java import
29import javax.swing.*;
30
31//
32
33// java import
34import java.io.*;
35import java.awt.*;
36import java.awt.dnd.*;
37import java.awt.datatransfer.*;
38import 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")
47public 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}