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: package org.apache.tools.ant.module.wizards.shortcut;
043:
044: import java.awt.Component;
045: import javax.swing.JEditorPane;
046: import javax.swing.event.ChangeListener;
047: import javax.swing.text.EditorKit;
048: import org.openide.WizardDescriptor;
049: import org.openide.util.HelpCtx;
050: import org.openide.util.NbBundle;
051:
052: final class CustomizeScriptPanel extends javax.swing.JPanel {
053:
054: /** Create the wizard panel component and set up some basic properties. */
055: public CustomizeScriptPanel(CustomizeScriptWizardPanel wiz) {
056: initComponents();
057: initAccessibility();
058: // Provide a name in the title bar.
059: setName(NbBundle.getMessage(CustomizeScriptPanel.class,
060: "CSP_LBL_cust_gend_ant_script"));
061: scriptPane.setContentType("text/xml"); // NOI18N
062: // Hack; EditorKit does not permit "fallback" kits, so we have to
063: // mimic what the IDE itself does:
064: EditorKit kit = scriptPane.getEditorKit();
065: String clazz = kit.getClass().getName();
066: if (clazz.equals("javax.swing.text.DefaultEditorKit") || // NOI18N
067: clazz.equals("javax.swing.JEditorPane$PlainEditorKit")) { // NOI18N
068: scriptPane.setEditorKit(JEditorPane
069: .createEditorKitForContentType("text/plain")); // NOI18N
070: }
071: }
072:
073: // --- VISUAL DESIGN OF PANEL ---
074:
075: @Override
076: public void requestFocus() {
077: super .requestFocus();
078: scriptPane.requestFocus();
079: }
080:
081: private void initAccessibility() {
082: scriptPane.getAccessibleContext().setAccessibleName(
083: NbBundle.getMessage(CustomizeScriptPanel.class,
084: "ACSN_TEXT_you_may_customize_gend2"));
085: scriptPane.getAccessibleContext().setAccessibleDescription(
086: NbBundle.getMessage(CustomizeScriptPanel.class,
087: "ACSD_TEXT_you_may_customize_gend2"));
088: this .getAccessibleContext().setAccessibleDescription(
089: NbBundle.getMessage(CustomizeScriptPanel.class,
090: "CSP_TEXT_you_may_customize_gend2"));
091: }
092:
093: /** This method is called from within the constructor to
094: * initialize the form.
095: * WARNING: Do NOT modify this code. The content of this method is
096: * always regenerated by the Form Editor.
097: */
098: private void initComponents() {//GEN-BEGIN:initComponents
099: scrollPane = new javax.swing.JScrollPane();
100: scriptPane = new javax.swing.JEditorPane();
101: hintsArea = new javax.swing.JTextArea();
102:
103: setLayout(new java.awt.BorderLayout(0, 11));
104:
105: scrollPane.setPreferredSize(new java.awt.Dimension(100, 100));
106: scrollPane.setViewportView(scriptPane);
107:
108: add(scrollPane, java.awt.BorderLayout.CENTER);
109:
110: hintsArea.setBackground(new java.awt.Color(204, 204, 204));
111: hintsArea.setEditable(false);
112: hintsArea.setFont(javax.swing.UIManager.getFont("Label.font"));
113: hintsArea.setForeground(new java.awt.Color(102, 102, 153));
114: hintsArea.setLineWrap(true);
115: hintsArea.setText(NbBundle.getMessage(
116: CustomizeScriptPanel.class,
117: "CSP_TEXT_you_may_customize_gend2"));
118: hintsArea.setWrapStyleWord(true);
119: hintsArea.setDisabledTextColor(javax.swing.UIManager
120: .getColor("Label.foreground"));
121: hintsArea.setEnabled(false);
122: hintsArea.setOpaque(false);
123: add(hintsArea, java.awt.BorderLayout.NORTH);
124:
125: }//GEN-END:initComponents
126:
127: // Variables declaration - do not modify//GEN-BEGIN:variables
128: private javax.swing.JTextArea hintsArea;
129: private javax.swing.JScrollPane scrollPane;
130: private javax.swing.JEditorPane scriptPane;
131:
132: // End of variables declaration//GEN-END:variables
133:
134: public static class CustomizeScriptWizardPanel implements
135: WizardDescriptor.Panel<ShortcutWizard> {
136:
137: private CustomizeScriptPanel panel = null;
138:
139: public Component getComponent() {
140: return getPanel();
141: }
142:
143: private CustomizeScriptPanel getPanel() {
144: if (panel == null) {
145: panel = new CustomizeScriptPanel(this );
146: }
147: return panel;
148: }
149:
150: public HelpCtx getHelp() {
151: return HelpCtx.DEFAULT_HELP;
152: }
153:
154: public boolean isValid() {
155: return true;
156: // XXX ideally make it valid only if script is parseable without errors;
157: // could use AntProjectSupport for this, or just parse the XML and check
158: // for the correct root element etc.
159: }
160:
161: public final void addChangeListener(ChangeListener l) {
162: }
163:
164: public final void removeChangeListener(ChangeListener l) {
165: }
166:
167: public void readSettings(ShortcutWizard wiz) {
168: String contents = wiz.getContents();
169: getPanel().scriptPane.setText(contents);
170: }
171:
172: public void storeSettings(ShortcutWizard wiz) {
173: wiz.putContents(getPanel().scriptPane.getText());
174: }
175: }
176:
177: }
|