KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormCustomEditorAdvanced


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 package org.netbeans.modules.form;
20
21 import org.openide.awt.Mnemonics;
22
23 /**
24  *
25  * @author Ian Formanek, Vladimir Zboril
26  */

27 public class FormCustomEditorAdvanced extends javax.swing.JPanel JavaDoc {
28
29     static final int DEFAULT_WIDTH = 350;
30     static final int DEFAULT_HEIGHT = 300;
31
32     static final long serialVersionUID =-885210213146017493L;
33
34     /** Creates new form FormCustomEditorAdvanced */
35     public FormCustomEditorAdvanced(String JavaDoc preCode, String JavaDoc postCode) {
36         initComponents();
37         Mnemonics.setLocalizedText(preCheckBox, FormUtils.getBundleString("CTL_GeneratePreInitializationCode")); // NOI18N
38
Mnemonics.setLocalizedText(postCheckBox, FormUtils.getBundleString("CTL_GeneratePostInitializationCode")); // NOI18N
39
preEditorPane.setContentType("text/x-java"); // allow syntax coloring // NOI18N
40
postEditorPane.setContentType("text/x-java"); // allow syntax coloring // NOI18N
41

42         // restore state according to parameters
43
preCheckBox.setSelected(preCode != null);
44         postCheckBox.setSelected(postCode != null);
45
46         // restore current pre/post code, if set
47
if (preCode != null) preEditorPane.setText(preCode);
48         if (postCode != null) postEditorPane.setText(postCode);
49         
50         org.openide.util.HelpCtx.setHelpIDString(this, "gui.source.modifying.property"); // NOI18N
51

52         preEditorPane.setEnabled(preCode != null);
53         postEditorPane.setEnabled(postCode != null);
54         
55         // cursors (carets) must be hidden explicitely in some situations
56
preEditorPane.getCaret().setVisible(preCheckBox.isSelected() && preEditorPane.hasFocus());
57         postEditorPane.getCaret().setVisible(postCheckBox.isSelected() && postEditorPane.hasFocus());
58
59         preEditorPane.getAccessibleContext().setAccessibleName(preCheckBox.getText());
60         postEditorPane.getAccessibleContext().setAccessibleName(postCheckBox.getText());
61
62         preCheckBox.getAccessibleContext().setAccessibleDescription(
63             FormUtils.getBundleString("ACSD_CTL_GeneratePreInitializationCode")); // NOI18N
64
postCheckBox.getAccessibleContext().setAccessibleDescription(
65             FormUtils.getBundleString("ACSD_CTL_GeneratePostInitializationCode")); // NOI18N
66
preEditorPane.getAccessibleContext().setAccessibleDescription(
67             FormUtils.getBundleString("ACSD_CTL_GeneratePreInitializationCodeArea")); // NOI18N
68
postEditorPane.getAccessibleContext().setAccessibleDescription(
69             FormUtils.getBundleString("ACSD_CTL_GeneratePostInitializationCodeArea")); // NOI18N
70
getAccessibleContext().setAccessibleDescription(
71             FormUtils.getBundleString("ACSD_FormCustomEditorAdvanced")); // NOI18N
72
}
73
74     String JavaDoc getPreCode() {
75         if (!preCheckBox.isSelected()) return null;
76         if ("".equals(preEditorPane.getText())) return null; // NOI18N
77
return preEditorPane.getText();
78     }
79
80     String JavaDoc getPostCode() {
81         if (!postCheckBox.isSelected()) return null;
82         if ("".equals(postEditorPane.getText())) return null; // NOI18N
83
return postEditorPane.getText();
84     }
85
86     public java.awt.Dimension JavaDoc getPreferredSize() {
87         java.awt.Dimension JavaDoc inh = super.getPreferredSize();
88         return new java.awt.Dimension JavaDoc(Math.max(inh.width, DEFAULT_WIDTH), Math.max(inh.height, DEFAULT_HEIGHT));
89     }
90        
91     /** This method is called from within the constructor to
92      * initialize the form.
93      * WARNING: Do NOT modify this code. The content of this method is
94      * always regenerated by the Form Editor.
95      */

96     private void initComponents() {//GEN-BEGIN:initComponents
97
prePanel = new javax.swing.JPanel JavaDoc();
98         preCheckBox = new javax.swing.JCheckBox JavaDoc();
99         preScrollPane = new javax.swing.JScrollPane JavaDoc();
100         preEditorPane = new javax.swing.JEditorPane JavaDoc();
101         postPanel = new javax.swing.JPanel JavaDoc();
102         postCheckBox = new javax.swing.JCheckBox JavaDoc();
103         postScrollPane = new javax.swing.JScrollPane JavaDoc();
104         postEditorPane = new javax.swing.JEditorPane JavaDoc();
105         
106         setLayout(new java.awt.GridBagLayout JavaDoc());
107         java.awt.GridBagConstraints JavaDoc gridBagConstraints1;
108         
109         prePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
110         java.awt.GridBagConstraints JavaDoc gridBagConstraints2;
111         
112         preCheckBox.setText("jCheckBox1");
113         preCheckBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
114             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
115                 preCheckBoxItemStateChanged(evt);
116             }
117         });
118         
119         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
121         gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
122         prePanel.add(preCheckBox, gridBagConstraints2);
123         
124         preScrollPane.setViewportView(preEditorPane);
125         
126         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
127         gridBagConstraints2.gridx = 0;
128         gridBagConstraints2.gridy = 1;
129         gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
130         gridBagConstraints2.gridheight = java.awt.GridBagConstraints.REMAINDER;
131         gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
132         gridBagConstraints2.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
133         gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
134         gridBagConstraints2.weightx = 1.0;
135         gridBagConstraints2.weighty = 1.0;
136         prePanel.add(preScrollPane, gridBagConstraints2);
137         
138         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
139         gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
140         gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
141         gridBagConstraints1.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
142         gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST;
143         gridBagConstraints1.weightx = 1.0;
144         gridBagConstraints1.weighty = 1.0;
145         add(prePanel, gridBagConstraints1);
146         
147         postPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
148         java.awt.GridBagConstraints JavaDoc gridBagConstraints3;
149         
150         postCheckBox.setText("jCheckBox2");
151         postCheckBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
152             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
153                 postCheckBoxItemStateChanged(evt);
154             }
155         });
156         
157         gridBagConstraints3 = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints3.gridwidth = java.awt.GridBagConstraints.REMAINDER;
159         gridBagConstraints3.anchor = java.awt.GridBagConstraints.NORTHWEST;
160         postPanel.add(postCheckBox, gridBagConstraints3);
161         
162         postScrollPane.setViewportView(postEditorPane);
163         
164         gridBagConstraints3 = new java.awt.GridBagConstraints JavaDoc();
165         gridBagConstraints3.gridx = 0;
166         gridBagConstraints3.gridy = 1;
167         gridBagConstraints3.gridwidth = java.awt.GridBagConstraints.REMAINDER;
168         gridBagConstraints3.gridheight = java.awt.GridBagConstraints.REMAINDER;
169         gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
170         gridBagConstraints3.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
171         gridBagConstraints3.anchor = java.awt.GridBagConstraints.NORTHWEST;
172         gridBagConstraints3.weightx = 1.0;
173         gridBagConstraints3.weighty = 1.0;
174         postPanel.add(postScrollPane, gridBagConstraints3);
175         
176         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints1.gridx = 0;
178         gridBagConstraints1.gridy = 1;
179         gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
180         gridBagConstraints1.gridheight = java.awt.GridBagConstraints.REMAINDER;
181         gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
182         gridBagConstraints1.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
183         gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST;
184         gridBagConstraints1.weightx = 1.0;
185         gridBagConstraints1.weighty = 1.0;
186         add(postPanel, gridBagConstraints1);
187         
188     }//GEN-END:initComponents
189

