jdk/src/share/classes/sun/tools/jconsole/ConnectDialog.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 12851 3334e1c781d0
child 19568 873477c7e278
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
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) 2004, 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.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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        hintTextColor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            ensureContrast(UIManager.getColor("Label.disabledForeground"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                           UIManager.getColor("Panel.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        disabledTableCellColor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            ensureContrast(new Color(0x808080),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                           UIManager.getColor("Table.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (remoteMessageLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            remoteMessageLabel.setForeground(hintTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            // Update html color setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            String colorStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                String.format("%06x", hintTextColor.getRGB() & 0xFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            remoteMessageLabel.setText("<html><font color=#" + colorStr + ">" +
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   284
                                       Messages.REMOTE_TF_USAGE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (localMessageLabel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            localMessageLabel.setForeground(hintTextColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            // Update html color setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            valueChanged(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        super.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private void createActions() {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   296
        connectAction = new AbstractAction(Messages.CONNECT) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            /* init */ {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   298
                putValue(Action.MNEMONIC_KEY, Resources.getMnemonicInt(Messages.CONNECT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                if (!isEnabled() || !isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                statusBar.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                if (remoteRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    String txt = remoteTF.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    String userName = userNameTF.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    userName = userName.equals("") ? null : userName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    String password = passwordTF.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    password = password.equals("") ? null : password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        if (txt.startsWith(JConsole.ROOT_URL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                            String url = txt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                            jConsole.addUrl(url, userName, password, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                            remoteTF.setText(JConsole.ROOT_URL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                            String host = remoteTF.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                            String port = "0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                            int index = host.lastIndexOf(":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                port = host.substring(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                host = host.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                            if (host.length() > 0 && port.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                int p = Integer.parseInt(port.trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                jConsole.addHost(host, p, userName, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                remoteTF.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                userNameTF.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                passwordTF.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                        statusBar.setText(ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                } else if (localRadioButton != null && localRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    // Try to connect to selected VM. If a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    // cannot be established for some reason (the process has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    // terminated for example) then keep the dialog open showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    // the connect error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                        jConsole.addVmid(vmModel.vmAt(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    refresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   356
        cancelAction = new AbstractAction(Messages.CANCEL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                statusBar.setText("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    // a label used solely for calculating the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private static JLabel tmpLabel = new JLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public static int getLabelWidth(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        tmpLabel.setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return (int) tmpLabel.getPreferredSize().getWidth() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    private class LocalTabJTable extends JTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        ManagedVmTableModel vmModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Border rendererBorder = new EmptyBorder(0, 6, 0, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        public LocalTabJTable(ManagedVmTableModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            super(model);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            this.vmModel = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            // Remove vertical lines, expect for GTK L&F.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            // (because GTK doesn't show header dividers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            if (!JConsole.IS_GTK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                setShowVerticalLines(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                setIntercellSpacing(new Dimension(0, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            // Double-click handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            addMouseListener(new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                public void mouseClicked(MouseEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    if (evt.getClickCount() == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                        connectButton.doClick();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            // Enter should call default action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            getActionMap().put("connect", connectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "connect");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        public String getToolTipText(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            java.awt.Point p = e.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            int rowIndex = rowAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            int colIndex = columnAtPoint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            int realColumnIndex = convertColumnIndexToModel(colIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (realColumnIndex == COL_NAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                LocalVirtualMachine vmd = vmModel.vmAt(rowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                tip = vmd.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        public TableCellRenderer getCellRenderer(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return new DefaultTableCellRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                public Component getTableCellRendererComponent(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                                               Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                                               boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                                               boolean hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                                               int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                                               int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    Component comp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        super.getTableCellRendererComponent(table, value, isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                                            hasFocus, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    if (!isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        LocalVirtualMachine lvm = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        if (!lvm.isManageable() && !lvm.isAttachable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                            comp.setForeground(disabledTableCellColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    if (comp instanceof JLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        JLabel label = (JLabel)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        label.setBorder(rendererBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                            label.setHorizontalAlignment(JLabel.RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public void setConnectionParameters(String url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                        String host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                                        int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                        String userName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                        String password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                                        String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if ((url != null && url.length() > 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            (host != null && host.length() > 0 && port > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            remoteRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            if (url != null && url.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                remoteTF.setText(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                remoteTF.setText(host+":"+port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            userNameTF.setText((userName != null) ? userName : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            passwordTF.setText((password != null) ? password : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            statusBar.setText((msg != null) ? msg : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (getPreferredSize().width > getWidth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            remoteTF.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            remoteTF.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public void itemStateChanged(ItemEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (!localRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            vmTable.getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    private void updateButtonStates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        boolean connectEnabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (remoteRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            connectEnabled = JConsole.isValidRemoteString(remoteTF.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        } else if (localRadioButton != null && localRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                LocalVirtualMachine lvm = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                connectEnabled = (lvm.isManageable() || lvm.isAttachable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        connectAction.setEnabled(connectEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public void insertUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public void removeUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public void changedUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        Component opposite = e.getOppositeComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (!e.isTemporary() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            source instanceof JTextField &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            opposite instanceof JComponent &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            SwingUtilities.getRootPane(opposite) == getRootPane()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            ((JTextField)source).selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (source == remoteTF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            remoteRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        } else if (source == vmTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            localRadioButton.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (vmModel.getRowCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                // if there's only one process then select the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                vmTable.setRowSelectionInterval(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    public void keyTyped(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        char c = e.getKeyChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if (c == KeyEvent.VK_ESCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        } else if (!(Character.isDigit(c) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                     c == KeyEvent.VK_BACK_SPACE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                     c == KeyEvent.VK_DELETE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            getToolkit().beep();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        boolean wasVisible = isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (b && !wasVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            SwingUtilities.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    if (remoteRadioButton.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                        remoteTF.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        remoteTF.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public void keyReleased(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    // ListSelectionListener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public void valueChanged(ListSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        updateButtonStates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        String labelText = " "; // Non-empty to reserve vertical space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            LocalVirtualMachine lvm = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (!lvm.isManageable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                if (lvm.isAttachable()) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   583
                    labelText = Messages.MANAGEMENT_WILL_BE_ENABLED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                } else {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   585
                    labelText = Messages.MANAGEMENT_NOT_ENABLED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        String colorStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            String.format("%06x", hintTextColor.getRGB() & 0xFFFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        localMessageLabel.setText("<html><font color=#" + colorStr + ">" + labelText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    // ----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    // Refresh the list of managed VMs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    public void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if (vmModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            // Remember selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            LocalVirtualMachine selected = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            int row = vmTable.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            if (row >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                selected = vmModel.vmAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            vmModel.refresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            int selectRow = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            int n = vmModel.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            if (selected != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    LocalVirtualMachine lvm = vmModel.vmAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    if (selected.vmid() == lvm.vmid() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                        selected.toString().equals(lvm.toString())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                        selectRow = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            if (selectRow > -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                vmTable.setRowSelectionInterval(selectRow, selectRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                vmTable.getSelectionModel().clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            Dimension dim = vmTable.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            // Tricky. Reduce height by one to avoid double line at bottom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            // but that causes a scroll bar to appear, so remove it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            dim.height = Math.min(dim.height-1, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            localTableScrollPane.setVerticalScrollBarPolicy((dim.height < 100)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                                ? JScrollPane.VERTICAL_SCROLLBAR_NEVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                                : JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            localTableScrollPane.getViewport().setMinimumSize(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            localTableScrollPane.getViewport().setPreferredSize(dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        setLocationRelativeTo(jConsole);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    // Represents the list of managed VMs as a tabular data model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    private static class ManagedVmTableModel extends AbstractTableModel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        private static String[] columnNames = {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   645
            Messages.COLUMN_NAME,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   646
            Messages.COLUMN_PID,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        private List<LocalVirtualMachine> vmList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            return columnNames.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        public String getColumnName(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            return columnNames[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        public synchronized int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            return vmList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        public synchronized Object getValueAt(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            assert col >= 0 && col <= columnNames.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            LocalVirtualMachine vm = vmList.get(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            switch (col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                case COL_NAME: return vm.displayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                case COL_PID:  return vm.vmid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                default: return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   673
        public Class<?> getColumnClass(int column) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            switch (column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                case COL_NAME: return String.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                case COL_PID:  return Integer.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                default: return super.getColumnClass(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        public ManagedVmTableModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            refresh();
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 synchronized LocalVirtualMachine vmAt(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            return vmList.get(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        public synchronized void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            Map<Integer, LocalVirtualMachine> map =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                LocalVirtualMachine.getAllVirtualMachines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            vmList = new ArrayList<LocalVirtualMachine>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            vmList.addAll(map.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            // data has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            fireTableDataChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    // A blank component that takes up as much space as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    // button part of a JRadioButton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    private static class Padder extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        JRadioButton radioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        Padder(JRadioButton radioButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            this.radioButton = radioButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   709
            setAccessibleName(this, Messages.BLANK);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            Rectangle r = getTextRectangle(radioButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            int w = (r != null && r.x > 8) ? r.x : 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            return new Dimension(w, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        private static Rectangle getTextRectangle(AbstractButton button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            String text = button.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (icon == null && button.getUI() instanceof BasicRadioButtonUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                icon = ((BasicRadioButtonUI)button.getUI()).getDefaultIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if ((icon == null) && (text == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            Rectangle paintIconR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            Rectangle paintTextR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            Rectangle paintViewR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            Insets paintViewInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            paintViewInsets = button.getInsets(paintViewInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            paintViewR.x = paintViewInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            paintViewR.y = paintViewInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            paintViewR.width = button.getWidth() - (paintViewInsets.left + paintViewInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            paintViewR.height = button.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            Graphics g = button.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                SwingUtilities.layoutCompoundLabel(button,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                                                   g.getFontMetrics(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                                                   text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                                   icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                                                   button.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                                                   button.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                                                   button.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                                                   button.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                                                   paintViewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                                                   paintIconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                                                   paintTextR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                                                   button.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            return paintTextR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
}