~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to ant/src/org/apache/tools/ant/module/wizards/shortcut/CustomizeScriptPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.apache.tools.ant.module.wizards.shortcut;
 
43
 
 
44
import java.awt.Component;
 
45
import javax.swing.JEditorPane;
 
46
import javax.swing.event.ChangeListener;
 
47
import javax.swing.text.EditorKit;
 
48
import org.openide.WizardDescriptor;
 
49
import org.openide.util.HelpCtx;
 
50
import org.openide.util.NbBundle;
 
51
 
 
52
final class CustomizeScriptPanel extends javax.swing.JPanel {
 
53
 
 
54
    /** Create the wizard panel component and set up some basic properties. */
 
55
    public CustomizeScriptPanel (CustomizeScriptWizardPanel wiz) {
 
56
        initComponents ();
 
57
        initAccessibility ();
 
58
        // Provide a name in the title bar.
 
59
        setName (NbBundle.getMessage (CustomizeScriptPanel.class, "CSP_LBL_cust_gend_ant_script"));
 
60
        scriptPane.setContentType ("text/xml"); // NOI18N
 
61
        // Hack; EditorKit does not permit "fallback" kits, so we have to
 
62
        // mimic what the IDE itself does:
 
63
        EditorKit kit = scriptPane.getEditorKit ();
 
64
        String clazz = kit.getClass ().getName ();
 
65
        if (clazz.equals ("javax.swing.text.DefaultEditorKit") || // NOI18N
 
66
               clazz.equals ("javax.swing.JEditorPane$PlainEditorKit")) { // NOI18N
 
67
            scriptPane.setEditorKit (JEditorPane.createEditorKitForContentType ("text/plain")); // NOI18N
 
68
        }
 
69
    }
 
70
 
 
71
    // --- VISUAL DESIGN OF PANEL ---
 
72
    
 
73
    @Override
 
74
    public void requestFocus () {
 
75
        super.requestFocus ();
 
76
        scriptPane.requestFocus ();
 
77
    }
 
78
 
 
79
    private void initAccessibility () {        
 
80
        scriptPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage (CustomizeScriptPanel.class, "ACSN_TEXT_you_may_customize_gend2"));          
 
81
        scriptPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (CustomizeScriptPanel.class, "ACSD_TEXT_you_may_customize_gend2"));          
 
82
        this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizeScriptPanel.class, "CSP_TEXT_you_may_customize_gend2"));
 
83
    }
 
84
    
 
85
    /** This method is called from within the constructor to
 
86
     * initialize the form.
 
87
     * WARNING: Do NOT modify this code. The content of this method is
 
88
     * always regenerated by the Form Editor.
 
89
     */
 
90
    private void initComponents() {//GEN-BEGIN:initComponents
 
91
        scrollPane = new javax.swing.JScrollPane();
 
92
        scriptPane = new javax.swing.JEditorPane();
 
93
        hintsArea = new javax.swing.JTextArea();
 
94
 
 
95
        setLayout(new java.awt.BorderLayout(0, 11));
 
96
 
 
97
        scrollPane.setPreferredSize(new java.awt.Dimension(100, 100));
 
98
        scrollPane.setViewportView(scriptPane);
 
99
 
 
100
        add(scrollPane, java.awt.BorderLayout.CENTER);
 
101
 
 
102
        hintsArea.setBackground(new java.awt.Color(204, 204, 204));
 
103
        hintsArea.setEditable(false);
 
104
        hintsArea.setFont(javax.swing.UIManager.getFont ("Label.font"));
 
105
        hintsArea.setForeground(new java.awt.Color(102, 102, 153));
 
106
        hintsArea.setLineWrap(true);
 
107
        hintsArea.setText(NbBundle.getMessage(CustomizeScriptPanel.class, "CSP_TEXT_you_may_customize_gend2"));
 
108
        hintsArea.setWrapStyleWord(true);
 
109
        hintsArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground"));
 
110
        hintsArea.setEnabled(false);
 
111
        hintsArea.setOpaque(false);
 
112
        add(hintsArea, java.awt.BorderLayout.NORTH);
 
113
 
 
114
    }//GEN-END:initComponents
 
115
 
 
116
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
117
    private javax.swing.JTextArea hintsArea;
 
118
    private javax.swing.JScrollPane scrollPane;
 
119
    private javax.swing.JEditorPane scriptPane;
 
120
    // End of variables declaration//GEN-END:variables
 
121
 
 
122
    
 
123
    public static class CustomizeScriptWizardPanel implements WizardDescriptor.Panel<ShortcutWizard> {
 
124
 
 
125
        private CustomizeScriptPanel panel = null;
 
126
 
 
127
        public Component getComponent () {
 
128
            return getPanel();
 
129
        }
 
130
        
 
131
        private CustomizeScriptPanel getPanel() {
 
132
            if (panel == null) {
 
133
                panel = new CustomizeScriptPanel(this);
 
134
            }
 
135
            return panel;
 
136
        }
 
137
 
 
138
        public HelpCtx getHelp () {
 
139
            return HelpCtx.DEFAULT_HELP;
 
140
        }
 
141
 
 
142
        public boolean isValid () {
 
143
            return true;
 
144
            // XXX ideally make it valid only if script is parseable without errors;
 
145
            // could use AntProjectSupport for this, or just parse the XML and check
 
146
            // for the correct root element etc.
 
147
        }
 
148
 
 
149
        public final void addChangeListener (ChangeListener l) {}
 
150
        public final void removeChangeListener (ChangeListener l) {}
 
151
 
 
152
        public void readSettings(ShortcutWizard wiz) {
 
153
            String contents = wiz.getContents();
 
154
            getPanel().scriptPane.setText(contents);
 
155
        }
 
156
        public void storeSettings(ShortcutWizard wiz) {
 
157
            wiz.putContents(getPanel().scriptPane.getText());
 
158
        }
 
159
    }
 
160
 
 
161
}