KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > html > palette > items > TEXTAREACustomizer


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.html.palette.items;
21 import java.awt.Dialog JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import javax.swing.JSpinner JavaDoc;
25 import javax.swing.SpinnerNumberModel JavaDoc;
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28 import org.openide.util.NbBundle;
29
30
31
32
33 /**
34  *
35  * @author Libor Kotouc
36  */

37 public class TEXTAREACustomizer extends javax.swing.JPanel JavaDoc {
38     
39     private Dialog JavaDoc dialog = null;
40     private DialogDescriptor descriptor = null;
41     private boolean dialogOK = false;
42
43     TEXTAREA textArea;
44             
45     /**
46      * Creates new form TEXTAREACustomizer
47      */

48     public TEXTAREACustomizer(TEXTAREA textArea) {
49         this.textArea = textArea;
50         
51         initComponents();
52     }
53     
54     public boolean showDialog() {
55         
56         dialogOK = false;
57         
58         String JavaDoc displayName = "";
59         try {
60             displayName = NbBundle.getBundle("org.netbeans.modules.html.palette.items.resources.Bundle").getString("NAME_html-TEXTAREA"); // NOI18N
61
}
62         catch (Exception JavaDoc e) {}
63         
64         descriptor = new DialogDescriptor
65                 (this, NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true,
66                  DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
67                  new ActionListener JavaDoc() {
68                      public void actionPerformed(ActionEvent JavaDoc e) {
69                         if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
70                             evaluateInput();
71                             dialogOK = true;
72                         }
73                         dialog.dispose();
74              }
75          }
76                 );
77         
78         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
79         dialog.setVisible(true);
80         repaint();
81         
82         return dialogOK;
83     }
84     
85     private void evaluateInput() {
86         
87         String JavaDoc name = jTextField1.getText();
88         textArea.setName(name);
89
90         String JavaDoc value = jTextArea1.getText();
91         textArea.setValue(value);
92         
93         textArea.setDisabled(jCheckBox1.isSelected());
94         textArea.setReadonly(jCheckBox2.isSelected());
95         
96         int rows = ((Integer JavaDoc)jSpinner1.getValue()).intValue();
97         textArea.setRows(rows);
98
99         int cols = ((Integer JavaDoc)jSpinner2.getValue()).intValue();
100         textArea.setCols(cols);
101         
102     }
103     
104     /** This method is called from within the constructor to
105      * initialize the form.
106      * WARNING: Do NOT modify this code. The content of this method is
107      * always regenerated by the Form Editor.
108      */

