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: /*
043: * FormCustomEditorAdvanced.java
044: *
045: * Created on February 26, 2001, 1:06 PM
046: */
047:
048: package org.netbeans.modules.form;
049:
050: /**
051: *
052: * @author Ian Formanek, Vladimir Zboril
053: */
054: public class FormCustomEditorAdvanced extends javax.swing.JPanel {
055:
056: static final int DEFAULT_WIDTH = 350;
057: static final int DEFAULT_HEIGHT = 300;
058:
059: static final long serialVersionUID = -885210213146017493L;
060:
061: /** Creates new form FormCustomEditorAdvanced */
062: public FormCustomEditorAdvanced(String preCode, String postCode) {
063: initComponents();
064: preCheckBox.setText(FormUtils
065: .getBundleString("CTL_GeneratePreInitializationCode")); // NOI18N
066: postCheckBox.setText(FormUtils
067: .getBundleString("CTL_GeneratePostInitializationCode")); // NOI18N
068: preCheckBox.setMnemonic(FormUtils.getBundleString(
069: "CTL_GeneratePreInitializationCode_Mnemonic") // NOI18N
070: .charAt(0));
071: postCheckBox.setMnemonic(FormUtils.getBundleString(
072: "CTL_GeneratePostInitializationCode_Mnemonic") // NOI18N
073: .charAt(0));
074: preEditorPane.setContentType("text/x-java"); // allow syntax coloring // NOI18N
075: postEditorPane.setContentType("text/x-java"); // allow syntax coloring // NOI18N
076:
077: // restore state according to parameters
078: preCheckBox.setSelected(preCode != null);
079: postCheckBox.setSelected(postCode != null);
080:
081: // restore current pre/post code, if set
082: if (preCode != null)
083: preEditorPane.setText(preCode);
084: if (postCode != null)
085: postEditorPane.setText(postCode);
086:
087: org.openide.util.HelpCtx.setHelpIDString(this ,
088: "gui.source.modifying.property"); // NOI18N
089:
090: preEditorPane.setEnabled(preCode != null);
091: postEditorPane.setEnabled(postCode != null);
092:
093: // cursors (carets) must be hidden explicitely in some situations
094: preEditorPane.getCaret().setVisible(
095: preCheckBox.isSelected() && preEditorPane.hasFocus());
096: postEditorPane.getCaret().setVisible(
097: postCheckBox.isSelected() && postEditorPane.hasFocus());
098:
099: preEditorPane.getAccessibleContext().setAccessibleName(
100: preCheckBox.getText());
101: postEditorPane.getAccessibleContext().setAccessibleName(
102: postCheckBox.getText());
103:
104: preCheckBox
105: .getAccessibleContext()
106: .setAccessibleDescription(
107: FormUtils
108: .getBundleString("ACSD_CTL_GeneratePreInitializationCode")); // NOI18N
109: postCheckBox
110: .getAccessibleContext()
111: .setAccessibleDescription(
112: FormUtils
113: .getBundleString("ACSD_CTL_GeneratePostInitializationCode")); // NOI18N
114: preEditorPane
115: .getAccessibleContext()
116: .setAccessibleDescription(
117: FormUtils
118: .getBundleString("ACSD_CTL_GeneratePreInitializationCodeArea")); // NOI18N
119: postEditorPane
120: .getAccessibleContext()
121: .setAccessibleDescription(
122: FormUtils
123: .getBundleString("ACSD_CTL_GeneratePostInitializationCodeArea")); // NOI18N
124: getAccessibleContext()
125: .setAccessibleDescription(
126: FormUtils
127: .getBundleString("ACSD_FormCustomEditorAdvanced")); // NOI18N
128: }
129:
130: String getPreCode() {
131: if (!preCheckBox.isSelected())
132: return null;
133: if ("".equals(preEditorPane.getText()))
134: return null; // NOI18N
135: return preEditorPane.getText();
136: }
137:
138: String getPostCode() {
139: if (!postCheckBox.isSelected())
140: return null;
141: if ("".equals(postEditorPane.getText()))
142: return null; // NOI18N
143: return postEditorPane.getText();
144: }
145:
146: public java.awt.Dimension getPreferredSize() {
147: java.awt.Dimension inh = super .getPreferredSize();
148: return new java.awt.Dimension(Math
149: .max(inh.width, DEFAULT_WIDTH), Math.max(inh.height,
150: DEFAULT_HEIGHT));
151: }
152:
153: /** This method is called from within the constructor to
154: * initialize the form.
155: * WARNING: Do NOT modify this code. The content of this method is
156: * always regenerated by the Form Editor.
157: */
158: private void initComponents() {//GEN-BEGIN:initComponents
159: prePanel = new javax.swing.JPanel();
160: preCheckBox = new javax.swing.JCheckBox();
161: preScrollPane = new javax.swing.JScrollPane();
162: preEditorPane = new javax.swing.JEditorPane();
163: postPanel = new javax.swing.JPanel();
164: postCheckBox = new javax.swing.JCheckBox();
165: postScrollPane = new javax.swing.JScrollPane();
166: postEditorPane = new javax.swing.JEditorPane();
167:
168: setLayout(new java.awt.GridBagLayout());
169: java.awt.GridBagConstraints gridBagConstraints1;
170:
171: prePanel.setLayout(new java.awt.GridBagLayout());
172: java.awt.GridBagConstraints gridBagConstraints2;
173:
174: preCheckBox.setText("jCheckBox1");
175: preCheckBox.addItemListener(new java.awt.event.ItemListener() {
176: public void itemStateChanged(java.awt.event.ItemEvent evt) {
177: preCheckBoxItemStateChanged(evt);
178: }
179: });
180:
181: gridBagConstraints2 = new java.awt.GridBagConstraints();
182: gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
183: gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
184: prePanel.add(preCheckBox, gridBagConstraints2);
185:
186: preScrollPane.setViewportView(preEditorPane);
187:
188: gridBagConstraints2 = new java.awt.GridBagConstraints();
189: gridBagConstraints2.gridx = 0;
190: gridBagConstraints2.gridy = 1;
191: gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
192: gridBagConstraints2.gridheight = java.awt.GridBagConstraints.REMAINDER;
193: gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
194: gridBagConstraints2.insets = new java.awt.Insets(5, 0, 0, 0);
195: gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
196: gridBagConstraints2.weightx = 1.0;
197: gridBagConstraints2.weighty = 1.0;
198: prePanel.add(preScrollPane, gridBagConstraints2);
199:
200: gridBagConstraints1 = new java.awt.GridBagConstraints();
201: gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
202: gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
203: gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11);
204: gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST;
205: gridBagConstraints1.weightx = 1.0;
206: gridBagConstraints1.weighty = 1.0;
207: add(prePanel, gridBagConstraints1);
208:
209: postPanel.setLayout(new java.awt.GridBagLayout());
210: java.awt.GridBagConstraints gridBagConstraints3;
211:
212: postCheckBox.setText("jCheckBox2");
213: postCheckBox.addItemListener(new java.awt.event.ItemListener() {
214: public void itemStateChanged(java.awt.event.ItemEvent evt) {
215: postCheckBoxItemStateChanged(evt);
216: }
217: });
218:
219: gridBagConstraints3 = new java.awt.GridBagConstraints();
220: gridBagConstraints3.gridwidth = java.awt.GridBagConstraints.REMAINDER;
221: gridBagConstraints3.anchor = java.awt.GridBagConstraints.NORTHWEST;
222: postPanel.add(postCheckBox, gridBagConstraints3);
223:
224: postScrollPane.setViewportView(postEditorPane);
225:
226: gridBagConstraints3 = new java.awt.GridBagConstraints();
227: gridBagConstraints3.gridx = 0;
228: gridBagConstraints3.gridy = 1;
229: gridBagConstraints3.gridwidth = java.awt.GridBagConstraints.REMAINDER;
230: gridBagConstraints3.gridheight = java.awt.GridBagConstraints.REMAINDER;
231: gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
232: gridBagConstraints3.insets = new java.awt.Insets(5, 0, 0, 0);
233: gridBagConstraints3.anchor = java.awt.GridBagConstraints.NORTHWEST;
234: gridBagConstraints3.weightx = 1.0;
235: gridBagConstraints3.weighty = 1.0;
236: postPanel.add(postScrollPane, gridBagConstraints3);
237:
238: gridBagConstraints1 = new java.awt.GridBagConstraints();
239: gridBagConstraints1.gridx = 0;
240: gridBagConstraints1.gridy = 1;
241: gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
242: gridBagConstraints1.gridheight = java.awt.GridBagConstraints.REMAINDER;
243: gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
244: gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11);
245: gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST;
246: gridBagConstraints1.weightx = 1.0;
247: gridBagConstraints1.weighty = 1.0;
248: add(postPanel, gridBagConstraints1);
249:
250: }//GEN-END:initComponents
251:
252: private void postCheckBoxItemStateChanged(
253: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_postCheckBoxItemStateChanged
254: // Add your handling code here:
255: postEditorPane.setEnabled(postCheckBox.isSelected());
256: if (postCheckBox.isSelected()) {
257: postEditorPane.requestFocus();
258: }
259: }//GEN-LAST:event_postCheckBoxItemStateChanged
260:
261: private void preCheckBoxItemStateChanged(
262: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_preCheckBoxItemStateChanged
263: // Add your handling code here:
264: preEditorPane.setEnabled(preCheckBox.isSelected());
265: if (preCheckBox.isSelected()) {
266: preEditorPane.requestFocus();
267: }
268: }//GEN-LAST:event_preCheckBoxItemStateChanged
269:
270: // Variables declaration - do not modify//GEN-BEGIN:variables
271: private javax.swing.JPanel prePanel;
272: private javax.swing.JCheckBox preCheckBox;
273: private javax.swing.JScrollPane preScrollPane;
274: private javax.swing.JEditorPane preEditorPane;
275: private javax.swing.JPanel postPanel;
276: private javax.swing.JCheckBox postCheckBox;
277: private javax.swing.JScrollPane postScrollPane;
278: private javax.swing.JEditorPane postEditorPane;
279: // End of variables declaration//GEN-END:variables
280:
281: }
|