Path: blob/master/src/jdk.jconsole/share/classes/sun/tools/jconsole/OverviewPanel.java
40948 views
/*1* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jconsole;2627import java.awt.*;2829import javax.swing.*;303132import static javax.swing.SwingConstants.*;33import static sun.tools.jconsole.JConsole.*;34import static sun.tools.jconsole.Utilities.*;353637@SuppressWarnings("serial")38abstract class OverviewPanel extends PlotterPanel {39private static final Dimension PREFERRED_PLOTTER_SIZE = new Dimension(300, 200);40private static final Dimension MINIMUM_PLOTTER_SIZE = new Dimension(200, 150);4142// This is the default view range for all the overview plotters43static final int VIEW_RANGE = -1; // Show all data4445static Color PLOTTER_COLOR = IS_GTK ? new Color(231, 111, 80) : null;4647private JLabel infoLabel;4849public OverviewPanel(String title) {50this(title, null, null, null);51}5253public OverviewPanel(String title, String plotterKey,54String plotterName, Plotter.Unit plotterUnit) {55super(title);56setLayout(new BorderLayout(0, 0));5758if (plotterKey != null && plotterName != null) {59Plotter plotter = new Plotter();60plotter.setPreferredSize(PREFERRED_PLOTTER_SIZE);61plotter.setMinimumSize(MINIMUM_PLOTTER_SIZE);62plotter.setViewRange(VIEW_RANGE);63if (plotterUnit != null) {64plotter.setUnit(plotterUnit);65}66plotter.createSequence(plotterKey, plotterName, PLOTTER_COLOR, true);67setAccessibleName(plotter,68Resources.format(Messages.OVERVIEW_PANEL_PLOTTER_ACCESSIBLE_NAME,69title));70setPlotter(plotter);71}72}737475public JLabel getInfoLabel() {76if (infoLabel == null) {77infoLabel = new JLabel("", CENTER) {78@Override79public void setText(String text) {80if (text.startsWith("<html>")) {81// Replace spaces with nbsp, except the82// last one of two or more (to allow wrapping)83StringBuilder buf = new StringBuilder();84char[] chars = text.toCharArray();85int n = chars.length;86for (int i = 0; i < n; i++) {87if (chars[i] == ' '88&& ((i < n-1 && chars[i+1] == ' ')89|| ((i == 0 || chars[i-1] != ' ')90&& (i == n-1 || chars[i+1] != ' ')))) {91buf.append(" ");92} else {93buf.append(chars[i]);94}95}96text = buf.toString();97}98super.setText(text);99}100};101102if (IS_GTK) {103JPanel southPanel = new JPanel(new BorderLayout());104JSeparator separator = new JSeparator(JSeparator.HORIZONTAL);105southPanel.add(separator, BorderLayout.NORTH);106southPanel.add(infoLabel, BorderLayout.SOUTH);107add(southPanel, BorderLayout.SOUTH);108} else {109add(infoLabel, BorderLayout.SOUTH);110}111}112return infoLabel;113}114}115116117