KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > railsprojects > ui > customizer > CustomizerCompile


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.netbeans.modules.ruby.railsprojects.ui.customizer;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.*;
25 import java.awt.*;
26 import java.io.BufferedReader JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.InputStreamReader JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation;
31 import org.openide.ErrorManager;
32
33 import org.openide.util.HelpCtx;
34 import org.openide.util.RequestProcessor;
35 import org.openide.util.RequestProcessor;
36
37 /**
38  *
39  * @author phrebejk
40  */

41 public class CustomizerCompile extends JPanel JavaDoc implements HelpCtx.Provider {
42
43         
44     public CustomizerCompile( RailsProjectProperties uiProperties ) {
45         initComponents();
46                 
47         additionalJavacParamsJTextField.setDocument( uiProperties.JAVAC_COMPILER_ARG_MODEL );
48
49         // Display the available Ruby flags
50
RequestProcessor.getDefault().post(new Runnable JavaDoc() {
51
52             public void run() {
53                 String JavaDoc path = RubyInstallation.getInstance().getRuby();
54                 ProcessBuilder JavaDoc pb = new ProcessBuilder JavaDoc(path, "-help");
55                 Map<String JavaDoc,String JavaDoc> env = pb.environment();
56                 String JavaDoc currentPath = env.get("PATH");
57
58                 if (currentPath == null) {
59                     currentPath = "";
60                 }
61                 currentPath = new File JavaDoc(RubyInstallation.getInstance().getRuby()).getParent() +
62                               File.pathSeparator + currentPath;
63                 env.put("PATH", currentPath);
64                 StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
65
66                 try {
67                     Process JavaDoc process = pb.start();
68                     // This is lame. I'm sure there's a way to route the forked process'
69
// I/O through the I/O window directly... but where is it?
70
// If not, grab the MevenJavaExecutor's Output inner class and use that here
71
InputStream JavaDoc is = process.getInputStream();
72                     InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(is);
73                     BufferedReader JavaDoc br = new BufferedReader JavaDoc(isr);
74                     String JavaDoc line;
75
76                     while ((line = br.readLine()) != null) {
77                         sb.append(line);
78                         sb.append("\n");
79                     }
80                     process.waitFor();
81                 }
82                 catch (IOException JavaDoc ex) {
83                     ErrorManager.getDefault().notify(ex);
84                 }
85                 catch (InterruptedException JavaDoc ex) {
86                     ErrorManager.getDefault().notify(ex);
87                 }
88                 flagsArea.setText(sb.toString());
89             }
90         }, 50);
91     }
92
93     public HelpCtx getHelpCtx() {
94         return new HelpCtx( CustomizerCompile.class );
95     }
96
97
98     /** This method is called from within the constructor to
99      * initialize the form.
100      * WARNING: Do NOT modify this code. The content of this method is
101      * always regenerated by the Form Editor.
102      */

103     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
104
private void initComponents() {
105         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
106
107         additionalJavacParamsJLabel = new javax.swing.JLabel JavaDoc();
108         additionalJavacParamsJTextField = new javax.swing.JTextField JavaDoc();
109         additionalJavacParamsExampleJLabel = new javax.swing.JLabel JavaDoc();
110         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
111         flagsArea = new javax.swing.JTextArea JavaDoc();
112
113         setLayout(new java.awt.GridBagLayout JavaDoc());
114
115         additionalJavacParamsJLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage (CustomizerCompile.class,"MNE_AdditionalCompilerOptions").charAt(0));
116         additionalJavacParamsJLabel.setLabelFor(additionalJavacParamsJTextField);
117         org.openide.awt.Mnemonics.setLocalizedText(additionalJavacParamsJLabel, org.openide.util.NbBundle.getMessage (CustomizerCompile.class,"LBL_AdditionalCompilerOptions"));
118         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
119         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
120         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
121         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 12);
122         add(additionalJavacParamsJLabel, gridBagConstraints);
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
125         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
126         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
127         gridBagConstraints.weightx = 1.0;
128         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
129         add(additionalJavacParamsJTextField, gridBagConstraints);
130         additionalJavacParamsJTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage (CustomizerCompile.class,"AD_AdditionalCompilerOptions"));
131
132         org.openide.awt.Mnemonics.setLocalizedText(additionalJavacParamsExampleJLabel, org.openide.util.NbBundle.getMessage (CustomizerCompile.class,"LBL_AdditionalCompilerOptionsExample"));
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridx = 1;
135         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
136         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
139         add(additionalJavacParamsExampleJLabel, gridBagConstraints);
140
141         flagsArea.setColumns(20);
142         flagsArea.setEditable(false);
143         flagsArea.setLineWrap(true);
144         flagsArea.setRows(5);
145         flagsArea.setWrapStyleWord(true);
146         jScrollPane1.setViewportView(flagsArea);
147
148         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.gridx = 0;
150         gridBagConstraints.gridy = 2;
151         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
152         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
153         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
154         gridBagConstraints.weightx = 1.0;
155         gridBagConstraints.weighty = 1.0;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
157         add(jScrollPane1, gridBagConstraints);
158     }// </editor-fold>//GEN-END:initComponents
159

160
161     // Variables declaration - do not modify//GEN-BEGIN:variables
162
private javax.swing.JLabel JavaDoc additionalJavacParamsExampleJLabel;
163     private javax.swing.JLabel JavaDoc additionalJavacParamsJLabel;
164     private javax.swing.JTextField JavaDoc additionalJavacParamsJTextField;
165     private javax.swing.JTextArea JavaDoc flagsArea;
166     private javax.swing.JScrollPane JavaDoc jScrollPane1;
167     // End of variables declaration//GEN-END:variables
168

169
170
171 }
172
Popular Tags