Path: blob/master/src/jdk.jconsole/share/classes/sun/tools/jconsole/OverviewTab.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.*;28import java.util.ArrayList;2930import javax.swing.*;31import javax.swing.border.*;323334@SuppressWarnings("serial")35class OverviewTab extends Tab {36JPanel gridPanel;37TimeComboBox timeComboBox;3839public static String getTabName() {40return Messages.OVERVIEW;41}4243public OverviewTab(VMPanel vmPanel) {44super(vmPanel, getTabName());4546setBorder(new EmptyBorder(4, 4, 3, 4));47setLayout(new BorderLayout());4849JPanel topPanel = new JPanel(new BorderLayout());50add(topPanel, BorderLayout.NORTH);5152JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 5));53topPanel.add(controlPanel, BorderLayout.CENTER);5455timeComboBox = new TimeComboBox();56LabeledComponent lc = new LabeledComponent(Messages.TIME_RANGE_COLON,57Resources.getMnemonicInt(Messages.TIME_RANGE_COLON),58timeComboBox);59controlPanel.add(lc);6061gridPanel = new JPanel(new AutoGridLayout(10, 6));62gridPanel.setBorder(null);63JScrollPane sp = new JScrollPane(gridPanel);64sp.setBorder(null);65sp.setViewportBorder(null);66add(sp, BorderLayout.CENTER);6768// Note that panels are added on first update69}707172public SwingWorker<?, ?> newSwingWorker() {73return new SwingWorker<Object, Object>() {74public Object doInBackground() {75return null;76}7778protected void done() {79if (gridPanel.getComponentCount() == 0) {80final ArrayList<Plotter> plotters = new ArrayList<Plotter>();81for (Tab tab : vmPanel.getTabs()) {82OverviewPanel[] ops = tab.getOverviewPanels();83if (ops != null) {84for (OverviewPanel op : ops) {85gridPanel.add(op);86Plotter plotter = op.getPlotter();87if (plotter != null) {88plotters.add(plotter);89timeComboBox.addPlotter(plotter);90}91}92}93}94if (plotters.size() > 0) {95workerAdd(new Runnable() {96public void run() {97ProxyClient proxyClient = vmPanel.getProxyClient();98for (Plotter plotter : plotters) {99proxyClient.addWeakPropertyChangeListener(plotter);100}101}102});103}104if (getParent() instanceof JTabbedPane) {105Utilities.updateTransparency((JTabbedPane)getParent());106}107}108}109};110}111112113114private class AutoGridLayout extends GridLayout {115public AutoGridLayout(int hGap, int vGap) {116super(0, 1, hGap, vGap);117}118119public Dimension preferredLayoutSize(Container parent) {120return minimumLayoutSize(parent);121}122123public Dimension minimumLayoutSize(Container parent) {124updateColumns(parent);125return super.minimumLayoutSize(parent);126}127128private void updateColumns(Container parent) {129// Use the outer panel width, not the scrolling gridPanel130int parentWidth = OverviewTab.this.getWidth();131132int columnWidth = 1;133134for (Component c : parent.getComponents()) {135columnWidth = Math.max(columnWidth, c.getPreferredSize().width);136}137138int n = parent.getComponentCount();139int maxCols = Math.min(n, parentWidth / columnWidth);140141for (int columns = maxCols; columns >= 1; columns--) {142if (columns == 1) {143setColumns(maxCols);144} else if ((n % columns) == 0) {145setColumns(columns);146break;147}148}149}150}151}152153154