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