KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > wizards > shortcut > CustomizeScriptPanel


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.apache.tools.ant.module.wizards.shortcut;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.JEditorPane JavaDoc;
24 import javax.swing.event.ChangeListener JavaDoc;
25 import javax.swing.text.EditorKit JavaDoc;
26 import org.openide.WizardDescriptor;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29
30 final class CustomizeScriptPanel extends javax.swing.JPanel JavaDoc {
31
32     /** Create the wizard panel component and set up some basic properties. */
33     public CustomizeScriptPanel (CustomizeScriptWizardPanel wiz) {
34         initComponents ();
35         initAccessibility ();
36         // Provide a name in the title bar.
37
setName (NbBundle.getMessage (CustomizeScriptPanel.class, "CSP_LBL_cust_gend_ant_script"));
38         scriptPane.setContentType ("text/xml"); // NOI18N
39
// Hack; EditorKit does not permit "fallback" kits, so we have to
40
// mimic what the IDE itself does:
41
EditorKit JavaDoc kit = scriptPane.getEditorKit ();
42         String JavaDoc clazz = kit.getClass ().getName ();
43         if (clazz.equals ("javax.swing.text.DefaultEditorKit") || // NOI18N
44
clazz.equals ("javax.swing.JEditorPane$PlainEditorKit")) { // NOI18N
45
scriptPane.setEditorKit (JEditorPane.createEditorKitForContentType ("text/plain")); // NOI18N
46
}
47     }
48
49     // --- VISUAL DESIGN OF PANEL ---
50

51     @Override JavaDoc
52     public void requestFocus () {
53         super.requestFocus ();
54         scriptPane.requestFocus ();
55     }
56
57     private void initAccessibility () {
58         scriptPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage (CustomizeScriptPanel.class, "ACSN_TEXT_you_may_customize_gend2"));
59         scriptPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (CustomizeScriptPanel.class, "ACSD_TEXT_you_may_customize_gend2"));
60         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizeScriptPanel.class, "CSP_TEXT_you_may_customize_gend2"));
61     }
62     
63     /** This method is called from within the constructor to
64      * initialize the form.
65      * WARNING: Do NOT modify this code. The content of this method is
66      * always regenerated by the Form Editor.
67      */

68     private void initComponents() {//GEN-BEGIN:initComponents
69
scrollPane = new javax.swing.JScrollPane JavaDoc();
70         scriptPane = new javax.swing.JEditorPane JavaDoc();
71         hintsArea = new javax.swing.JTextArea JavaDoc();
72
73         setLayout(new java.awt.BorderLayout JavaDoc(0, 11));
74
75         scrollPane.setPreferredSize(new java.awt.Dimension JavaDoc(100, 100));
76         scrollPane.setViewportView(scriptPane);
77
78         add(scrollPane, java.awt.BorderLayout.CENTER);
79
80         hintsArea.setBackground(new java.awt.Color JavaDoc(204, 204, 204));
81         hintsArea.setEditable(false);
82         hintsArea.setFont(javax.swing.UIManager.getFont ("Label.font"));
83         hintsArea.setForeground(new java.awt.Color JavaDoc(102, 102, 153));
84         hintsArea.setLineWrap(true);
85         hintsArea.setText(NbBundle.getMessage(CustomizeScriptPanel.class, "CSP_TEXT_you_may_customize_gend2"));
86         hintsArea.setWrapStyleWord(true);
87         hintsArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground"));
88         hintsArea.setEnabled(false);
89         hintsArea.setOpaque(false);
90         add(hintsArea, java.awt.BorderLayout.NORTH);
91
92     }//GEN-END:initComponents
93

94     // Variables declaration - do not modify//GEN-BEGIN:variables
95
private javax.swing.JTextArea JavaDoc hintsArea;
96     private javax.swing.JScrollPane JavaDoc scrollPane;
97     private javax.swing.JEditorPane JavaDoc scriptPane;
98     // End of variables declaration//GEN-END:variables
99

100     
101     public static class CustomizeScriptWizardPanel implements WizardDescriptor.Panel {
102
103         private CustomizeScriptPanel panel = null;
104
105         public Component JavaDoc getComponent () {
106             return getPanel();
107         }
108         
109         private CustomizeScriptPanel getPanel() {
110             if (panel == null) {
111                 panel = new CustomizeScriptPanel(this);
112             }
113             return panel;
114         }
115
116         public HelpCtx getHelp () {
117             return HelpCtx.DEFAULT_HELP;
118         }
119
120         public boolean isValid () {
121             return true;
122             // XXX ideally make it valid only if script is parseable without errors;
123
// could use AntProjectSupport for this, or just parse the XML and check
124
// for the correct root element etc.
125
}
126
127         public final void addChangeListener (ChangeListener JavaDoc l) {}
128         public final void removeChangeListener (ChangeListener JavaDoc l) {}
129         /*
130         private final Set listeners = new HashSet (1); // Set<ChangeListener>
131         public final void addChangeListener (ChangeListener l) {
132             synchronized (listeners) {
133                 listeners.add (l);
134             }
135         }
136         public final void removeChangeListener (ChangeListener l) {
137             synchronized (listeners) {
138                 listeners.remove (l);
139             }
140         }
141         protected final void fireChangeEvent () {
142             Iterator it;
143             synchronized (listeners) {
144                 it = new HashSet (listeners).iterator ();
145             }
146             ChangeEvent ev = new ChangeEvent (this);
147             while (it.hasNext ()) {
148                 ((ChangeListener) it.next ()).stateChanged (ev);
149             }
150         }
151         */

152
153         public void readSettings (Object JavaDoc settings) {
154             ShortcutWizard wiz = (ShortcutWizard) settings;
155             String JavaDoc contents = wiz.getContents();
156             getPanel().scriptPane.setText(contents);
157         }
158         public void storeSettings (Object JavaDoc settings) {
159             ShortcutWizard wiz = (ShortcutWizard) settings;
160             wiz.putContents(getPanel().scriptPane.getText());
161         }
162     }
163
164 }
165
Popular Tags