jdk/src/jdk.jconsole/share/classes/sun/tools/jconsole/OverviewPanel.java
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 25859 3317bb8137f4
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments Reviewed-by: attila, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12851
diff changeset
     2
 * Copyright (c) 2006, 2012, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import static javax.swing.SwingConstants.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import static sun.tools.jconsole.JConsole.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
abstract class OverviewPanel extends PlotterPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final Dimension PREFERRED_PLOTTER_SIZE = new Dimension(300, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final Dimension MINIMUM_PLOTTER_SIZE = new Dimension(200, 150);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    // This is the default view range for all the overview plotters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final int VIEW_RANGE = -1;   // Show all data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static Color PLOTTER_COLOR = IS_GTK ? new Color(231, 111, 80) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private JLabel infoLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public OverviewPanel(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this(title, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public OverviewPanel(String title, String plotterKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                         String plotterName, Plotter.Unit plotterUnit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        super(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        setLayout(new BorderLayout(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (plotterKey != null && plotterName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            Plotter plotter = new Plotter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            plotter.setPreferredSize(PREFERRED_PLOTTER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            plotter.setMinimumSize(MINIMUM_PLOTTER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            plotter.setViewRange(VIEW_RANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            if (plotterUnit != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                plotter.setUnit(plotterUnit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            plotter.createSequence(plotterKey, plotterName, PLOTTER_COLOR, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            setAccessibleName(plotter,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    69
                              Resources.format(Messages.OVERVIEW_PANEL_PLOTTER_ACCESSIBLE_NAME,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                      title));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            setPlotter(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public JLabel getInfoLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (infoLabel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            infoLabel = new JLabel("", CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                public void setText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    if (text.startsWith("<html>")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                        // Replace spaces with nbsp, except the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                        // last one of two or more (to allow wrapping)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                        StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                        char[] chars = text.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                        int n = chars.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                            if (chars[i] == ' '
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                && ((i < n-1 && chars[i+1] == ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                    || ((i == 0 || chars[i-1] != ' ')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                        && (i == n-1 || chars[i+1] != ' ')))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                buf.append("&nbsp;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                buf.append(chars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        text = buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    super.setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (IS_GTK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                JPanel southPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                southPanel.add(separator, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                southPanel.add(infoLabel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                add(southPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                add(infoLabel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return infoLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}