109     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
110
private void initComponents() {
111         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
112
113         jLabel4 = new javax.swing.JLabel JavaDoc();
114         jTextField1 = new javax.swing.JTextField JavaDoc();
115         jLabel1 = new javax.swing.JLabel JavaDoc();
116         jLabel3 = new javax.swing.JLabel JavaDoc();
117         jCheckBox1 = new javax.swing.JCheckBox JavaDoc();
118         jCheckBox2 = new javax.swing.JCheckBox JavaDoc();
119         jLabel5 = new javax.swing.JLabel JavaDoc();
120         jSpinner1 = new javax.swing.JSpinner JavaDoc();
121         jSpinner2 = new javax.swing.JSpinner JavaDoc();
122         jLabel2 = new javax.swing.JLabel JavaDoc();
123         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
124         jTextArea1 = new javax.swing.JTextArea JavaDoc();
125
126         setLayout(new java.awt.GridBagLayout JavaDoc());
127
128         jLabel4.setLabelFor(jSpinner1);
129         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_TEXTAREA_Rows"));
130         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131         gridBagConstraints.gridx = 0;
132         gridBagConstraints.gridy = 4;
133         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
136         add(jLabel4, gridBagConstraints);
137         jLabel4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSN_TEXTAREA_Rows"));
138         jLabel4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSD_TEXTAREA_Rows"));
139
140         jTextField1.setColumns(30);
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 1;
143         gridBagConstraints.gridy = 0;
144         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146         gridBagConstraints.weightx = 1.0;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
148         add(jTextField1, gridBagConstraints);
149
150         jLabel1.setLabelFor(jTextField1);
151         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_TEXTAREA_Name"));
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 0;
154         gridBagConstraints.gridy = 0;
155         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
158         add(jLabel1, gridBagConstraints);
159         jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSN_TEXTAREA_Name"));
160         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSD_TEXTAREA_Name"));
161
162         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_TEXTAREA_State"));
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridx = 0;
165         gridBagConstraints.gridy = 2;
166         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
167         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
168         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
169         add(jLabel3, gridBagConstraints);
170         jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSN_TEXTAREA_State"));
171         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSD_TEXTAREA_State"));
172
173         org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_TEXTAREA_disabled"));
174         jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
175         jCheckBox1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridx = 1;
178         gridBagConstraints.gridy = 2;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
182         add(jCheckBox1, gridBagConstraints);
183         jCheckBox1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSN_TEXTAREA_disabled"));
184         jCheckBox1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSD_TEXTAREA_disabled"));
185
186         org.openide.awt.Mnemonics.setLocalizedText(jCheckBox2, org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_TEXTAREA_readonly"));
187         jCheckBox2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
188         jCheckBox2.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
189         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
190         gridBagConstraints.gridx = 1;
191         gridBagConstraints.gridy = 3;
192         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
194         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
195         add(jCheckBox2, gridBagConstraints);
196         jCheckBox2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSN_TEXTAREA_readonly"));
197         jCheckBox2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSD_TEXTAREA_readonly"));
198
199         jLabel5.setLabelFor(jSpinner2);
200         org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_TEXTAREA_Columns"));
201         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
202         gridBagConstraints.gridx = 0;
203         gridBagConstraints.gridy = 5;
204         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
206         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 12, 0);
207         add(jLabel5, gridBagConstraints);
208         jLabel5.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSN_TEXTAREA_Columns"));
209         jLabel5.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSD_TEXTAREA_Columns"));
210
211         jSpinner1.setModel(new SpinnerNumberModel JavaDoc(textArea.getRows(), 1, Integer.MAX_VALUE, 1));
212         jSpinner1.setEditor(new JSpinner.NumberEditor JavaDoc(jSpinner1, "#"));
213         jSpinner1.setValue(new Integer JavaDoc(textArea.getRows()));
214         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
215         gridBagConstraints.gridx = 1;
216         gridBagConstraints.gridy = 4;
217         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
218         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
219         add(jSpinner1, gridBagConstraints);
220
221         jSpinner2.setModel(new SpinnerNumberModel JavaDoc(textArea.getCols(), 1, Integer.MAX_VALUE, 1));
222         jSpinner2.setEditor(new JSpinner.NumberEditor JavaDoc(jSpinner2, "#"));
223         jSpinner2.setValue(new Integer JavaDoc(textArea.getCols()));
224         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
225         gridBagConstraints.gridx = 1;
226         gridBagConstraints.gridy = 5;
227         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
228         gridBagConstraints.weightx = 1.0;
229         gridBagConstraints.weighty = 1.0;
230         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 12, 12);
231         add(jSpinner2, gridBagConstraints);
232
233         jLabel2.setLabelFor(jTextArea1);
234         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "LBL_TEXTAREA_Value"));
235         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
236         gridBagConstraints.gridx = 0;
237         gridBagConstraints.gridy = 1;
238         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
239         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
240         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
241         add(jLabel2, gridBagConstraints);
242         jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSN_TEXTAREA_Value"));
243         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TEXTAREACustomizer.class, "ACSD_TEXTAREA_Value"));
244
245         jTextArea1.setColumns(30);
246         jTextArea1.setRows(5);
247         jScrollPane1.setViewportView(jTextArea1);
248
249         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
250         gridBagConstraints.gridx = 1;
251         gridBagConstraints.gridy = 1;
252         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
253         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
254         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
255         add(jScrollPane1, gridBagConstraints);
256
257     }// </editor-fold>//GEN-END:initComponents
258

259     
260     // Variables declaration - do not modify//GEN-BEGIN:variables
261
private javax.swing.JCheckBox JavaDoc jCheckBox1;
262     private javax.swing.JCheckBox JavaDoc jCheckBox2;
263     private javax.swing.JLabel JavaDoc jLabel1;
264     private javax.swing.JLabel JavaDoc jLabel2;
265     private javax.swing.JLabel JavaDoc jLabel3;
266     private javax.swing.JLabel JavaDoc jLabel4;
267     private javax.swing.JLabel JavaDoc jLabel5;
268     private javax.swing.JScrollPane JavaDoc jScrollPane1;
269     private javax.swing.JSpinner JavaDoc jSpinner1;
270     private javax.swing.JSpinner JavaDoc jSpinner2;
271     private javax.swing.JTextArea JavaDoc jTextArea1;
272     private javax.swing.JTextField JavaDoc jTextField1;
273     // End of variables declaration//GEN-END:variables
274

275 }
276
Popular Tags