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: /*
043: * NewParameterPanel.java
044: *
045: * Created on August 22, 2005, 11:01 AM
046: */
047:
048: package org.netbeans.modules.uml.propertysupport.customizers;
049:
050: import java.awt.Color;
051: import java.util.ResourceBundle;
052: import javax.swing.DefaultComboBoxModel;
053: import org.openide.DialogDescriptor;
054: import org.openide.util.NbBundle;
055:
056: public class NewParameterPanel extends javax.swing.JPanel {
057: private ResourceBundle bundle = NbBundle
058: .getBundle(ParameterCustomizerPanel.class);
059: private DialogDescriptor dd;
060: private DefaultComboBoxModel typeModel = new DefaultComboBoxModel();
061: private Object[] paramList;
062:
063: /** Creates new NewParameterPanel */
064: public NewParameterPanel(DefaultComboBoxModel comboBoxModel,
065: Object[] parameterList) {
066: initComponents();
067: paramList = parameterList;
068: setTypeList(comboBoxModel);
069: name.setColumns(25);
070: name.getDocument().addDocumentListener(
071: new javax.swing.event.DocumentListener() {
072: public void insertUpdate(
073: javax.swing.event.DocumentEvent e) {
074: nameChanged();
075: }
076:
077: public void removeUpdate(
078: javax.swing.event.DocumentEvent e) {
079: nameChanged();
080: }
081:
082: public void changedUpdate(
083: javax.swing.event.DocumentEvent e) {
084: nameChanged();
085: }
086:
087: });
088:
089: // set message color
090: Color c = javax.swing.UIManager.getColor("nb.errorForeground"); //NOI18N
091: if (c == null) {
092: c = new Color(89, 79, 191);
093: }
094: messageArea.setForeground(c);
095: messageArea.setBackground(this .getBackground());
096: }
097:
098: public void setTypeList(DefaultComboBoxModel comboBoxModel) {
099: if (comboBoxModel != null) {
100: typeModel = comboBoxModel;
101: type.setModel(typeModel);
102: }
103: }
104:
105: public void setDialogDescriptor(DialogDescriptor dd) {
106: this .dd = dd;
107: }
108:
109: public String getParamType() {
110: return (String) type.getSelectedItem();
111: }
112:
113: public String getParamName() {
114: return name.getText();
115: }
116:
117: private void nameChanged() {
118: String paramName = getParamName().trim();
119: boolean valid = true;
120: String message = "";
121: if (paramName == null || paramName.length() == 0) {
122: message = NbBundle.getMessage(NewParameterPanel.class,
123: "MSG_EMTPY_NAME");
124: valid = false;
125: } else {
126: // validate the name to make sure it is unique
127: ElementData elem = null;
128: if (paramList != null) {
129: for (int i = 0; i < paramList.length; i++) {
130: elem = (ElementData) paramList[i];
131: if (elem.getName().equals(paramName)) {
132: valid = false;
133: message = NbBundle.getMessage(
134: NewParameterPanel.class,
135: "MSG_DUPLICATE", paramName);
136: break;
137: }
138: }
139: }
140: }
141:
142: // enable/disable the OK button
143: if (dd != null) {
144: dd.setValid(valid);
145: }
146: messageArea.setText(message);
147: }
148:
149: /** This method is called from within the constructor to
150: * initialize the form.
151: * WARNING: Do NOT modify this code. The content of this method is
152: * always regenerated by the Form Editor.
153: */
154: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
155: private void initComponents() {
156: java.awt.GridBagConstraints gridBagConstraints;
157:
158: nameLabel = new javax.swing.JLabel();
159: name = new javax.swing.JTextField();
160: typeLabel = new javax.swing.JLabel();
161: type = new javax.swing.JComboBox();
162: messageArea = new javax.swing.JTextArea();
163:
164: setLayout(new java.awt.GridBagLayout());
165:
166: nameLabel.setLabelFor(name);
167: org.openide.awt.Mnemonics.setLocalizedText(nameLabel,
168: org.openide.util.NbBundle.getBundle(
169: NewParameterPanel.class).getString("LBL_NAME"));
170: gridBagConstraints = new java.awt.GridBagConstraints();
171: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
173: gridBagConstraints.insets = new java.awt.Insets(10, 5, 5, 0);
174: add(nameLabel, gridBagConstraints);
175: nameLabel.getAccessibleContext().setAccessibleName(
176: bundle.getString("LBL_NAME"));
177: nameLabel.getAccessibleContext().setAccessibleDescription(
178: bundle.getString("ACSN_NAME"));
179:
180: gridBagConstraints = new java.awt.GridBagConstraints();
181: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
183: gridBagConstraints.weightx = 0.8;
184: gridBagConstraints.insets = new java.awt.Insets(10, 5, 5, 5);
185: add(name, gridBagConstraints);
186: name.getAccessibleContext().setAccessibleName(
187: bundle.getString("ACSN_NAME"));
188: name.getAccessibleContext().setAccessibleDescription(
189: bundle.getString("ACSN_NAME"));
190:
191: typeLabel.setLabelFor(type);
192: org.openide.awt.Mnemonics.setLocalizedText(typeLabel,
193: org.openide.util.NbBundle.getBundle(
194: NewParameterPanel.class).getString("LBL_TYPE"));
195: gridBagConstraints = new java.awt.GridBagConstraints();
196: gridBagConstraints.gridx = 0;
197: gridBagConstraints.gridy = 1;
198: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
199: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
200: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
201: add(typeLabel, gridBagConstraints);
202: typeLabel.getAccessibleContext().setAccessibleName(
203: bundle.getString("LBL_TYPE"));
204: typeLabel.getAccessibleContext().setAccessibleDescription(
205: bundle.getString("ACSN_TYPE"));
206:
207: type.setEditable(true);
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridx = 1;
210: gridBagConstraints.gridy = 1;
211: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
213: gridBagConstraints.weightx = 0.8;
214: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
215: add(type, gridBagConstraints);
216: type.getAccessibleContext().setAccessibleName(
217: bundle.getString("ACSN_TYPE"));
218: type.getAccessibleContext().setAccessibleDescription(
219: bundle.getString("ACSN_TYPE"));
220:
221: messageArea.setBackground(new java.awt.Color(212, 208, 200));
222: messageArea.setEditable(false);
223: messageArea.setLineWrap(true);
224: messageArea.setRows(1);
225: messageArea.setWrapStyleWord(true);
226: gridBagConstraints = new java.awt.GridBagConstraints();
227: gridBagConstraints.gridx = 0;
228: gridBagConstraints.gridy = 2;
229: gridBagConstraints.gridwidth = 2;
230: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
231: gridBagConstraints.weightx = 1.0;
232: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
233: add(messageArea, gridBagConstraints);
234:
235: }// </editor-fold>//GEN-END:initComponents
236:
237: // Variables declaration - do not modify//GEN-BEGIN:variables
238: private javax.swing.JTextArea messageArea;
239: private javax.swing.JTextField name;
240: private javax.swing.JLabel nameLabel;
241: private javax.swing.JComboBox type;
242: private javax.swing.JLabel typeLabel;
243: // End of variables declaration//GEN-END:variables
244:
245: }
|