0N/A/*
0N/A * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
2362N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Oracle designates this
2362N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2362N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/Apackage sun.tools.jconsole;
0N/A
0N/Aimport java.util.List;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.util.*;
0N/A
3984N/Aimport javax.swing.*;
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.plaf.basic.BasicRadioButtonUI;
0N/Aimport javax.swing.table.*;
0N/A
0N/A
0N/A
0N/Aimport static java.awt.BorderLayout.*;
0N/Aimport static javax.swing.ListSelectionModel.*;
0N/Aimport static sun.tools.jconsole.Utilities.*;
0N/A
0N/A@SuppressWarnings("serial")
0N/Apublic class ConnectDialog extends InternalDialog
0N/A implements DocumentListener, FocusListener,
0N/A ItemListener, ListSelectionListener, KeyListener {
0N/A
0N/A private static final int COL_NAME = 0;
0N/A private static final int COL_PID = 1;
0N/A
0N/A
0N/A JConsole jConsole;
0N/A JTextField userNameTF, passwordTF;
0N/A JRadioButton localRadioButton, remoteRadioButton;
0N/A JLabel localMessageLabel, remoteMessageLabel;
0N/A JTextField remoteTF;
0N/A JButton connectButton, cancelButton;
0N/A JPanel radioButtonPanel;
0N/A
0N/A private Icon mastheadIcon =
0N/A new MastheadIcon(Messages.CONNECT_DIALOG_MASTHEAD_TITLE);
0N/A private Color hintTextColor, disabledTableCellColor;
0N/A
0N/A // The table of managed VM (local process)
0N/A JTable vmTable;
0N/A ManagedVmTableModel vmModel = null;
0N/A
0N/A JScrollPane localTableScrollPane = null;
0N/A
0N/A private Action connectAction, cancelAction;
0N/A
0N/A
0N/A public ConnectDialog(JConsole jConsole) {
0N/A super(jConsole, Messages.CONNECT_DIALOG_TITLE, true);
0N/A
0N/A this.jConsole = jConsole;
0N/A setAccessibleDescription(this,
0N/A Messages.CONNECT_DIALOG_ACCESSIBLE_DESCRIPTION);
0N/A setDefaultCloseOperation(HIDE_ON_CLOSE);
0N/A setResizable(false);
0N/A Container cp = (JComponent)getContentPane();
0N/A
0N/A radioButtonPanel = new JPanel(new BorderLayout(0, 12));
0N/A radioButtonPanel.setBorder(new EmptyBorder(6, 12, 12, 12));
0N/A ButtonGroup radioButtonGroup = new ButtonGroup();
0N/A JPanel bottomPanel = new JPanel(new BorderLayout());
0N/A
0N/A statusBar = new JLabel(" ", JLabel.CENTER);
0N/A setAccessibleName(statusBar,
0N/A Messages.CONNECT_DIALOG_STATUS_BAR_ACCESSIBLE_NAME);
0N/A
0N/A Font normalLabelFont = statusBar.getFont();
0N/A Font boldLabelFont = normalLabelFont.deriveFont(Font.BOLD);
0N/A Font smallLabelFont = normalLabelFont.deriveFont(normalLabelFont.getSize2D() - 1);
0N/A
0N/A JLabel mastheadLabel = new JLabel(mastheadIcon);
0N/A setAccessibleName(mastheadLabel,
0N/A Messages.CONNECT_DIALOG_MASTHEAD_ACCESSIBLE_NAME);
0N/A
0N/A cp.add(mastheadLabel, NORTH);
0N/A cp.add(radioButtonPanel, CENTER);
0N/A cp.add(bottomPanel, SOUTH);
0N/A
0N/A createActions();
0N/A
0N/A remoteTF = new JTextField();
0N/A remoteTF.addActionListener(connectAction);
0N/A remoteTF.getDocument().addDocumentListener(this);
0N/A remoteTF.addFocusListener(this);
0N/A remoteTF.setPreferredSize(remoteTF.getPreferredSize());
0N/A setAccessibleName(remoteTF,
0N/A Messages.REMOTE_PROCESS_TEXT_FIELD_ACCESSIBLE_NAME);
0N/A
0N/A //
0N/A // If the VM supports the local attach mechanism (is: Sun
0N/A // implementation) then the Local Process panel is created.
0N/A //
0N/A if (JConsole.isLocalAttachAvailable()) {
0N/A vmModel = new ManagedVmTableModel();
0N/A vmTable = new LocalTabJTable(vmModel);
0N/A vmTable.setSelectionMode(SINGLE_SELECTION);
0N/A vmTable.setPreferredScrollableViewportSize(new Dimension(400, 250));
0N/A vmTable.setColumnSelectionAllowed(false);
0N/A vmTable.addFocusListener(this);
0N/A vmTable.getSelectionModel().addListSelectionListener(this);
0N/A
0N/A TableColumnModel columnModel = vmTable.getColumnModel();
0N/A
0N/A TableColumn pidColumn = columnModel.getColumn(COL_PID);
0N/A pidColumn.setMaxWidth(getLabelWidth("9999999"));
0N/A pidColumn.setResizable(false);
0N/A
0N/A TableColumn cmdLineColumn = columnModel.getColumn(COL_NAME);
0N/A cmdLineColumn.setResizable(false);
0N/A
0N/A localRadioButton = new JRadioButton(Messages.LOCAL_PROCESS_COLON);
0N/A localRadioButton.setMnemonic(Resources.getMnemonicInt(Messages.LOCAL_PROCESS_COLON));
0N/A localRadioButton.setFont(boldLabelFont);
0N/A localRadioButton.addItemListener(this);
0N/A radioButtonGroup.add(localRadioButton);
0N/A
0N/A JPanel localPanel = new JPanel(new BorderLayout());
0N/A
0N/A JPanel localTablePanel = new JPanel(new BorderLayout());
0N/A
0N/A radioButtonPanel.add(localPanel, NORTH);
0N/A
0N/A localPanel.add(localRadioButton, NORTH);
0N/A localPanel.add(new Padder(localRadioButton), LINE_START);
0N/A localPanel.add(localTablePanel, CENTER);
0N/A
0N/A localTableScrollPane = new JScrollPane(vmTable);
0N/A
0N/A localTablePanel.add(localTableScrollPane, NORTH);
0N/A
0N/A localMessageLabel = new JLabel(" ");
0N/A localMessageLabel.setFont(smallLabelFont);
0N/A localMessageLabel.setForeground(hintTextColor);
0N/A localTablePanel.add(localMessageLabel, SOUTH);
0N/A }
0N/A
0N/A remoteRadioButton = new JRadioButton(Messages.REMOTE_PROCESS_COLON);
0N/A remoteRadioButton.setMnemonic(Resources.getMnemonicInt(Messages.REMOTE_PROCESS_COLON));
0N/A remoteRadioButton.setFont(boldLabelFont);
0N/A radioButtonGroup.add(remoteRadioButton);
0N/A
1024N/A JPanel remotePanel = new JPanel(new BorderLayout());
1024N/A if (localRadioButton != null) {
1024N/A remotePanel.add(remoteRadioButton, NORTH);
1024N/A remotePanel.add(new Padder(remoteRadioButton), LINE_START);
1024N/A
0N/A Action nextRadioButtonAction =
0N/A new AbstractAction("nextRadioButton") {
0N/A public void actionPerformed(ActionEvent ev) {
0N/A JRadioButton rb =
0N/A (ev.getSource() == localRadioButton) ? remoteRadioButton
0N/A : localRadioButton;
0N/A rb.doClick();
0N/A rb.requestFocus();
0N/A }
0N/A };
0N/A
0N/A localRadioButton.getActionMap().put("nextRadioButton", nextRadioButtonAction);
0N/A remoteRadioButton.getActionMap().put("nextRadioButton", nextRadioButtonAction);
0N/A
1024N/A localRadioButton.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
1024N/A "nextRadioButton");
1024N/A remoteRadioButton.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),
1024N/A "nextRadioButton");
1024N/A } else {
1024N/A JLabel remoteLabel = new JLabel(remoteRadioButton.getText());
1024N/A remoteLabel.setFont(boldLabelFont);
1024N/A remotePanel.add(remoteLabel, NORTH);
1024N/A }
1024N/A radioButtonPanel.add(remotePanel, SOUTH);
0N/A
0N/A JPanel remoteTFPanel = new JPanel(new BorderLayout());
0N/A remotePanel.add(remoteTFPanel, CENTER);
0N/A
0N/A remoteTFPanel.add(remoteTF, NORTH);
0N/A
0N/A remoteMessageLabel = new JLabel("<html>" + Messages.REMOTE_TF_USAGE + "</html>");
0N/A remoteMessageLabel.setFont(smallLabelFont);
0N/A remoteMessageLabel.setForeground(hintTextColor);
0N/A remoteTFPanel.add(remoteMessageLabel, CENTER);
0N/A
0N/A JPanel userPwdPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
0N/A userPwdPanel.setBorder(new EmptyBorder(12, 0, 0, 0)); // top padding
0N/A
0N/A int tfWidth = JConsole.IS_WIN ? 12 : 8;
0N/A
0N/A userNameTF = new JTextField(tfWidth);
0N/A userNameTF.addActionListener(connectAction);
0N/A userNameTF.getDocument().addDocumentListener(this);
0N/A userNameTF.addFocusListener(this);
0N/A setAccessibleName(userNameTF,
0N/A Messages.USERNAME_ACCESSIBLE_NAME);
0N/A LabeledComponent lc;
0N/A lc = new LabeledComponent(Messages.USERNAME_COLON_,
0N/A Resources.getMnemonicInt(Messages.USERNAME_COLON_),
0N/A userNameTF);
0N/A lc.label.setFont(boldLabelFont);
0N/A userPwdPanel.add(lc);
0N/A
0N/A passwordTF = new JPasswordField(tfWidth);
0N/A // Heights differ, so fix here
0N/A passwordTF.setPreferredSize(userNameTF.getPreferredSize());
0N/A passwordTF.addActionListener(connectAction);
0N/A passwordTF.getDocument().addDocumentListener(this);
0N/A passwordTF.addFocusListener(this);
0N/A setAccessibleName(passwordTF,
0N/A Messages.PASSWORD_ACCESSIBLE_NAME);
0N/A
0N/A lc = new LabeledComponent(Messages.PASSWORD_COLON_,
0N/A Resources.getMnemonicInt(Messages.PASSWORD_COLON_),
0N/A passwordTF);
0N/A lc.setBorder(new EmptyBorder(0, 12, 0, 0)); // Left padding
0N/A lc.label.setFont(boldLabelFont);
0N/A userPwdPanel.add(lc);
0N/A
0N/A remoteTFPanel.add(userPwdPanel, SOUTH);
0N/A
0N/A String connectButtonToolTipText =
0N/A Messages.CONNECT_DIALOG_CONNECT_BUTTON_TOOLTIP;
0N/A connectButton = new JButton(connectAction);
0N/A connectButton.setToolTipText(connectButtonToolTipText);
0N/A
0N/A cancelButton = new JButton(cancelAction);
0N/A
0N/A JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
0N/A buttonPanel.setBorder(new EmptyBorder(12, 12, 2, 12));
0N/A if (JConsole.IS_GTK) {
0N/A buttonPanel.add(cancelButton);
0N/A buttonPanel.add(connectButton);
0N/A } else {
0N/A buttonPanel.add(connectButton);
0N/A buttonPanel.add(cancelButton);
0N/A }
0N/A bottomPanel.add(buttonPanel, NORTH);
0N/A
0N/A bottomPanel.add(statusBar, SOUTH);
0N/A
0N/A updateButtonStates();
0N/A Utilities.updateTransparency(this);
0N/A }
0N/A
0N/A public void revalidate() {
0N/A // Adjust some colors
0N/A hintTextColor =
0N/A ensureContrast(UIManager.getColor("Label.disabledForeground"),
0N/A UIManager.getColor("Panel.background"));
0N/A disabledTableCellColor =
0N/A ensureContrast(new Color(0x808080),
0N/A UIManager.getColor("Table.background"));
0N/A
0N/A if (remoteMessageLabel != null) {
0N/A remoteMessageLabel.setForeground(hintTextColor);
0N/A // Update html color setting
0N/A String colorStr =
0N/A String.format("%06x", hintTextColor.getRGB() & 0xFFFFFF);
0N/A remoteMessageLabel.setText("<html><font color=#" + colorStr + ">" +
0N/A Messages.REMOTE_TF_USAGE);
0N/A }
0N/A if (localMessageLabel != null) {
0N/A localMessageLabel.setForeground(hintTextColor);
0N/A // Update html color setting
0N/A valueChanged(null);
0N/A }
0N/A
0N/A super.revalidate();
0N/A }
0N/A
0N/A private void createActions() {
0N/A connectAction = new AbstractAction(Messages.CONNECT) {
0N/A /* init */ {
0N/A putValue(Action.MNEMONIC_KEY, Resources.getMnemonicInt(Messages.CONNECT));
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent ev) {
0N/A if (!isEnabled() || !isVisible()) {
0N/A return;
0N/A }
0N/A setVisible(false);
0N/A statusBar.setText("");
0N/A
0N/A if (remoteRadioButton.isSelected()) {
0N/A String txt = remoteTF.getText().trim();
0N/A String userName = userNameTF.getText().trim();
0N/A userName = userName.equals("") ? null : userName;
0N/A String password = passwordTF.getText();
0N/A password = password.equals("") ? null : password;
0N/A try {
0N/A if (txt.startsWith(JConsole.ROOT_URL)) {
0N/A String url = txt;
0N/A jConsole.addUrl(url, userName, password, false);
0N/A remoteTF.setText(JConsole.ROOT_URL);
0N/A return;
0N/A } else {
0N/A String host = remoteTF.getText().trim();
0N/A String port = "0";
0N/A int index = host.lastIndexOf(":");
0N/A if (index >= 0) {
0N/A port = host.substring(index + 1);
0N/A host = host.substring(0, index);
0N/A }
0N/A if (host.length() > 0 && port.length() > 0) {
0N/A int p = Integer.parseInt(port.trim());
0N/A jConsole.addHost(host, p, userName, password);
0N/A remoteTF.setText("");
0N/A userNameTF.setText("");
0N/A passwordTF.setText("");
0N/A return;
0N/A }
0N/A }
0N/A } catch (Exception ex) {
0N/A statusBar.setText(ex.toString());
0N/A }
0N/A setVisible(true);
0N/A } else if (localRadioButton != null && localRadioButton.isSelected()) {
0N/A // Try to connect to selected VM. If a connection
0N/A // cannot be established for some reason (the process has
0N/A // terminated for example) then keep the dialog open showing
0N/A // the connect error.
0N/A //
0N/A int row = vmTable.getSelectedRow();
0N/A if (row >= 0) {
0N/A jConsole.addVmid(vmModel.vmAt(row));
0N/A }
0N/A refresh();
0N/A }
0N/A }
0N/A };
0N/A
0N/A cancelAction = new AbstractAction(Messages.CANCEL) {
0N/A public void actionPerformed(ActionEvent ev) {
0N/A setVisible(false);
0N/A statusBar.setText("");
0N/A }
0N/A };
0N/A }
0N/A
0N/A
0N/A // a label used solely for calculating the width
0N/A private static JLabel tmpLabel = new JLabel();
0N/A public static int getLabelWidth(String text) {
0N/A tmpLabel.setText(text);
0N/A return (int) tmpLabel.getPreferredSize().getWidth() + 1;
0N/A }
0N/A
0N/A private class LocalTabJTable extends JTable {
0N/A ManagedVmTableModel vmModel;
0N/A Border rendererBorder = new EmptyBorder(0, 6, 0, 6);
0N/A
0N/A public LocalTabJTable(ManagedVmTableModel model) {
0N/A super(model);
0N/A this.vmModel = model;
0N/A
0N/A // Remove vertical lines, expect for GTK L&F.
0N/A // (because GTK doesn't show header dividers)
0N/A if (!JConsole.IS_GTK) {
0N/A setShowVerticalLines(false);
0N/A setIntercellSpacing(new Dimension(0, 1));
0N/A }
0N/A
0N/A // Double-click handler
0N/A addMouseListener(new MouseAdapter() {
0N/A public void mouseClicked(MouseEvent evt) {
0N/A if (evt.getClickCount() == 2) {
0N/A connectButton.doClick();
0N/A }
0N/A }
0N/A });
0N/A
0N/A // Enter should call default action
0N/A getActionMap().put("connect", connectAction);
0N/A InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0N/A inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "connect");
0N/A }
0N/A
0N/A public String getToolTipText(MouseEvent e) {
0N/A String tip = null;
0N/A java.awt.Point p = e.getPoint();
0N/A int rowIndex = rowAtPoint(p);
0N/A int colIndex = columnAtPoint(p);
0N/A int realColumnIndex = convertColumnIndexToModel(colIndex);
0N/A
0N/A if (realColumnIndex == COL_NAME) {
0N/A LocalVirtualMachine vmd = vmModel.vmAt(rowIndex);
0N/A tip = vmd.toString();
0N/A }
0N/A return tip;
0N/A }
0N/A
0N/A public TableCellRenderer getCellRenderer(int row, int column) {
1024N/A return new DefaultTableCellRenderer() {
1024N/A public Component getTableCellRendererComponent(JTable table,
1024N/A Object value,
0N/A boolean isSelected,
1024N/A boolean hasFocus,
1024N/A int row,
1024N/A int column) {
0N/A Component comp =
0N/A super.getTableCellRendererComponent(table, value, isSelected,
0N/A hasFocus, row, column);
0N/A
0N/A if (!isSelected) {
0N/A LocalVirtualMachine lvm = vmModel.vmAt(row);
0N/A if (!lvm.isManageable() && !lvm.isAttachable()) {
0N/A comp.setForeground(disabledTableCellColor);
0N/A }
0N/A }
0N/A
0N/A if (comp instanceof JLabel) {
0N/A JLabel label = (JLabel)comp;
0N/A label.setBorder(rendererBorder);
0N/A
0N/A if (value instanceof Integer) {
0N/A label.setHorizontalAlignment(JLabel.RIGHT);
0N/A }
0N/A }
1024N/A
1024N/A return comp;
1024N/A }
1024N/A };
1024N/A }
1024N/A }
1024N/A
1024N/A public void setConnectionParameters(String url,
1024N/A String host,
1024N/A int port,
1024N/A String userName,
1024N/A String password,
1024N/A String msg) {
1024N/A if ((url != null && url.length() > 0) ||
1024N/A (host != null && host.length() > 0 && port > 0)) {
1024N/A
1024N/A remoteRadioButton.setSelected(true);
1024N/A if (url != null && url.length() > 0) {
1024N/A remoteTF.setText(url);
1024N/A } else {
1024N/A remoteTF.setText(host+":"+port);
1024N/A }
1024N/A userNameTF.setText((userName != null) ? userName : "");
1024N/A passwordTF.setText((password != null) ? password : "");
1024N/A
1024N/A statusBar.setText((msg != null) ? msg : "");
1024N/A if (getPreferredSize().width > getWidth()) {
1024N/A pack();
1024N/A }
1024N/A remoteTF.requestFocus();
1024N/A remoteTF.selectAll();
1024N/A }
1024N/A }
1024N/A
1024N/A
0N/A public void itemStateChanged(ItemEvent ev) {
1024N/A if (!localRadioButton.isSelected()) {
1024N/A vmTable.getSelectionModel().clearSelection();
0N/A }
0N/A updateButtonStates();
0N/A }
0N/A
0N/A private void updateButtonStates() {
1024N/A boolean connectEnabled = false;
0N/A
1024N/A if (remoteRadioButton.isSelected()) {
1024N/A connectEnabled = JConsole.isValidRemoteString(remoteTF.getText());
1024N/A } else if (localRadioButton != null && localRadioButton.isSelected()) {
1024N/A int row = vmTable.getSelectedRow();
1024N/A if (row >= 0) {
1024N/A LocalVirtualMachine lvm = vmModel.vmAt(row);
1024N/A connectEnabled = (lvm.isManageable() || lvm.isAttachable());
1024N/A }
1024N/A }
1024N/A
1024N/A connectAction.setEnabled(connectEnabled);
1024N/A }
1024N/A
1024N/A public void insertUpdate(DocumentEvent e) {
1024N/A updateButtonStates();
1024N/A }
0N/A
0N/A public void removeUpdate(DocumentEvent e) {
1024N/A updateButtonStates();
0N/A }
0N/A
0N/A public void changedUpdate(DocumentEvent e) {
0N/A updateButtonStates();
0N/A }
0N/A
0N/A public void focusGained(FocusEvent e) {
0N/A Object source = e.getSource();
0N/A Component opposite = e.getOppositeComponent();
0N/A
0N/A if (!e.isTemporary() &&
0N/A source instanceof JTextField &&
0N/A opposite instanceof JComponent &&
0N/A SwingUtilities.getRootPane(opposite) == getRootPane()) {
0N/A
0N/A ((JTextField)source).selectAll();
0N/A }
0N/A
0N/A if (source == remoteTF) {
0N/A remoteRadioButton.setSelected(true);
0N/A } else if (source == vmTable) {
0N/A localRadioButton.setSelected(true);
1024N/A if (vmModel.getRowCount() == 1) {
1024N/A // if there's only one process then select the row
1024N/A vmTable.setRowSelectionInterval(0, 0);
0N/A }
0N/A }
1024N/A updateButtonStates();
1024N/A }
1024N/A
0N/A public void focusLost(FocusEvent e) {
0N/A }
1024N/A
0N/A public void keyTyped(KeyEvent e) {
0N/A char c = e.getKeyChar();
0N/A if (c == KeyEvent.VK_ESCAPE) {
1024N/A setVisible(false);
1024N/A } else if (!(Character.isDigit(c) ||
1024N/A c == KeyEvent.VK_BACK_SPACE ||
1024N/A c == KeyEvent.VK_DELETE)) {
1024N/A getToolkit().beep();
1024N/A e.consume();
1024N/A }
0N/A }
0N/A
0N/A public void setVisible(boolean b) {
0N/A boolean wasVisible = isVisible();
0N/A super.setVisible(b);
0N/A if (b && !wasVisible) {
0N/A SwingUtilities.invokeLater(new Runnable() {
0N/A public void run() {
0N/A if (remoteRadioButton.isSelected()) {
0N/A remoteTF.requestFocus();
0N/A remoteTF.selectAll();
0N/A }
0N/A }
0N/A });
0N/A }
0N/A }
0N/A
0N/A public void keyPressed(KeyEvent e) {
0N/A }
0N/A
0N/A public void keyReleased(KeyEvent e) {
1024N/A }
1024N/A
0N/A
0N/A // ListSelectionListener interface
0N/A public void valueChanged(ListSelectionEvent e) {
0N/A updateButtonStates();
0N/A String labelText = " "; // Non-empty to reserve vertical space
1024N/A int row = vmTable.getSelectedRow();
0N/A if (row >= 0) {
0N/A LocalVirtualMachine lvm = vmModel.vmAt(row);
0N/A if (!lvm.isManageable()) {
0N/A if (lvm.isAttachable()) {
0N/A labelText = Messages.MANAGEMENT_WILL_BE_ENABLED;
0N/A } else {
0N/A labelText = Messages.MANAGEMENT_NOT_ENABLED;
0N/A }
1024N/A }
0N/A }
1024N/A String colorStr =
1024N/A String.format("%06x", hintTextColor.getRGB() & 0xFFFFFF);
1024N/A localMessageLabel.setText("<html><font color=#" + colorStr + ">" + labelText);
0N/A }
1024N/A // ----
1024N/A
0N/A
0N/A // Refresh the list of managed VMs
0N/A public void refresh() {
0N/A if (vmModel != null) {
0N/A // Remember selection
0N/A LocalVirtualMachine selected = null;
0N/A int row = vmTable.getSelectedRow();
0N/A if (row >= 0) {
0N/A selected = vmModel.vmAt(row);
0N/A }
0N/A
0N/A vmModel.refresh();
0N/A
0N/A int selectRow = -1;
0N/A int n = vmModel.getRowCount();
0N/A if (selected != null) {
0N/A for (int i = 0; i < n; i++) {
0N/A LocalVirtualMachine lvm = vmModel.vmAt(i);
0N/A if (selected.vmid() == lvm.vmid() &&
0N/A selected.toString().equals(lvm.toString())) {
0N/A
0N/A selectRow = i;
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A if (selectRow > -1) {
0N/A vmTable.setRowSelectionInterval(selectRow, selectRow);
0N/A } else {
0N/A vmTable.getSelectionModel().clearSelection();
0N/A }
0N/A
0N/A Dimension dim = vmTable.getPreferredSize();
0N/A
0N/A // Tricky. Reduce height by one to avoid double line at bottom,
0N/A // but that causes a scroll bar to appear, so remove it.
0N/A dim.height = Math.min(dim.height-1, 100);
0N/A localTableScrollPane.setVerticalScrollBarPolicy((dim.height < 100)
0N/A ? JScrollPane.VERTICAL_SCROLLBAR_NEVER
0N/A : JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
0N/A localTableScrollPane.getViewport().setMinimumSize(dim);
0N/A localTableScrollPane.getViewport().setPreferredSize(dim);
0N/A }
0N/A pack();
0N/A setLocationRelativeTo(jConsole);
0N/A }
0N/A
0N/A // Represents the list of managed VMs as a tabular data model.
0N/A private static class ManagedVmTableModel extends AbstractTableModel {
0N/A private static String[] columnNames = {
0N/A Messages.COLUMN_NAME,
0N/A Messages.COLUMN_PID,
0N/A };
0N/A
0N/A private List<LocalVirtualMachine> vmList;
0N/A
0N/A public int getColumnCount() {
0N/A return columnNames.length;
0N/A }
0N/A
0N/A public String getColumnName(int col) {
0N/A return columnNames[col];
0N/A }
0N/A
0N/A public synchronized int getRowCount() {
0N/A return vmList.size();
0N/A }
0N/A
0N/A public synchronized Object getValueAt(int row, int col) {
0N/A assert col >= 0 && col <= columnNames.length;
0N/A LocalVirtualMachine vm = vmList.get(row);
0N/A switch (col) {
0N/A case COL_NAME: return vm.displayName();
0N/A case COL_PID: return vm.vmid();
0N/A default: return null;
0N/A }
0N/A }
0N/A
0N/A public Class<?> getColumnClass(int column) {
0N/A switch (column) {
0N/A case COL_NAME: return String.class;
0N/A case COL_PID: return Integer.class;
0N/A default: return super.getColumnClass(column);
0N/A }
0N/A }
0N/A
0N/A public ManagedVmTableModel() {
0N/A refresh();
0N/A }
0N/A
0N/A
0N/A public synchronized LocalVirtualMachine vmAt(int pos) {
0N/A return vmList.get(pos);
0N/A }
0N/A
0N/A public synchronized void refresh() {
0N/A Map<Integer, LocalVirtualMachine> map =
0N/A LocalVirtualMachine.getAllVirtualMachines();
0N/A vmList = new ArrayList<LocalVirtualMachine>();
0N/A vmList.addAll(map.values());
0N/A
0N/A // data has changed
0N/A fireTableDataChanged();
0N/A }
0N/A }
0N/A
0N/A // A blank component that takes up as much space as the
0N/A // button part of a JRadioButton.
0N/A private static class Padder extends JPanel {
0N/A JRadioButton radioButton;
0N/A
0N/A Padder(JRadioButton radioButton) {
0N/A this.radioButton = radioButton;
0N/A
0N/A setAccessibleName(this, Messages.BLANK);
0N/A }
0N/A
0N/A public Dimension getPreferredSize() {
0N/A Rectangle r = getTextRectangle(radioButton);
0N/A int w = (r != null && r.x > 8) ? r.x : 22;
0N/A
0N/A return new Dimension(w, 0);
0N/A }
0N/A
0N/A private static Rectangle getTextRectangle(AbstractButton button) {
0N/A String text = button.getText();
0N/A Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();
0N/A
0N/A if (icon == null && button.getUI() instanceof BasicRadioButtonUI) {
0N/A icon = ((BasicRadioButtonUI)button.getUI()).getDefaultIcon();
0N/A }
0N/A
0N/A if ((icon == null) && (text == null)) {
0N/A return null;
0N/A }
0N/A
0N/A Rectangle paintIconR = new Rectangle();
0N/A Rectangle paintTextR = new Rectangle();
0N/A Rectangle paintViewR = new Rectangle();
0N/A Insets paintViewInsets = new Insets(0, 0, 0, 0);
0N/A
0N/A paintViewInsets = button.getInsets(paintViewInsets);
0N/A paintViewR.x = paintViewInsets.left;
0N/A paintViewR.y = paintViewInsets.top;
0N/A paintViewR.width = button.getWidth() - (paintViewInsets.left + paintViewInsets.right);
0N/A paintViewR.height = button.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
0N/A
0N/A Graphics g = button.getGraphics();
0N/A if (g == null) {
0N/A return null;
0N/A }
0N/A SwingUtilities.layoutCompoundLabel(button,
0N/A g.getFontMetrics(),
0N/A text,
0N/A icon,
0N/A button.getVerticalAlignment(),
0N/A button.getHorizontalAlignment(),
0N/A button.getVerticalTextPosition(),
0N/A button.getHorizontalTextPosition(),
0N/A paintViewR,
0N/A paintIconR,
0N/A paintTextR,
0N/A button.getIconTextGap());
0N/A
0N/A return paintTextR;
0N/A }
0N/A }
0N/A
0N/A}
0N/A