001: /*
002: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.tools.jconsole.inspector;
026:
027: import javax.swing.JTable;
028: import javax.swing.JScrollPane;
029: import javax.swing.JButton;
030:
031: import java.awt.event.MouseListener;
032: import java.awt.Component;
033: import java.awt.Container;
034:
035: import sun.tools.jconsole.MBeansTab;
036: import sun.tools.jconsole.Resources;
037:
038: public class XDataViewer {
039:
040: public static final int OPEN = 1;
041: public static final int ARRAY = 2;
042: public static final int NUMERIC = 3;
043: public static final int NOT_SUPPORTED = 4;
044:
045: private MBeansTab tab;
046:
047: public XDataViewer(MBeansTab tab) {
048: this .tab = tab;
049: }
050:
051: public static void registerForMouseEvent(Component comp,
052: MouseListener mouseListener) {
053: if (comp instanceof JScrollPane) {
054: JScrollPane pane = (JScrollPane) comp;
055: comp = pane.getViewport().getView();
056: }
057: if (comp instanceof Container) {
058: Container container = (Container) comp;
059: Component[] components = container.getComponents();
060: for (int i = 0; i < components.length; i++) {
061: registerForMouseEvent(components[i], mouseListener);
062: }
063: }
064:
065: //No registration for XOpenTypedata that are themselves clickable.
066: //No registration for JButton that are themselves clickable.
067: if (comp != null
068: && (!(comp instanceof XOpenTypeViewer.XOpenTypeData) && !(comp instanceof JButton)))
069: comp.addMouseListener(mouseListener);
070: }
071:
072: public static void dispose(MBeansTab tab) {
073: XPlottingViewer.dispose(tab);
074: }
075:
076: public static boolean isViewableValue(Object value) {
077: boolean ret = false;
078: if ((ret = XArrayDataViewer.isViewableValue(value)))
079: return ret;
080: if ((ret = XOpenTypeViewer.isViewableValue(value)))
081: return ret;
082: if ((ret = XPlottingViewer.isViewableValue(value)))
083: return ret;
084:
085: return ret;
086: }
087:
088: public static int getViewerType(Object data) {
089: if (XArrayDataViewer.isViewableValue(data))
090: return ARRAY;
091: if (XOpenTypeViewer.isViewableValue(data))
092: return OPEN;
093: if (XPlottingViewer.isViewableValue(data))
094: return NUMERIC;
095:
096: return NOT_SUPPORTED;
097: }
098:
099: public static String getActionLabel(int type) {
100: if (type == ARRAY || type == OPEN)
101: return Resources.getText("visualize");
102: if (type == NUMERIC)
103: return Resources.getText("plot");
104: return Resources.getText("expand");
105: }
106:
107: public Component createOperationViewer(Object value, XMBean mbean) {
108: if (value instanceof Number)
109: return null;
110: return createAttributeViewer(value, mbean, null, null);
111: }
112:
113: public static Component createNotificationViewer(Object value) {
114: Component comp = null;
115:
116: if (value instanceof Number)
117: return null;
118:
119: if ((comp = XArrayDataViewer.loadArray(value)) != null)
120: return comp;
121:
122: if ((comp = XOpenTypeViewer.loadOpenType(value)) != null)
123: return comp;
124:
125: return comp;
126: }
127:
128: public Component createAttributeViewer(Object value, XMBean mbean,
129: String attributeName, JTable table) {
130: Component comp = null;
131: if ((comp = XArrayDataViewer.loadArray(value)) != null)
132: return comp;
133: if ((comp = XOpenTypeViewer.loadOpenType(value)) != null)
134: return comp;
135: if ((comp = XPlottingViewer.loadPlotting(mbean, attributeName,
136: value, table, tab)) != null)
137: return comp;
138:
139: return comp;
140: }
141: }
|