KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > actions > ConnectorPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.ui.actions;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.GridBagConstraints JavaDoc;
24 import java.awt.GridBagLayout JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.Window JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.util.Collections JavaDoc;
30 import java.util.Comparator JavaDoc;
31
32 import java.util.List JavaDoc;
33
34 import javax.swing.JComboBox JavaDoc;
35 import javax.swing.JComponent JavaDoc;
36 import javax.swing.JLabel JavaDoc;
37 import javax.swing.JPanel JavaDoc;
38 import javax.swing.JSeparator JavaDoc;
39 import javax.swing.border.EmptyBorder JavaDoc;
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 JavaDoc implements ActionListener JavaDoc {
52
53     public static final String JavaDoc PROP_TYPE = "type";
54     
55     /** Contains list of AttachType names.*/
56     private JComboBox JavaDoc cbAttachTypes;
57     /** Switches off listenning on cbAttachTypes.*/
58     private boolean doNotListen;
59     /** Contains list of installed AttachTypes.*/
60     private List JavaDoc attachTypes;
61     /** Currentlydisplayed panel.*/
62     private Controller currentPanel;
63     /** Current attach type, which is stored into settings for the next invocation. */
64     private AttachType currentAttachType;
65
66
67     public ConnectorPanel () {
68         getAccessibleContext ().setAccessibleDescription (
69             NbBundle.getMessage (ConnectorPanel.class, "ACSD_ConnectorPanel")
70         );
71         cbAttachTypes = new JComboBox JavaDoc ();
72         cbAttachTypes.getAccessibleContext ().setAccessibleDescription (
73             NbBundle.getMessage (ConnectorPanel.class,
74                 "ACSD_CTL_Connect_through")// NOI18N
75
);
76         attachTypes = DebuggerManager.getDebuggerManager ().lookup (
77             null, AttachType.class
78         );
79         String JavaDoc 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 JavaDoc() {
84             public int compare(Object JavaDoc o1, Object JavaDoc 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!"); // NOI18N
99
cbAttachTypes.addActionListener (this);
100
101         setLayout (new GridBagLayout JavaDoc ());
102         setBorder (new EmptyBorder JavaDoc (11, 11, 0, 10));
103         refresh (defaultIndex);
104     }
105     
106     private void refresh (int index) {
107         JLabel JavaDoc cbLabel = new JLabel JavaDoc();
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")// NOI18N
113
);
114         cbLabel.setLabelFor (cbAttachTypes);
115
116         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc ();
117         c.insets = new Insets JavaDoc (0, 0, 6, 6);
118         add (cbLabel, c);
119         c = new GridBagConstraints JavaDoc ();
120         c.weightx = 1.0;
121         c.fill = java.awt.GridBagConstraints.HORIZONTAL;
122         c.gridwidth = 0;
123         c.insets = new Insets JavaDoc (0, 3, 6, 0);
124         doNotListen = true;
125         cbAttachTypes.setSelectedIndex (index);
126         doNotListen = false;
127         add (cbAttachTypes, c);
128         c.insets = new Insets JavaDoc (0, 0, 6, 0);
129         add (new JSeparator JavaDoc(), c);
130         c = new GridBagConstraints JavaDoc ();
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 JavaDoc 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     /**
145      * Called when a user selects debugger type in a combo-box.
146      */

147     public void actionPerformed (ActionEvent JavaDoc e) {
148         if (doNotListen) return;
149         if (e.getActionCommand ().equals ("SwitchMe!")); // NOI18N
150
removeAll ();
151         refresh (((JComboBox JavaDoc) e.getSource ()).getSelectedIndex ());
152         Component JavaDoc w = getParent ();
153         while (!(w instanceof Window JavaDoc))
154             w = w.getParent ();
155         if (w != null) ((Window JavaDoc) w).pack (); // ugly hack...
156
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 JavaDoc 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