|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.debugger.jpda.ui; import com.sun.jdi.Bootstrap; import com.sun.jdi.VirtualMachine; import com.sun.jdi.VirtualMachineManager; import com.sun.jdi.connect.AttachingConnector; import com.sun.jdi.connect.Connector; import com.sun.jdi.connect.Connector.Argument; import com.sun.jdi.connect.IllegalConnectorArgumentsException; import com.sun.jdi.connect.ListeningConnector; import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.DebuggerInfo; import org.netbeans.api.debugger.Properties; import org.netbeans.api.debugger.jpda.JPDADebugger; import org.netbeans.api.debugger.jpda.AbstractDICookie; import org.netbeans.api.debugger.jpda.AttachingDICookie; import org.netbeans.api.debugger.jpda.ListeningDICookie; import org.netbeans.spi.debugger.ui.Controller; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.util.NbBundle; /** * Panel for entering parameters of attaching to a remote VM. * If the debugger offers more * connectors * then the panel contains also a combo-box for selecting a connector. * * @author Jan Jancura */ public class ConnectPanel extends JPanel implements Controller, ActionListener { /** List of all AttachingConnectors.*/ private List connectors; /** Combo with list of all AttachingConnector names.*/ private JComboBox cbConnectors; /** List of JTextFields containing all parameters of curentConnector. */ private JTextField[] tfParams; public ConnectPanel () { VirtualMachineManager vmm = Bootstrap.virtualMachineManager (); connectors = new ArrayList (); connectors.addAll (vmm.attachingConnectors ()); connectors.addAll (vmm.listeningConnectors ()); if (connectors.size () == 0) { // no attaching connectors available => print message only add (new JLabel ( NbBundle.getMessage (ConnectPanel.class, "CTL_No_Connector") )); return; } int defaultIndex = 0; if (connectors.size () > 1) { // more than one attaching connector available => // init cbConnectors & selext default connector cbConnectors = new JComboBox (); cbConnectors.getAccessibleContext ().setAccessibleDescription ( NbBundle.getMessage (ConnectPanel.class, "ACSD_CTL_Connector") ); String lacn = Properties.getDefault ().getProperties ("debugger"). getString ("last_attaching_connector", ""); int i, k = connectors.size (); for (i = 0; i < k; i++) { Connector connector = (Connector) connectors.get (i); if ((lacn != null) && connector.name ().equals (lacn)) defaultIndex = i; int jj = connector.name ().lastIndexOf ('.'); String s = (jj < 0) ? connector.name () : connector.name ().substring (jj + 1); cbConnectors.addItem ( s + " (" + connector.description () + ")" ); } cbConnectors.setActionCommand ("SwitchMe!"); cbConnectors.addActionListener (this); } cbConnectors.setSelectedIndex (defaultIndex); } /** * Adds options for a selected connector type to this panel. */ private void refresh (int index) { removeAll(); Connector connector = (Connector) connectors.get (index); GridBagConstraints c; GridBagLayout layout = new GridBagLayout (); setLayout (layout); if (cbConnectors != null) { // more than oneconnection => first line contains connector // selector c = new GridBagConstraints (); c.insets = new Insets (0, 0, 3, 3); JLabel lblConnectors = new JLabel ( NbBundle.getMessage (ConnectPanel.class, "CTL_Connector") // NOI18N ); lblConnectors.setDisplayedMnemonic ( NbBundle.getMessage (ConnectPanel.class, "MN_CTL_Connector").charAt (0) // NOI18N ); lblConnectors.setLabelFor (cbConnectors); layout.setConstraints (lblConnectors, c); add (lblConnectors); c.insets = new Insets (0, 3, 3, 0); c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints (cbConnectors, c); add (cbConnectors); } // second line => transport c = new GridBagConstraints (); c.insets = new Insets (3, 0, 0, 6); JLabel lblTransport = new JLabel ( NbBundle.getMessage (ConnectPanel.class, "CTL_Transport") ); lblTransport.setDisplayedMnemonic ( NbBundle.getMessage (ConnectPanel.class, "CTL_Transport_Mnemonic").charAt(0) ); layout.setConstraints (lblTransport, c); add (lblTransport); final JTextField tfTransport = new JTextField (); tfTransport.setEditable (false); lblTransport.setLabelFor (tfTransport); c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets (3, 3, 0, 0); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; layout.setConstraints (tfTransport, c); tfTransport.setText (connector.transport ().name ()); tfTransport.getAccessibleContext ().setAccessibleDescription ( NbBundle.getMessage (ConnectPanel.class, "ACSD_CTL_Transport") ); tfTransport.addFocusListener (new FocusAdapter () { public void focusGained (FocusEvent evt) { tfTransport.selectAll (); } }); add (tfTransport); // other lines Map args = getSavedArgs (connector); tfParams = new JTextField [args.size ()]; Iterator it = args.keySet ().iterator (); int i = 0; while (it.hasNext ()) { String name = (String) it.next (); Argument a = (Argument) args.get (name); String label = translate (a.label ()); char mnemonic = getMnemonic (a.label ()); c = new GridBagConstraints (); c.insets = new Insets (6, 0, 0, 3); c.anchor = GridBagConstraints.WEST; JLabel iLabel = new JLabel (label); iLabel.setDisplayedMnemonic (mnemonic); add (iLabel, c); JTextField tfParam = new JTextField (a.value ()); iLabel.setLabelFor (tfParam); tfParam.setName (name); tfParam.getAccessibleContext ().setAccessibleDescription ( new MessageFormat (NbBundle.getMessage ( ConnectPanel.class, "ACSD_CTL_Argument" )).format (new Object[] { a.label() }) ); c = new GridBagConstraints (); c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets (6, 3, 0, 0); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; add (tfParam, c); tfParams [i ++] = tfParam; } // // Create an empty panel that resizes vertically so that // other elements have fix height: c = new GridBagConstraints (); c.weighty = 1.0; JPanel p = new JPanel (); p.setPreferredSize (new Dimension (1, 1)); add (p, c); } /** * Refreshes panel with options corresponding to the selected connector type. * This method is called when a user selects new connector type. */ public void actionPerformed (ActionEvent e) { refresh (((JComboBox) e.getSource ()).getSelectedIndex ()); Component w = getParent (); while ( (w != null) && !(w instanceof Window)) w = w.getParent (); if (w != null) ((Window) w).pack (); // ugly hack... return; } public boolean cancel () { return true; } public boolean ok () { int index = cbConnectors.getSelectedIndex (); Connector connector = (Connector) connectors.get (index); Map args = getEditedArgs (tfParams, connector); if (args == null) return true; // CANCEL saveArgs (args, connector); if (connector instanceof AttachingConnector) DebuggerManager.getDebuggerManager ().startDebugging ( DebuggerInfo.create ( AttachingDICookie.ID, new Object [] { AttachingDICookie.create ( (AttachingConnector) connector, args ) } ) ); else if (connector instanceof ListeningConnector) DebuggerManager.getDebuggerManager ().startDebugging ( DebuggerInfo.create ( ListeningDICookie.ID, new Object [] { ListeningDICookie.create ( (ListeningConnector) connector, args ) } ) ); return true; } // private helper methods .................................................. /** * Is hostname unknown? This method resolves if the specified * string means "hostname unknown". * Hostname is considered unknown if: *
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.