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