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-2007 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: * CodeClipParametersDialog.java
043: *
044: * Created on July 27, 2006, 10:16 AM
045: *
046: * The dialog box for codclip parameters
047: *
048: * @author jhoff & octav
049: * @author Joelle Lam <joelle.lam@sun.com>
050: * @version %I%, %G%
051: */
052: package org.netbeans.modules.visualweb.palette.codeclips;
053:
054: import java.awt.*;
055: import java.awt.event.*;
056: import java.util.*;
057: import javax.swing.*;
058: import javax.swing.event.DocumentEvent;
059: import javax.swing.event.DocumentListener;
060: import org.openide.NotifyDescriptor;
061:
062: import org.openide.util.NbBundle;
063: import org.openide.NotifyDescriptor;
064: import org.openide.DialogDisplayer;
065: import org.openide.DialogDescriptor;
066:
067: public class CodeClipsParametersDialog extends JPanel {
068:
069: /** UI properties
070: */
071: /** ToDo - remove this restriction and make newParam/paramArray Vectors
072: */
073: //private final int MAX_PARAMS = 3;
074: private boolean cancelled = false;
075: private java.awt.Dialog dialog;
076: private DialogDescriptor dlg;
077: private java.awt.GridBagConstraints gbc;
078: private Vector<String> newParam = new Vector<String>();
079: private Vector<String> paramArr = new Vector<String>();
080: private ArrayList<JTextField> list = new ArrayList<JTextField>();
081: private Component[] components;
082:
083: /** Creates new form CodeClipsParameters */
084: public CodeClipsParametersDialog(String clipName,
085: Vector<String> paramArray) {
086:
087: //this.paramArray = paramArray;
088: this .paramArr = paramArray;
089: init();
090: ActionListener listener = new ActionListener() {
091: public void actionPerformed(ActionEvent evt) {
092: Object o = evt.getSource();
093: if (o == NotifyDescriptor.CANCEL_OPTION) {
094: cancelled = true;
095:
096: } else if (o == NotifyDescriptor.OK_OPTION) {
097: for (int i = 0; i < list.size(); i++) {
098: String str = ((JTextField) list.get(i))
099: .getText();
100: newParam.add(str);
101: }
102:
103: // warnOnEmptyString(newParam.elementAt(0).toString());
104: }
105: }
106: };
107:
108: String title = NbBundle.getMessage(
109: CodeClipsParametersDialog.class, "PARAMETERS")
110: + " <" + clipName + ">"; // NOI18N
111: dlg = new DialogDescriptor(this , title, true, listener);
112: // disable "Ok" button until user changes the old string
113: dlg.setValid(true);
114:
115: dialog = DialogDisplayer.getDefault().createDialog(dlg);
116: dialog.setVisible(true);
117: getAccessibleContext().setAccessibleName(title);
118: getAccessibleContext()
119: .setAccessibleDescription(
120: NbBundle
121: .getMessage(
122: CodeClipsParametersDialog.class,
123: "ACSD_NavigationView_CodeClipsParametersDialogDesc"));
124:
125: }
126:
127: /**
128: *
129: */
130: private void init() {
131: final JPanel panel = new JPanel();
132: final JPanel panel2 = new JPanel();
133: setLayout(new java.awt.GridBagLayout());
134: panel2.setLayout(new java.awt.GridLayout(1, 0, 5, 0));
135: gbc = new java.awt.GridBagConstraints();
136: panel.setLayout(new java.awt.GridBagLayout());
137: gbc = new java.awt.GridBagConstraints();
138: gbc.insets = new Insets(2, 2, 2, 2);
139: int number = paramArr.size();
140: addComponents(number, panel, gbc);
141: add(panel, gbc);
142: add(panel2, gbc);
143: setVisible(true);
144: setLocation(200, 200);
145: components = panel.getComponents();
146: // setPreferredSize(new java.awt.Dimension(WIDTH, HEIGHT));
147: }
148:
149: private void addComponents(int n, JPanel panel,
150: GridBagConstraints gbc) {
151: for (int i = 0; i < n; i++) {
152: JLabel label = new JLabel(paramArr.elementAt(i).replace(
153: "_", " "));
154: // JTextField tf = new JTextField(paramArr.elementAt(i), 16);
155: JTextField tf = new JTextField("", 16);
156: tf.getAccessibleContext().setAccessibleName(
157: NbBundle.getMessage(
158: CodeClipsParametersDialog.class,
159: "ACSD_ParameterName")
160: + paramArr.elementAt(i));
161: tf.getAccessibleContext().setAccessibleDescription(
162: NbBundle.getMessage(
163: CodeClipsParametersDialog.class,
164: "ACSD_ParameterDesc")
165: + paramArr.elementAt(i));
166: gbc.gridwidth = gbc.RELATIVE;
167: gbc.anchor = gbc.EAST;
168: gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
169: panel.add(label, gbc);
170: gbc.gridwidth = gbc.REMAINDER;
171: gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
172: gbc.anchor = gbc.WEST;
173: gbc.weightx = 1.0;
174: //gbc.insets = new java.awt.Insets(10,0,0,10);
175: panel.add(tf, gbc);
176: list.add(tf);
177: panel.revalidate();
178: panel.repaint();
179: }
180: }
181:
182: public boolean isCancelled() {
183: return cancelled;
184: }
185:
186: /**
187: * @return The array of params edited, some of the entries can be null or ""
188: */
189: public Vector getNewParam() {
190: return newParam;
191: }
192:
193: private void warnOnEmptyString(String name) {
194: if ("".equals(name)) {
195: NotifyDescriptor d = new NotifyDescriptor.Message(NbBundle
196: .getMessage(CodeClipsParametersDialog.class,
197: "NO_EMPTY_STRING"), // NOI18N
198: NotifyDescriptor.ERROR_MESSAGE);
199: DialogDisplayer.getDefault().notify(d);
200: }
201: }
202:
203: private class ParamNameChangeListener implements DocumentListener {
204:
205: public void insertUpdate(DocumentEvent e) {
206: enableOkButton();
207: }
208:
209: public void removeUpdate(DocumentEvent e) {
210: enableOkButton();
211: }
212:
213: public void changedUpdate(DocumentEvent e) {
214: enableOkButton();
215: }
216:
217: public void enableOkButton() {
218: dlg.setValid(true);
219: }
220: }
221: }
|