jdk/src/share/classes/sun/tools/jconsole/OverviewTab.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.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class OverviewTab extends Tab {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    JPanel gridPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    TimeComboBox timeComboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static String getTabName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        return getText("Overview");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public OverviewTab(VMPanel vmPanel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        super(vmPanel, getTabName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        setBorder(new EmptyBorder(4, 4, 3, 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        JPanel topPanel     = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        add(topPanel, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        topPanel.add(controlPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        timeComboBox = new TimeComboBox();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        LabeledComponent lc = new LabeledComponent(Resources.getText("Time Range:"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                                                   getMnemonicInt("Time Range:"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                                   timeComboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        controlPanel.add(lc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        gridPanel = new JPanel(new AutoGridLayout(10, 6));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        gridPanel.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        JScrollPane sp = new JScrollPane(gridPanel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        sp.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        sp.setViewportBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        add(sp, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        // Note that panels are added on first update
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
    public SwingWorker<?, ?> newSwingWorker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return new SwingWorker<Object, Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            public Object doInBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            protected void done() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                if (gridPanel.getComponentCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    final ArrayList<Plotter> plotters = new ArrayList<Plotter>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    for (Tab tab : vmPanel.getTabs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        OverviewPanel[] ops = tab.getOverviewPanels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        if (ops != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                            for (OverviewPanel op : ops) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                gridPanel.add(op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                Plotter plotter = op.getPlotter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                if (plotter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                    plotters.add(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                    timeComboBox.addPlotter(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    if (plotters.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        workerAdd(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                ProxyClient proxyClient = vmPanel.getProxyClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                for (Plotter plotter : plotters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                    proxyClient.addWeakPropertyChangeListener(plotter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    if (getParent() instanceof JTabbedPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                        Utilities.updateTransparency((JTabbedPane)getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private class AutoGridLayout extends GridLayout {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        public AutoGridLayout(int hGap, int vGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            super(0, 1, hGap, vGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public Dimension preferredLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return minimumLayoutSize(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        public Dimension minimumLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            updateColumns(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return super.minimumLayoutSize(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        private void updateColumns(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            // Use the outer panel width, not the scrolling gridPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            int parentWidth = OverviewTab.this.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            int columnWidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            for (Component c : parent.getComponents()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                columnWidth = Math.max(columnWidth, c.getPreferredSize().width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            int n = parent.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            int maxCols = Math.min(n, parentWidth / columnWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            for (int columns = maxCols; columns >= 1; columns--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                if (columns == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    setColumns(maxCols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                } else if ((n % columns) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    setColumns(columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}