190     private void postCheckBoxItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_postCheckBoxItemStateChanged
191
// Add your handling code here:
192
postEditorPane.setEnabled(postCheckBox.isSelected());
193         if (postCheckBox.isSelected()) {
194             postEditorPane.requestFocus();
195         }
196     }//GEN-LAST:event_postCheckBoxItemStateChanged
197

198     private void preCheckBoxItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_preCheckBoxItemStateChanged
199
// Add your handling code here:
200
preEditorPane.setEnabled(preCheckBox.isSelected());
201         if (preCheckBox.isSelected()) {
202             preEditorPane.requestFocus();
203         }
204     }//GEN-LAST:event_preCheckBoxItemStateChanged
205

206
207     // Variables declaration - do not modify//GEN-BEGIN:variables
208
private javax.swing.JPanel JavaDoc prePanel;
209     private javax.swing.JCheckBox JavaDoc preCheckBox;
210     private javax.swing.JScrollPane JavaDoc preScrollPane;
211     private javax.swing.JEditorPane JavaDoc preEditorPane;
212     private javax.swing.JPanel JavaDoc postPanel;
213     private javax.swing.JCheckBox JavaDoc postCheckBox;
214     private javax.swing.JScrollPane JavaDoc postScrollPane;
215     private javax.swing.JEditorPane JavaDoc postEditorPane;
216     // End of variables declaration//GEN-END:variables
217

218 }
219
Popular Tags