KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > WatchPanel


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 package org.netbeans.modules.debugger.ui;
20
21 import org.openide.awt.Mnemonics;
22 import org.openide.util.NbBundle;
23
24 import javax.swing.*;
25 import javax.swing.border.EmptyBorder JavaDoc;
26 import javax.swing.border.CompoundBorder JavaDoc;
27 import java.util.*;
28 import java.awt.BorderLayout JavaDoc;
29
30 /**
31  * A GUI panel for customizing a Watch.
32  *
33  * @author Maros Sandor
34  */

35 public class WatchPanel {
36
37     private JPanel panel;
38     private JTextField textField;
39     private String JavaDoc expression;
40
41     public WatchPanel(String JavaDoc expression) {
42         this.expression = expression;
43     }
44
45     public JComponent getPanel() {
46         if (panel != null) return panel;
47
48         panel = new JPanel();
49         ResourceBundle bundle = NbBundle.getBundle(WatchPanel.class);
50
51         panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); // NOI18N
52
JLabel textLabel = new JLabel();
53         Mnemonics.setLocalizedText(textLabel, bundle.getString ("CTL_Watch_Name")); // NOI18N
54
textLabel.setBorder (new EmptyBorder JavaDoc (0, 0, 0, 10));
55         panel.setLayout (new BorderLayout JavaDoc ());
56         panel.setBorder (new EmptyBorder JavaDoc (11, 12, 1, 11));
57         panel.add ("West", textLabel); // NOI18N
58
panel.add ("Center", textField = new JTextField (25)); // NOI18N
59
textField.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N
60
textField.setBorder (
61             new CompoundBorder JavaDoc (textField.getBorder (),
62             new EmptyBorder JavaDoc (2, 0, 2, 0))
63         );
64         String JavaDoc t = Utils.getIdentifier ();
65         if (t != null) {
66             textField.setText (t);
67         } else {
68             textField.setText (expression);
69         }
70         textField.selectAll ();
71
72         textLabel.setLabelFor (textField);
73         textField.requestFocus ();
74         return panel;
75     }
76
77     public String JavaDoc getExpression() {
78         return textField.getText().trim();
79     }
80 }
81
Popular Tags