779 lines · 28.9 KB · Java
RawDownload
                LocalVirtualMachine lvm = vmModel.vmAt(row);                connectEnabled = (lvm.isManageable() || lvm.isAttachable());            }        }         connectAction.setEnabled(connectEnabled);    }     public void insertUpdate(DocumentEvent e) {        updateButtonStates();    }     public void removeUpdate(DocumentEvent e) {        updateButtonStates();    }     public void changedUpdate(DocumentEvent e) {        updateButtonStates();    }     public void focusGained(FocusEvent e) {        Object source = e.getSource();        Component opposite = e.getOppositeComponent();         if (!e.isTemporary() &&            source instanceof JTextField &&            opposite instanceof JComponent &&            SwingUtilities.getRootPane(opposite) == getRootPane()) {             ((JTextField)source).selectAll();        }         if (source == remoteTF) {            remoteRadioButton.setSelected(true);        } else if (source == vmTable) {            localRadioButton.setSelected(true);            if (vmModel.getRowCount() == 1) {                // if there's only one process then select the row                vmTable.setRowSelectionInterval(0, 0);            }        }        updateButtonStates();    }     public void focusLost(FocusEvent e) {    }     public void keyTyped(KeyEvent e) {        char c = e.getKeyChar();        if (c == KeyEvent.VK_ESCAPE) {            setVisible(false);        } else if (!(Character.isDigit(c) ||                     c == KeyEvent.VK_BACK_SPACE ||                     c == KeyEvent.VK_DELETE)) {            getToolkit().beep();            e.consume();        }    }     public void setVisible(boolean b) {        boolean wasVisible = isVisible();        super.setVisible(b);        if (b && !wasVisible) {            SwingUtilities.invokeLater(new Runnable() {                public void run() {                    if (remoteRadioButton.isSelected()) {                        remoteTF.requestFocus();                        remoteTF.selectAll();                    }                }            });        }    }     public void keyPressed(KeyEvent e) {    }     public void keyReleased(KeyEvent e) {    }      // ListSelectionListener interface    public void valueChanged(ListSelectionEvent e) {        updateButtonStates();        String labelText = " "; // Non-empty to reserve vertical space        int row = vmTable.getSelectedRow();        if (row >= 0) {            LocalVirtualMachine lvm = vmModel.vmAt(row);            if (!lvm.isManageable()) {                if (lvm.isAttachable()) {                    labelText = getText("Management Will Be Enabled");                } else {                    labelText = getText("Management Not Enabled");                }            }        }        String colorStr =            String.format("%06x", hintTextColor.getRGB() & 0xFFFFFF);        localMessageLabel.setText("<html><font color=#" + colorStr + ">" + labelText);    }    // ----      // Refresh the list of managed VMs    public void refresh() {        if (vmModel != null) {            // Remember selection            LocalVirtualMachine selected = null;            int row = vmTable.getSelectedRow();            if (row >= 0) {                selected = vmModel.vmAt(row);            }             vmModel.refresh();             int selectRow = -1;            int n = vmModel.getRowCount();            if (selected != null) {                for (int i = 0; i < n; i++) {                    LocalVirtualMachine lvm = vmModel.vmAt(i);                    if (selected.vmid() == lvm.vmid() &&                        selected.toString().equals(lvm.toString())) {                         selectRow = i;                        break;                    }                }            }            if (selectRow > -1) {                vmTable.setRowSelectionInterval(selectRow, selectRow);            } else {                vmTable.getSelectionModel().clearSelection();            }             Dimension dim = vmTable.getPreferredSize();             // Tricky. Reduce height by one to avoid double line at bottom,            // but that causes a scroll bar to appear, so remove it.            dim.height = Math.min(dim.height-1, 100);            localTableScrollPane.setVerticalScrollBarPolicy((dim.height < 100)                                                ? JScrollPane.VERTICAL_SCROLLBAR_NEVER                                                : JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);            localTableScrollPane.getViewport().setMinimumSize(dim);            localTableScrollPane.getViewport().setPreferredSize(dim);        }        pack();        setLocationRelativeTo(jConsole);    }     // Represents the list of managed VMs as a tabular data model.    private static class ManagedVmTableModel extends AbstractTableModel {        private static String[] columnNames = {            Resources.getText("Column.Name"),            Resources.getText("Column.PID"),        };         private List<LocalVirtualMachine> vmList;         public int getColumnCount() {            return columnNames.length;        }         public String getColumnName(int col) {            return columnNames[col];        }         public synchronized int getRowCount() {            return vmList.size();        }         public synchronized Object getValueAt(int row, int col) {            assert col >= 0 && col <= columnNames.length;            LocalVirtualMachine vm = vmList.get(row);            switch (col) {                case COL_NAME: return vm.displayName();                case COL_PID:  return vm.vmid();                default: return null;            }        }         public Class getColumnClass(int column) {            switch (column) {                case COL_NAME: return String.class;                case COL_PID:  return Integer.class;                default: return super.getColumnClass(column);            }        }         public ManagedVmTableModel() {            refresh();        }          public synchronized LocalVirtualMachine vmAt(int pos) {            return vmList.get(pos);        }         public synchronized void refresh() {            Map<Integer, LocalVirtualMachine> map =                LocalVirtualMachine.getAllVirtualMachines();            vmList = new ArrayList<LocalVirtualMachine>();            vmList.addAll(map.values());             // data has changed            fireTableDataChanged();        }    }      // Convenience method    private static String getText(String key) {        return Resources.getText(key);    }      // A blank component that takes up as much space as the    // button part of a JRadioButton.    private static class Padder extends JPanel {        JRadioButton radioButton;         Padder(JRadioButton radioButton) {            this.radioButton = radioButton;             setAccessibleName(this, getText("Blank"));        }         public Dimension getPreferredSize() {            Rectangle r = getTextRectangle(radioButton);            int w = (r != null && r.x > 8) ? r.x : 22;             return new Dimension(w, 0);        }         private static Rectangle getTextRectangle(AbstractButton button) {            String text = button.getText();            Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();             if (icon == null && button.getUI() instanceof BasicRadioButtonUI) {                icon = ((BasicRadioButtonUI)button.getUI()).getDefaultIcon();            }             if ((icon == null) && (text == null)) {                return null;            }             Rectangle paintIconR = new Rectangle();            Rectangle paintTextR = new Rectangle();            Rectangle paintViewR = new Rectangle();            Insets paintViewInsets = new Insets(0, 0, 0, 0);             paintViewInsets = button.getInsets(paintViewInsets);            paintViewR.x = paintViewInsets.left;            paintViewR.y = paintViewInsets.top;            paintViewR.width = button.getWidth() - (paintViewInsets.left + paintViewInsets.right);            paintViewR.height = button.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);             Graphics g = button.getGraphics();            if (g == null) {                return null;            }            String clippedText =                SwingUtilities.layoutCompoundLabel(button,                                                   g.getFontMetrics(),                                                   text,                                                   icon,                                                   button.getVerticalAlignment(),                                                   button.getHorizontalAlignment(),                                                   button.getVerticalTextPosition(),                                                   button.getHorizontalTextPosition(),                                                   paintViewR,                                                   paintIconR,                                                   paintTextR,                                                   button.getIconTextGap());             return paintTextR;        }    } }

Lines 501–779 of 779. Previous lines