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