001: /*
002: * Copyright 2006 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:
026: package sun.tools.jconsole;
027:
028: import java.awt.*;
029: import java.awt.event.*;
030:
031: import javax.swing.*;
032: import javax.swing.border.*;
033:
034: import static javax.swing.SwingConstants.*;
035: import static sun.tools.jconsole.JConsole.*;
036: import static sun.tools.jconsole.Resources.*;
037: import static sun.tools.jconsole.Utilities.*;
038:
039: @SuppressWarnings("serial")
040: abstract class OverviewPanel extends PlotterPanel {
041: private static final Dimension PREFERRED_PLOTTER_SIZE = new Dimension(
042: 300, 200);
043: private static final Dimension MINIMUM_PLOTTER_SIZE = new Dimension(
044: 200, 150);
045:
046: // This is the default view range for all the overview plotters
047: static final int VIEW_RANGE = -1; // Show all data
048:
049: static Color PLOTTER_COLOR = IS_GTK ? new Color(231, 111, 80)
050: : null;
051:
052: private JLabel infoLabel;
053:
054: public OverviewPanel(String title) {
055: this (title, null, null, null);
056: }
057:
058: public OverviewPanel(String title, String plotterKey,
059: String plotterName, Plotter.Unit plotterUnit) {
060: super (title);
061: setLayout(new BorderLayout(0, 0));
062:
063: if (plotterKey != null && plotterName != null) {
064: Plotter plotter = new Plotter();
065: plotter.setPreferredSize(PREFERRED_PLOTTER_SIZE);
066: plotter.setMinimumSize(MINIMUM_PLOTTER_SIZE);
067: plotter.setViewRange(VIEW_RANGE);
068: if (plotterUnit != null) {
069: plotter.setUnit(plotterUnit);
070: }
071: plotter.createSequence(plotterKey, plotterName,
072: PLOTTER_COLOR, true);
073: setAccessibleName(plotter, getText(
074: "OverviewPanel.plotter.accessibleName", title));
075: setPlotter(plotter);
076: }
077: }
078:
079: public JLabel getInfoLabel() {
080: if (infoLabel == null) {
081: infoLabel = new JLabel("", CENTER) {
082: @Override
083: public void setText(String text) {
084: if (text.startsWith("<html>")) {
085: // Replace spaces with nbsp, except the
086: // last one of two or more (to allow wrapping)
087: StringBuilder buf = new StringBuilder();
088: char[] chars = text.toCharArray();
089: int n = chars.length;
090: for (int i = 0; i < n; i++) {
091: if (chars[i] == ' '
092: && ((i < n - 1 && chars[i + 1] == ' ') || ((i == 0 || chars[i - 1] != ' ') && (i == n - 1 || chars[i + 1] != ' ')))) {
093: buf.append(" ");
094: } else {
095: buf.append(chars[i]);
096: }
097: }
098: text = buf.toString();
099: }
100: super .setText(text);
101: }
102: };
103:
104: if (IS_GTK) {
105: JPanel southPanel = new JPanel(new BorderLayout());
106: JSeparator separator = new JSeparator(
107: JSeparator.HORIZONTAL);
108: southPanel.add(separator, BorderLayout.NORTH);
109: southPanel.add(infoLabel, BorderLayout.SOUTH);
110: add(southPanel, BorderLayout.SOUTH);
111: } else {
112: add(infoLabel, BorderLayout.SOUTH);
113: }
114: }
115: return infoLabel;
116: }
117: }
|