jdk/src/share/classes/sun/tools/jconsole/OverviewPanel.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 12851 3334e1c781d0
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import static javax.swing.SwingConstants.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import static sun.tools.jconsole.JConsole.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import static sun.tools.jconsole.Resources.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
abstract class OverviewPanel extends PlotterPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final Dimension PREFERRED_PLOTTER_SIZE = new Dimension(300, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static final Dimension MINIMUM_PLOTTER_SIZE = new Dimension(200, 150);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    // This is the default view range for all the overview plotters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static final int VIEW_RANGE = -1;   // Show all data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static Color PLOTTER_COLOR = IS_GTK ? new Color(231, 111, 80) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private JLabel infoLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public OverviewPanel(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        this(title, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public OverviewPanel(String title, String plotterKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                         String plotterName, Plotter.Unit plotterUnit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        setLayout(new BorderLayout(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (plotterKey != null && plotterName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            Plotter plotter = new Plotter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            plotter.setPreferredSize(PREFERRED_PLOTTER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            plotter.setMinimumSize(MINIMUM_PLOTTER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            plotter.setViewRange(VIEW_RANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            if (plotterUnit != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                plotter.setUnit(plotterUnit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            plotter.createSequence(plotterKey, plotterName, PLOTTER_COLOR, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            setAccessibleName(plotter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                              getText("OverviewPanel.plotter.accessibleName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                      title));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            setPlotter(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public JLabel getInfoLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (infoLabel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            infoLabel = new JLabel("", CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                public void setText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    if (text.startsWith("<html>")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                        // Replace spaces with nbsp, except the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                        // last one of two or more (to allow wrapping)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                        StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        char[] chars = text.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        int n = chars.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                            if (chars[i] == ' '
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                && ((i < n-1 && chars[i+1] == ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                    || ((i == 0 || chars[i-1] != ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                        && (i == n-1 || chars[i+1] != ' ')))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                buf.append("&nbsp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                buf.append(chars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                        text = buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    super.setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (IS_GTK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                JPanel southPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                southPanel.add(separator, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                southPanel.add(infoLabel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                add(southPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                add(infoLabel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return infoLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}