KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > dlg > LabeledTextFieldDialog


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.db.explorer.dlg;
21
22 import java.awt.*;
23 import java.awt.event.*;
24 import java.util.*;
25 import javax.swing.*;
26 import org.openide.util.NbBundle;
27 import javax.swing.border.EmptyBorder JavaDoc;
28 import org.openide.DialogDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.netbeans.modules.db.explorer.*;
31 import org.openide.awt.Mnemonics;
32
33 /**
34 * @author Slavek Psenicka
35 */

36 public class LabeledTextFieldDialog {
37     boolean result = false;
38     Dialog dialog = null;
39     Object JavaDoc combosel = null;
40     JTextField field;
41     JTextArea notesarea;
42     JButton edButton;
43     JLabel label;
44     final String JavaDoc original_notes;
45     private ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle"); //NOI18N
46

47     public LabeledTextFieldDialog(String JavaDoc notes) {
48         String JavaDoc title = bundle.getString("RecreateTableRenameTable");
49         String JavaDoc lab = bundle.getString("RecreateTableNewName");
50         original_notes = notes;
51         try {
52             JPanel pane = new JPanel();
53             pane.setBorder(new EmptyBorder JavaDoc(new Insets(5,5,5,5)));
54             GridBagLayout layout = new GridBagLayout();
55             GridBagConstraints con = new GridBagConstraints ();
56             pane.setLayout (layout);
57
58             // Title
59

60             label = new JLabel();
61             Mnemonics.setLocalizedText(label, lab);
62             label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_RecreateTableNewNameA11yDesc")); // NOI18N
63
con.anchor = GridBagConstraints.WEST;
64             con.insets = new java.awt.Insets JavaDoc (2, 2, 2, 2);
65             con.gridx = 0;
66             con.gridy = 0;
67             layout.setConstraints(label, con);
68             pane.add(label);
69
70             // Textfield
71

72             con.fill = GridBagConstraints.HORIZONTAL;
73             con.weightx = 1.0;
74             con.gridx = 1;
75             con.gridy = 0;
76             con.insets = new java.awt.Insets JavaDoc (2, 2, 2, 2);
77             field = new JTextField(35);
78             field.getAccessibleContext().setAccessibleName(bundle.getString("ACS_RecreateTableNewNameTextFieldA11yName")); // NOI18N
79
field.setToolTipText(bundle.getString("ACS_RecreateTableNewNameTextFieldA11yDesc")); // NOI18N
80
label.setLabelFor(field);
81             layout.setConstraints(field, con);
82             pane.add(field);
83
84             // Descr.
85

86             JLabel desc = new JLabel();
87             Mnemonics.setLocalizedText(desc, bundle.getString("RecreateTableRenameNotes"));
88             desc.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_RecreateTableRenameNotesA11yDesc")); // NOI18N
89
con.anchor = GridBagConstraints.WEST;
90             con.gridx = 0;
91             con.gridy = 2;
92             con.weighty = 2.0;
93             layout.setConstraints(desc, con);
94             pane.add(desc);
95
96             // Notes
97

98             notesarea = new JTextArea(notes, 10, 50);
99             notesarea.setEditable(false);
100             notesarea.setLineWrap(true);
101             notesarea.setWrapStyleWord(true);
102             notesarea.setFont(label.getFont());
103             notesarea.setBackground(label.getBackground()); // grey
104
notesarea.setEnabled(false);
105             notesarea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground"));
106             notesarea.getAccessibleContext().setAccessibleName(bundle.getString("ACS_RecreateTableTableScriptTextAreaA11yName")); // NOI18N
107
notesarea.setToolTipText(bundle.getString("ACS_RecreateTableTableScriptTextAreaA11yDesc")); // NOI18N
108
desc.setLabelFor(notesarea);
109             con.weightx = 1.0;
110             con.weighty = 1.0;
111             con.gridwidth = 2;
112             con.fill = GridBagConstraints.BOTH;
113             con.insets = new java.awt.Insets JavaDoc (10, 0, 0, 0);
114             con.gridx = 0;
115             con.gridy = 3;
116             notesarea.setBorder(new EmptyBorder JavaDoc(new Insets(5,5,5,5)));
117             JScrollPane spane = new JScrollPane(notesarea);
118             layout.setConstraints(spane, con);
119             pane.add(spane);
120             
121             // edit button
122
edButton = new JButton();
123             Mnemonics.setLocalizedText(edButton, bundle.getString("EditCommand")); // NOI18N
124
edButton.setToolTipText(bundle.getString("ACS_EditCommandA11yDesc")); // NOI18N
125
con.fill = GridBagConstraints.WEST;
126             con.weighty = 0.0;
127             con.weightx = 0.0;
128             con.gridx = 0;
129             con.gridy = 5;
130             layout.setConstraints(edButton, con);
131             pane.add(edButton);
132
133             edButton.addActionListener(new ActionListener() {
134                 public void actionPerformed(ActionEvent event) {
135                     if(edButton.getText().startsWith(bundle.getString("EditCommand"))) { // NOI18N
136
// set to edit
137
Mnemonics.setLocalizedText(edButton, bundle.getString("ReloadCommand"));
138                         edButton.setToolTipText(bundle.getString("ACS_ReloadCommandA11yDesc")); // NOI18N
139
notesarea.setEditable( true );
140                         notesarea.setEnabled(true);
141                         notesarea.setBackground(field.getBackground()); // white
142
notesarea.requestFocus();
143                         field.setEditable( false );
144                         field.setBackground(label.getBackground()); // grey
145
} else {
146                         // reload script from file
147
Mnemonics.setLocalizedText(edButton, bundle.getString("EditCommand"));
148                         edButton.setToolTipText(bundle.getString("ACS_EditCommandA11yDesc")); // NOI18N
149
notesarea.setText(original_notes);
150                         notesarea.setEditable( false );
151                         notesarea.setEnabled(false);
152                         notesarea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground"));
153                         field.setEditable( true );
154                         field.setBackground(notesarea.getBackground()); // grey
155
notesarea.setBackground(label.getBackground()); // white
156
field.requestFocus();
157                     }
158                 }
159             });
160
161             ActionListener listener = new ActionListener() {
162                 public void actionPerformed(ActionEvent event) {
163                     if (event.getSource() == DialogDescriptor.OK_OPTION)
164                         result = true;
165                     else
166                         result = false;;
167                 }
168             };
169
170             pane.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_RecreateTableDialogA11yDesc"));
171
172             DialogDescriptor descriptor = new DialogDescriptor(pane, title, true, listener);
173             dialog = DialogDisplayer.getDefault().createDialog(descriptor);
174             dialog.setResizable(true);
175         } catch (MissingResourceException ex) {
176             ex.printStackTrace();
177         }
178     }
179
180     public boolean run() {
181         if (dialog != null)
182             dialog.setVisible(true);
183         
184         return result;
185     }
186
187     public String JavaDoc getStringValue() {
188         return field.getText();
189     }
190
191     public String JavaDoc getEditedCommand() {
192         return notesarea.getText();
193     }
194
195     public boolean isEditable() {
196         return notesarea.isEditable();
197     }
198
199     public void setStringValue(String JavaDoc val) {
200         field.setText(val);
201     }
202 }
203
Popular Tags