src/jdk.jconsole/share/classes/sun/tools/jconsole/ConnectDialog.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/jdk.jconsole/share/classes/sun/tools/jconsole/ConnectDialog.java@3317bb8137f4
child 52902 e3398b2e1ab0
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19568
873477c7e278 6800801: NPE in JConsole when using Nimbus L&F
egahlin
parents: 14342
diff changeset
     2
 * Copyright (c) 2004, 2013, 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.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.basic.BasicRadioButtonUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    39
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import static java.awt.BorderLayout.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import static javax.swing.ListSelectionModel.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class ConnectDialog extends InternalDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                implements DocumentListener, FocusListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                           ItemListener, ListSelectionListener, KeyListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final int COL_NAME = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final int COL_PID  = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    JConsole jConsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    JTextField userNameTF, passwordTF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    JRadioButton localRadioButton, remoteRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    JLabel localMessageLabel, remoteMessageLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    JTextField remoteTF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    JButton connectButton, cancelButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    JPanel radioButtonPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Icon mastheadIcon =
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    63
        new MastheadIcon(Messages.CONNECT_DIALOG_MASTHEAD_TITLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private Color hintTextColor, disabledTableCellColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // The table of managed VM (local process)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    JTable vmTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    ManagedVmTableModel vmModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    JScrollPane localTableScrollPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private Action connectAction, cancelAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public ConnectDialog(JConsole jConsole) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    76
        super(jConsole, Messages.CONNECT_DIALOG_TITLE, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        this.jConsole = jConsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        setAccessibleDescription(this,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    80
                                 Messages.CONNECT_DIALOG_ACCESSIBLE_DESCRIPTION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        setDefaultCloseOperation(HIDE_ON_CLOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        Container cp = (JComponent)getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        radioButtonPanel = new JPanel(new BorderLayout(0, 12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        radioButtonPanel.setBorder(new EmptyBorder(6, 12, 12, 12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        ButtonGroup radioButtonGroup = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        JPanel bottomPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        statusBar = new JLabel(" ", JLabel.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        setAccessibleName(statusBar,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    92
                          Messages.CONNECT_DIALOG_STATUS_BAR_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        Font normalLabelFont = statusBar.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        Font boldLabelFont = normalLabelFont.deriveFont(Font.BOLD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        Font smallLabelFont = normalLabelFont.deriveFont(normalLabelFont.getSize2D() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        JLabel mastheadLabel = new JLabel(mastheadIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        setAccessibleName(mastheadLabel,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   100
                          Messages.CONNECT_DIALOG_MASTHEAD_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        cp.add(mastheadLabel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        cp.add(radioButtonPanel, CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        cp.add(bottomPanel, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        createActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        remoteTF = new JTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        remoteTF.addActionListener(connectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        remoteTF.getDocument().addDocumentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        remoteTF.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        remoteTF.setPreferredSize(remoteTF.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        setAccessibleName(remoteTF,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   114
                          Messages.REMOTE_PROCESS_TEXT_FIELD_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // If the VM supports the local attach mechanism (is: Sun
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // implementation) then the Local Process panel is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (JConsole.isLocalAttachAvailable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            vmModel = new ManagedVmTableModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            vmTable = new LocalTabJTable(vmModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            vmTable.setSelectionMode(SINGLE_SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            vmTable.setPreferredScrollableViewportSize(new Dimension(400, 250));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            vmTable.setColumnSelectionAllowed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            vmTable.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            vmTable.getSelectionModel().addListSelectionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            TableColumnModel columnModel = vmTable.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            TableColumn pidColumn = columnModel.getColumn(COL_PID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            pidColumn.setMaxWidth(getLabelWidth("9999999"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            pidColumn.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            TableColumn cmdLineColumn = columnModel.getColumn(COL_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            cmdLineColumn.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   138
            localRadioButton = new JRadioButton(Messages.LOCAL_PROCESS_COLON);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   139
            localRadioButton.setMnemonic(Resources.getMnemonicInt(Messages.LOCAL_PROCESS_COLON));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            localRadioButton.setFont(boldLabelFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            localRadioButton.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            radioButtonGroup.add(localRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            JPanel localPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            JPanel localTablePanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            radioButtonPanel.add(localPanel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            localPanel.add(localRadioButton, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            localPanel.add(new Padder(localRadioButton), LINE_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            localPanel.add(localTablePanel, CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            localTableScrollPane = new JScrollPane(vmTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            localTablePanel.add(localTableScrollPane, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            localMessageLabel = new JLabel(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            localMessageLabel.setFont(smallLabelFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            localMessageLabel.setForeground(hintTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            localTablePanel.add(localMessageLabel, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   164
        remoteRadioButton = new JRadioButton(Messages.REMOTE_PROCESS_COLON);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   165
        remoteRadioButton.setMnemonic(Resources.getMnemonicInt(Messages.REMOTE_PROCESS_COLON));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        remoteRadioButton.setFont(boldLabelFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        radioButtonGroup.add(remoteRadioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        JPanel remotePanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (localRadioButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            remotePanel.add(remoteRadioButton, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            remotePanel.add(new Padder(remoteRadioButton), LINE_START);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            Action nextRadioButtonAction =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                new AbstractAction("nextRadioButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        JRadioButton rb =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                            (ev.getSource() == localRadioButton) ? remoteRadioButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                                                 : localRadioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        rb.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                        rb.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            localRadioButton.getActionMap().put("nextRadioButton", nextRadioButtonAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            remoteRadioButton.getActionMap().put("nextRadioButton", nextRadioButtonAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            localRadioButton.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                               "nextRadioButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            remoteRadioButton.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                                "nextRadioButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            JLabel remoteLabel = new JLabel(remoteRadioButton.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            remoteLabel.setFont(boldLabelFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            remotePanel.add(remoteLabel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        radioButtonPanel.add(remotePanel, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        JPanel remoteTFPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        remotePanel.add(remoteTFPanel, CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        remoteTFPanel.add(remoteTF, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   204
        remoteMessageLabel = new JLabel("<html>" + Messages.REMOTE_TF_USAGE + "</html>");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        remoteMessageLabel.setFont(smallLabelFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        remoteMessageLabel.setForeground(hintTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        remoteTFPanel.add(remoteMessageLabel, CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        JPanel userPwdPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        userPwdPanel.setBorder(new EmptyBorder(12, 0, 0, 0)); // top padding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        int tfWidth = JConsole.IS_WIN ? 12 : 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        userNameTF = new JTextField(tfWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        userNameTF.addActionListener(connectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        userNameTF.getDocument().addDocumentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        userNameTF.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        setAccessibleName(userNameTF,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   219
            Messages.USERNAME_ACCESSIBLE_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        LabeledComponent lc;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   221
        lc = new LabeledComponent(Messages.USERNAME_COLON_,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   222
                                  Resources.getMnemonicInt(Messages.USERNAME_COLON_),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                  userNameTF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        lc.label.setFont(boldLabelFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        userPwdPanel.add(lc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        passwordTF = new JPasswordField(tfWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // Heights differ, so fix here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        passwordTF.setPreferredSize(userNameTF.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        passwordTF.addActionListener(connectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        passwordTF.getDocument().addDocumentListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        passwordTF.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        setAccessibleName(passwordTF,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   234
            Messages.PASSWORD_ACCESSIBLE_NAME);
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   235
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   236
        lc = new LabeledComponent(Messages.PASSWORD_COLON_,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   237
                                  Resources.getMnemonicInt(Messages.PASSWORD_COLON_),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                  passwordTF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        lc.setBorder(new EmptyBorder(0, 12, 0, 0)); // Left padding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        lc.label.setFont(boldLabelFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        userPwdPanel.add(lc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        remoteTFPanel.add(userPwdPanel, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        String connectButtonToolTipText =
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   246
            Messages.CONNECT_DIALOG_CONNECT_BUTTON_TOOLTIP;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        connectButton = new JButton(connectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        connectButton.setToolTipText(connectButtonToolTipText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        cancelButton = new JButton(cancelAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        buttonPanel.setBorder(new EmptyBorder(12, 12, 2, 12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (JConsole.IS_GTK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            buttonPanel.add(cancelButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            buttonPanel.add(connectButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            buttonPanel.add(connectButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            buttonPanel.add(cancelButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        bottomPanel.add(buttonPanel, NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        bottomPanel.add(statusBar, SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        Utilities.updateTransparency(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // Adjust some colors
19568
873477c7e278 6800801: NPE in JConsole when using Nimbus L&F
egahlin
parents: 14342
diff changeset
   271
        Color disabledForeground = UIManager.getColor("Label.disabledForeground");
873477c7e278 6800801: NPE in JConsole when using Nimbus L&F
egahlin
parents: 14342
diff changeset
   272
        if (disabledForeground == null) {
873477c7e278 6800801: NPE in JConsole when using Nimbus L&F
egahlin
parents: 14342
diff changeset
   273
            // fall back for Nimbus that doesn't support 'Label.disabledForeground'
873477c7e278 6800801: NPE in JConsole when using Nimbus L&F
egahlin
parents: 14342
diff changeset
   274
            disabledForeground = UIManager.getColor("Label.disabledText");
873477c7e278 6800801: NPE in JConsole when using Nimbus L&F
egahlin
parents: 14342
diff changeset
   275
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        hintTextColor =
19568
873477c7e278 6800801: NPE in JConsole when using Nimbus L&F
egahlin
parents: 14342
diff changeset
   277
            ensureContrast(disabledForeground,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                           UIManager.getColor("Panel.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        disabledTableCellColor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            ensureContrast(new Color(0x808080),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                           UIManager.getColor("Table.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (remoteMessageLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            remoteMessageLabel.setForeground(hintTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            // Update html color setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            String colorStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                String.format("%06x", hintTextColor.getRGB() & 0xFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            remoteMessageLabel.setText("<html><font color=#" + colorStr + ">" +
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   289
                                       Messages.REMOTE_TF_USAGE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (localMessageLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            localMessageLabel.setForeground(hintTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            // Update html color setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            valueChanged(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        super.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    private void createActions() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   301
        connectAction = new AbstractAction(Messages.CONNECT) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            /* init */ {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   303
                putValue(Action.MNEMONIC_KEY, Resources.getMnemonicInt(Messages.CONNECT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                if (!isEnabled() || !isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                statusBar.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if (remoteRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    String txt = remoteTF.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    String userName = userNameTF.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    userName = userName.equals("") ? null : userName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    String password = passwordTF.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    password = password.equals("") ? null : password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        if (txt.startsWith(JConsole.ROOT_URL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                            String url = txt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                            jConsole.addUrl(url, userName, password, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                            remoteTF.setText(JConsole.ROOT_URL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                            String host = remoteTF.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                            String port = "0";
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 19568
diff changeset
   328
                            int index = host.lastIndexOf(':');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                port = host.substring(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                host = host.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                            if (host.length() > 0 && port.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                int p = Integer.parseInt(port.trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                jConsole.addHost(host, p, userName, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                remoteTF.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                userNameTF.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                passwordTF.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        statusBar.setText(ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                } else if (localRadioButton != null && localRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    // Try to connect to selected VM. If a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    // cannot be established for some reason (the process has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    // terminated for example) then keep the dialog open showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    // the connect error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                        jConsole.addVmid(vmModel.vmAt(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    refresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   361
        cancelAction = new AbstractAction(Messages.CANCEL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                statusBar.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    // a label used solely for calculating the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private static JLabel tmpLabel = new JLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public static int getLabelWidth(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        tmpLabel.setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return (int) tmpLabel.getPreferredSize().getWidth() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private class LocalTabJTable extends JTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        ManagedVmTableModel vmModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Border rendererBorder = new EmptyBorder(0, 6, 0, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        public LocalTabJTable(ManagedVmTableModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            super(model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            this.vmModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            // Remove vertical lines, expect for GTK L&F.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            // (because GTK doesn't show header dividers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (!JConsole.IS_GTK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                setShowVerticalLines(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                setIntercellSpacing(new Dimension(0, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            // Double-click handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            addMouseListener(new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                public void mouseClicked(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    if (evt.getClickCount() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                        connectButton.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            // Enter should call default action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            getActionMap().put("connect", connectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "connect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        public String getToolTipText(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            java.awt.Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            int rowIndex = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            int colIndex = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            int realColumnIndex = convertColumnIndexToModel(colIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            if (realColumnIndex == COL_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                LocalVirtualMachine vmd = vmModel.vmAt(rowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                tip = vmd.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        public TableCellRenderer getCellRenderer(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            return new DefaultTableCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                public Component getTableCellRendererComponent(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                                               Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                                               boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                                               boolean hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                                               int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                                               int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    Component comp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        super.getTableCellRendererComponent(table, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                                            hasFocus, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    if (!isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        LocalVirtualMachine lvm = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        if (!lvm.isManageable() && !lvm.isAttachable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                            comp.setForeground(disabledTableCellColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    if (comp instanceof JLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        JLabel label = (JLabel)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        label.setBorder(rendererBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                            label.setHorizontalAlignment(JLabel.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public void setConnectionParameters(String url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                                        String host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                        int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                        String userName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                        String password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                        String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if ((url != null && url.length() > 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            (host != null && host.length() > 0 && port > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            remoteRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if (url != null && url.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                remoteTF.setText(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                remoteTF.setText(host+":"+port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            userNameTF.setText((userName != null) ? userName : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            passwordTF.setText((password != null) ? password : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            statusBar.setText((msg != null) ? msg : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (getPreferredSize().width > getWidth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            remoteTF.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            remoteTF.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public void itemStateChanged(ItemEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (!localRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            vmTable.getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    private void updateButtonStates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        boolean connectEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (remoteRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            connectEnabled = JConsole.isValidRemoteString(remoteTF.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        } else if (localRadioButton != null && localRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                LocalVirtualMachine lvm = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                connectEnabled = (lvm.isManageable() || lvm.isAttachable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        connectAction.setEnabled(connectEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public void insertUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public void removeUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public void changedUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        Component opposite = e.getOppositeComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (!e.isTemporary() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            source instanceof JTextField &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            opposite instanceof JComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            SwingUtilities.getRootPane(opposite) == getRootPane()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            ((JTextField)source).selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (source == remoteTF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            remoteRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        } else if (source == vmTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            localRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            if (vmModel.getRowCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                // if there's only one process then select the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                vmTable.setRowSelectionInterval(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        char c = e.getKeyChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (c == KeyEvent.VK_ESCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        } else if (!(Character.isDigit(c) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                     c == KeyEvent.VK_BACK_SPACE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                     c == KeyEvent.VK_DELETE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            getToolkit().beep();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        boolean wasVisible = isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (b && !wasVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            SwingUtilities.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    if (remoteRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                        remoteTF.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                        remoteTF.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public void keyReleased(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    // ListSelectionListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        String labelText = " "; // Non-empty to reserve vertical space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            LocalVirtualMachine lvm = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            if (!lvm.isManageable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                if (lvm.isAttachable()) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   588
                    labelText = Messages.MANAGEMENT_WILL_BE_ENABLED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                } else {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   590
                    labelText = Messages.MANAGEMENT_NOT_ENABLED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        String colorStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            String.format("%06x", hintTextColor.getRGB() & 0xFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        localMessageLabel.setText("<html><font color=#" + colorStr + ">" + labelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    // ----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    // Refresh the list of managed VMs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (vmModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            // Remember selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            LocalVirtualMachine selected = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                selected = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            vmModel.refresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            int selectRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            int n = vmModel.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            if (selected != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    LocalVirtualMachine lvm = vmModel.vmAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    if (selected.vmid() == lvm.vmid() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                        selected.toString().equals(lvm.toString())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        selectRow = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (selectRow > -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                vmTable.setRowSelectionInterval(selectRow, selectRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                vmTable.getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            Dimension dim = vmTable.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            // Tricky. Reduce height by one to avoid double line at bottom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            // but that causes a scroll bar to appear, so remove it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            dim.height = Math.min(dim.height-1, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            localTableScrollPane.setVerticalScrollBarPolicy((dim.height < 100)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                                ? JScrollPane.VERTICAL_SCROLLBAR_NEVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                                                : JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            localTableScrollPane.getViewport().setMinimumSize(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            localTableScrollPane.getViewport().setPreferredSize(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        setLocationRelativeTo(jConsole);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    // Represents the list of managed VMs as a tabular data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    private static class ManagedVmTableModel extends AbstractTableModel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        private static String[] columnNames = {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   650
            Messages.COLUMN_NAME,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   651
            Messages.COLUMN_PID,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        private List<LocalVirtualMachine> vmList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            return columnNames.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        public String getColumnName(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            return columnNames[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        public synchronized int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            return vmList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        public synchronized Object getValueAt(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            assert col >= 0 && col <= columnNames.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            LocalVirtualMachine vm = vmList.get(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            switch (col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                case COL_NAME: return vm.displayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                case COL_PID:  return vm.vmid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                default: return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   678
        public Class<?> getColumnClass(int column) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            switch (column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                case COL_NAME: return String.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                case COL_PID:  return Integer.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                default: return super.getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        public ManagedVmTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            refresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        public synchronized LocalVirtualMachine vmAt(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return vmList.get(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        public synchronized void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            Map<Integer, LocalVirtualMachine> map =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                LocalVirtualMachine.getAllVirtualMachines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            vmList = new ArrayList<LocalVirtualMachine>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            vmList.addAll(map.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            // data has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            fireTableDataChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    // A blank component that takes up as much space as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    // button part of a JRadioButton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    private static class Padder extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        JRadioButton radioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        Padder(JRadioButton radioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            this.radioButton = radioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   714
            setAccessibleName(this, Messages.BLANK);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            Rectangle r = getTextRectangle(radioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            int w = (r != null && r.x > 8) ? r.x : 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            return new Dimension(w, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        private static Rectangle getTextRectangle(AbstractButton button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            String text = button.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            if (icon == null && button.getUI() instanceof BasicRadioButtonUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                icon = ((BasicRadioButtonUI)button.getUI()).getDefaultIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            if ((icon == null) && (text == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            Rectangle paintIconR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            Rectangle paintTextR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            Rectangle paintViewR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            Insets paintViewInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            paintViewInsets = button.getInsets(paintViewInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            paintViewR.x = paintViewInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            paintViewR.y = paintViewInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            paintViewR.width = button.getWidth() - (paintViewInsets.left + paintViewInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            paintViewR.height = button.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            Graphics g = button.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                SwingUtilities.layoutCompoundLabel(button,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                                                   g.getFontMetrics(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                                                   text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                                                   icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                                                   button.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                                                   button.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                                                   button.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                                                   button.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                                                   paintViewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                                   paintIconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                                                   paintTextR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                                                   button.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            return paintTextR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
}