001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.db.explorer.dlg;
043:
044: import java.awt.*;
045: import java.awt.event.*;
046: import java.util.*;
047: import javax.swing.*;
048: import org.openide.util.NbBundle;
049: import javax.swing.border.EmptyBorder;
050: import org.openide.DialogDescriptor;
051: import org.openide.DialogDisplayer;
052: import org.netbeans.modules.db.explorer.*;
053: import org.openide.awt.Mnemonics;
054:
055: /**
056: * @author Slavek Psenicka
057: */
058: public class LabeledTextFieldDialog {
059: boolean result = false;
060: Dialog dialog = null;
061: Object combosel = null;
062: JTextField field;
063: JTextArea notesarea;
064: JButton edButton;
065: JLabel label;
066: final String original_notes;
067: private ResourceBundle bundle = NbBundle
068: .getBundle("org.netbeans.modules.db.resources.Bundle"); //NOI18N
069:
070: public LabeledTextFieldDialog(String notes) {
071: String title = bundle.getString("RecreateTableRenameTable");
072: String lab = bundle.getString("RecreateTableNewName");
073: original_notes = notes;
074: try {
075: JPanel pane = new JPanel();
076: pane.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
077: GridBagLayout layout = new GridBagLayout();
078: GridBagConstraints con = new GridBagConstraints();
079: pane.setLayout(layout);
080:
081: // Title
082:
083: label = new JLabel();
084: Mnemonics.setLocalizedText(label, lab);
085: label
086: .getAccessibleContext()
087: .setAccessibleDescription(
088: bundle
089: .getString("ACS_RecreateTableNewNameA11yDesc")); // NOI18N
090: con.anchor = GridBagConstraints.WEST;
091: con.insets = new java.awt.Insets(2, 2, 2, 2);
092: con.gridx = 0;
093: con.gridy = 0;
094: layout.setConstraints(label, con);
095: pane.add(label);
096:
097: // Textfield
098:
099: con.fill = GridBagConstraints.HORIZONTAL;
100: con.weightx = 1.0;
101: con.gridx = 1;
102: con.gridy = 0;
103: con.insets = new java.awt.Insets(2, 2, 2, 2);
104: field = new JTextField(35);
105: field
106: .getAccessibleContext()
107: .setAccessibleName(
108: bundle
109: .getString("ACS_RecreateTableNewNameTextFieldA11yName")); // NOI18N
110: field
111: .setToolTipText(bundle
112: .getString("ACS_RecreateTableNewNameTextFieldA11yDesc")); // NOI18N
113: label.setLabelFor(field);
114: layout.setConstraints(field, con);
115: pane.add(field);
116:
117: // Descr.
118:
119: JLabel desc = new JLabel();
120: Mnemonics.setLocalizedText(desc, bundle
121: .getString("RecreateTableRenameNotes"));
122: desc
123: .getAccessibleContext()
124: .setAccessibleDescription(
125: bundle
126: .getString("ACS_RecreateTableRenameNotesA11yDesc")); // NOI18N
127: con.anchor = GridBagConstraints.WEST;
128: con.gridx = 0;
129: con.gridy = 2;
130: con.weighty = 2.0;
131: layout.setConstraints(desc, con);
132: pane.add(desc);
133:
134: // Notes
135:
136: notesarea = new JTextArea(notes, 10, 50);
137: notesarea.setEditable(false);
138: notesarea.setLineWrap(true);
139: notesarea.setWrapStyleWord(true);
140: notesarea.setFont(label.getFont());
141: notesarea.setBackground(label.getBackground()); // grey
142: notesarea.setEnabled(false);
143: notesarea.setDisabledTextColor(javax.swing.UIManager
144: .getColor("Label.foreground"));
145: notesarea
146: .getAccessibleContext()
147: .setAccessibleName(
148: bundle
149: .getString("ACS_RecreateTableTableScriptTextAreaA11yName")); // NOI18N
150: notesarea
151: .setToolTipText(bundle
152: .getString("ACS_RecreateTableTableScriptTextAreaA11yDesc")); // NOI18N
153: desc.setLabelFor(notesarea);
154: con.weightx = 1.0;
155: con.weighty = 1.0;
156: con.gridwidth = 2;
157: con.fill = GridBagConstraints.BOTH;
158: con.insets = new java.awt.Insets(10, 0, 0, 0);
159: con.gridx = 0;
160: con.gridy = 3;
161: notesarea
162: .setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
163: JScrollPane spane = new JScrollPane(notesarea);
164: layout.setConstraints(spane, con);
165: pane.add(spane);
166:
167: // edit button
168: edButton = new JButton();
169: Mnemonics.setLocalizedText(edButton, bundle
170: .getString("EditCommand")); // NOI18N
171: edButton.setToolTipText(bundle
172: .getString("ACS_EditCommandA11yDesc")); // NOI18N
173: con.fill = GridBagConstraints.WEST;
174: con.weighty = 0.0;
175: con.weightx = 0.0;
176: con.gridx = 0;
177: con.gridy = 5;
178: layout.setConstraints(edButton, con);
179: pane.add(edButton);
180:
181: edButton.addActionListener(new ActionListener() {
182: private boolean noedit = true;
183:
184: public void actionPerformed(ActionEvent event) {
185: if (noedit) { // NOI18N
186: // set to edit
187: noedit = false;
188: Mnemonics.setLocalizedText(edButton, bundle
189: .getString("ReloadCommand"));
190: edButton
191: .setToolTipText(bundle
192: .getString("ACS_ReloadCommandA11yDesc")); // NOI18N
193: notesarea.setEditable(true);
194: notesarea.setEnabled(true);
195: notesarea.setBackground(field.getBackground()); // white
196: notesarea.requestFocus();
197: field.setEditable(false);
198: field.setBackground(label.getBackground()); // grey
199: } else {
200: // reload script from file
201: noedit = true;
202: Mnemonics.setLocalizedText(edButton, bundle
203: .getString("EditCommand"));
204: edButton.setToolTipText(bundle
205: .getString("ACS_EditCommandA11yDesc")); // NOI18N
206: notesarea.setText(original_notes);
207: notesarea.setEditable(false);
208: notesarea.setEnabled(false);
209: notesarea
210: .setDisabledTextColor(javax.swing.UIManager
211: .getColor("Label.foreground"));
212: field.setEditable(true);
213: field.setBackground(notesarea.getBackground()); // grey
214: notesarea.setBackground(label.getBackground()); // white
215: field.requestFocus();
216: }
217: }
218: });
219:
220: ActionListener listener = new ActionListener() {
221: public void actionPerformed(ActionEvent event) {
222: if (event.getSource() == DialogDescriptor.OK_OPTION)
223: result = true;
224: else
225: result = false;
226: ;
227: }
228: };
229:
230: pane
231: .getAccessibleContext()
232: .setAccessibleDescription(
233: bundle
234: .getString("ACS_RecreateTableDialogA11yDesc"));
235:
236: DialogDescriptor descriptor = new DialogDescriptor(pane,
237: title, true, listener);
238: dialog = DialogDisplayer.getDefault().createDialog(
239: descriptor);
240: dialog.setResizable(true);
241: } catch (MissingResourceException ex) {
242: ex.printStackTrace();
243: }
244: }
245:
246: public boolean run() {
247: if (dialog != null)
248: dialog.setVisible(true);
249:
250: return result;
251: }
252:
253: public String getStringValue() {
254: return field.getText();
255: }
256:
257: public String getEditedCommand() {
258: return notesarea.getText();
259: }
260:
261: public boolean isEditable() {
262: return notesarea.isEditable();
263: }
264:
265: public void setStringValue(String val) {
266: field.setText(val);
267: }
268: }
|