1 19 20 package org.netbeans.modules.debugger.ui.actions; 21 22 import java.awt.Component ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.GridBagLayout ; 25 import java.awt.Insets ; 26 import java.awt.Window ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.util.Collections ; 30 import java.util.Comparator ; 31 32 import java.util.List ; 33 34 import javax.swing.JComboBox ; 35 import javax.swing.JComponent ; 36 import javax.swing.JLabel ; 37 import javax.swing.JPanel ; 38 import javax.swing.JSeparator ; 39 import javax.swing.border.EmptyBorder ; 40 41 import org.netbeans.api.debugger.DebuggerManager; 42 import org.netbeans.api.debugger.Properties; 43 44 import org.netbeans.spi.debugger.ui.AttachType; 45 import org.netbeans.spi.debugger.ui.Controller; 46 import org.openide.awt.Mnemonics; 47 48 import org.openide.util.NbBundle; 49 50 51 public class ConnectorPanel extends JPanel implements ActionListener { 52 53 public static final String PROP_TYPE = "type"; 54 55 56 private JComboBox cbAttachTypes; 57 58 private boolean doNotListen; 59 60 private List attachTypes; 61 62 private Controller currentPanel; 63 64 private AttachType currentAttachType; 65 66 67 public ConnectorPanel () { 68 getAccessibleContext ().setAccessibleDescription ( 69 NbBundle.getMessage (ConnectorPanel.class, "ACSD_ConnectorPanel") 70 ); 71 cbAttachTypes = new JComboBox (); 72 cbAttachTypes.getAccessibleContext ().setAccessibleDescription ( 73 NbBundle.getMessage (ConnectorPanel.class, 74 "ACSD_CTL_Connect_through") ); 76 attachTypes = DebuggerManager.getDebuggerManager ().lookup ( 77 null, AttachType.class 78 ); 79 String defaultAttachTypeName = 80 Properties.getDefault ().getProperties ("debugger").getString ("last_attach_type", null); 81 int defaultIndex = 0; 82 int i, k = attachTypes.size (); 83 Collections.sort(attachTypes, new Comparator () { 84 public int compare(Object o1, Object o2) { 85 if (!(o1 instanceof AttachType) || !(o2 instanceof AttachType)) return 0; 86 return ((AttachType) o1).getTypeDisplayName().compareTo(((AttachType) o2).getTypeDisplayName()); 87 } 88 }); 89 for (i = 0; i < k; i++) { 90 AttachType at = (AttachType) attachTypes.get (i); 91 cbAttachTypes.addItem (at.getTypeDisplayName ()); 92 if ( (defaultAttachTypeName != null) && 93 (defaultAttachTypeName.equals (at.getClass ().getName ())) 94 ) 95 defaultIndex = i; 96 } 97 98 cbAttachTypes.setActionCommand ("SwitchMe!"); cbAttachTypes.addActionListener (this); 100 101 setLayout (new GridBagLayout ()); 102 setBorder (new EmptyBorder (11, 11, 0, 10)); 103 refresh (defaultIndex); 104 } 105 106 private void refresh (int index) { 107 JLabel cbLabel = new JLabel (); 108 Mnemonics.setLocalizedText(cbLabel, 109 NbBundle.getMessage (ConnectorPanel.class, "CTL_Connect_through")); 110 cbLabel.getAccessibleContext ().setAccessibleDescription ( 111 NbBundle.getMessage (ConnectorPanel.class, 112 "ACSD_CTL_Connect_through") ); 114 cbLabel.setLabelFor (cbAttachTypes); 115 116 GridBagConstraints c = new GridBagConstraints (); 117 c.insets = new Insets (0, 0, 6, 6); 118 add (cbLabel, c); 119 c = new GridBagConstraints (); 120 c.weightx = 1.0; 121 c.fill = java.awt.GridBagConstraints.HORIZONTAL; 122 c.gridwidth = 0; 123 c.insets = new Insets (0, 3, 6, 0); 124 doNotListen = true; 125 cbAttachTypes.setSelectedIndex (index); 126 doNotListen = false; 127 add (cbAttachTypes, c); 128 c.insets = new Insets (0, 0, 6, 0); 129 add (new JSeparator (), c); 130 c = new GridBagConstraints (); 131 c.weightx = 1.0; 132 c.weighty = 1.0; 133 c.fill = java.awt.GridBagConstraints.BOTH; 134 c.gridwidth = 0; 135 AttachType attachType = (AttachType) attachTypes.get (index); 136 JComponent customizer = attachType.getCustomizer (); 137 currentPanel = (Controller) customizer; 138 firePropertyChange(PROP_TYPE, null, customizer); 139 this.currentAttachType = attachType; 140 add (customizer, c); 141 } 142 143 144 147 public void actionPerformed (ActionEvent e) { 148 if (doNotListen) return; 149 if (e.getActionCommand ().equals ("SwitchMe!")); removeAll (); 151 refresh (((JComboBox ) e.getSource ()).getSelectedIndex ()); 152 Component w = getParent (); 153 while (!(w instanceof Window )) 154 w = w.getParent (); 155 if (w != null) ((Window ) w).pack (); return; 157 } 158 159 Controller getController() { 160 return currentPanel; 161 } 162 163 public boolean cancel () { 164 return currentPanel.cancel (); 165 } 166 167 public boolean ok () { 168 String defaultAttachTypeName = currentAttachType.getClass().getName(); 169 Properties.getDefault().getProperties("debugger").setString("last_attach_type", defaultAttachTypeName); 170 return currentPanel.ok (); 171 } 172 } 173 174 175 176 | Popular Tags |