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-2007 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.netbeans.modules.cnd.makewizard;
043:
044: import java.awt.GridBagConstraints;
045: import java.awt.Insets;
046: import java.awt.event.ActionEvent;
047: import java.awt.event.ActionListener;
048: import java.awt.event.FocusEvent;
049: import java.awt.event.FocusListener;
050: import java.io.File;
051: import javax.swing.JButton;
052: import javax.swing.JDialog;
053: import javax.swing.JFileChooser;
054: import javax.swing.JLabel;
055: import javax.swing.JTextField;
056: import org.netbeans.modules.cnd.api.utils.IpeFileSystemView;
057: import org.netbeans.modules.cnd.api.utils.IpeUtils;
058:
059: /**
060: * Create the basic compiler flags panel in the Makefile wizard.
061: */
062: /* Implements FocusListener because if you selected something in a text field,
063: * then clicked in a different text field, your selection would persist in the
064: * previous text field. Need to lose the selection when you lose the focus.
065: * This issue is when using jdk 1.4.0.
066: */
067: public class CompilerPathPanel extends MakefileWizardPanel implements
068: FocusListener {
069: /** Serial version number */
070: static final long serialVersionUID = 1334257510688903149L;
071:
072: // the fields in the panel...
073: private JTextField c;
074: private JTextField cpp;
075: private JTextField f95;
076: private JTextField asm;
077:
078: private boolean initialized;
079: private JFileChooser fc;
080:
081: /** Save the chooser directory for subsequent choosers calls */
082: private File chooserDir;
083:
084: /**
085: * Constructor for the compiler paths panel.
086: */
087: public CompilerPathPanel(MakefileWizard wd) {
088: super (wd);
089: String subtitle = getString("LBL_CompilerPathPanel"); // NOI18N
090: setSubTitle(subtitle);
091: this .getAccessibleContext().setAccessibleDescription(subtitle);
092: initialized = false;
093: }
094:
095: /** Defer widget creation until the panel needs to be displayed */
096: private void create() {
097:
098: setLayout(new java.awt.GridBagLayout());
099: GridBagConstraints grid = new GridBagConstraints();
100: grid.fill = GridBagConstraints.HORIZONTAL;
101:
102: JLabel pathLabel = new JLabel(getString("LBL_CompilerPaths")); // NOI18N
103: grid.anchor = GridBagConstraints.NORTHWEST;
104: grid.gridx = 0;
105: grid.gridy = 0;
106: grid.gridwidth = GridBagConstraints.REMAINDER;
107: add(pathLabel, grid, -1);
108:
109: c = createLine(1, getString("LBL_C"), getString("MNEM_C")); // NOI18N
110: cpp = createLine(2, getString("LBL_Cpp"), getString("MNEM_Cpp")); // NOI18N
111: f95 = createLine(4, getString("LBL_F95"), getString("MNEM_F95")); // NOI18N
112: asm = createLine(5, getString("LBL_Asm"), getString("MNEM_Asm")); // NOI18N
113:
114: c.addFocusListener(this );
115: cpp.addFocusListener(this );
116: f95.addFocusListener(this );
117: asm.addFocusListener(this );
118:
119: grid.gridx = 0;
120: grid.gridy = 7;
121: grid.gridwidth = GridBagConstraints.REMAINDER;
122: grid.gridheight = GridBagConstraints.REMAINDER;
123: grid.weightx = 1.0;
124: grid.weighty = 1.0;
125: add(new JLabel(""), grid); // NOI18N
126: }
127:
128: private JTextField createLine(int lnum, String label,
129: String mnemonic) {
130: GridBagConstraints grid = new GridBagConstraints();
131: grid.gridy = lnum;
132:
133: JLabel nueLabel = new JLabel(label);
134: nueLabel.setDisplayedMnemonic(mnemonic.charAt(0));
135: grid.anchor = GridBagConstraints.WEST;
136: grid.gridx = 0;
137: grid.gridwidth = 1;
138: if (lnum == 1) {
139: grid.insets = new Insets(5, 0, 0, 0);
140: } else {
141: grid.insets = new Insets(11, 0, 0, 0);
142: }
143: add(nueLabel, grid);
144:
145: JTextField nueText = new JTextField();
146: nueLabel.setLabelFor(nueText);
147: grid.anchor = GridBagConstraints.WEST;
148: grid.gridx = 1;
149: grid.gridwidth = GridBagConstraints.RELATIVE;
150: grid.fill = GridBagConstraints.HORIZONTAL;
151: grid.weightx = 1.0;
152: grid.insets = new Insets(11, 12, 0, 0);
153: add(nueText, grid);
154:
155: JButton chooser = new JButton(getString("BTN_Chooser")); // NOI18N
156: String mnem = "MNEM_Chooser" + // NOI18N
157: new Integer(lnum);
158: chooser.setMnemonic(getString(mnem).charAt(0));
159: grid.anchor = GridBagConstraints.WEST;
160: grid.gridx = 2;
161: grid.gridwidth = 1;
162: grid.fill = GridBagConstraints.NONE;
163: grid.weightx = 0.0;
164: grid.insets = new Insets(11, 5, 0, 0);
165: add(chooser, grid);
166: createChooser(nueText, chooser);
167:
168: return nueText;
169: }
170:
171: /**
172: * Create a FileChoose for the text field.
173: */
174: protected void createChooser(final JTextField text,
175: final JButton chooser) {
176:
177: chooser.addActionListener(new ActionListener() {
178: public void actionPerformed(ActionEvent evt) {
179:
180: if (fc == null) {
181: fc = new JFileChooser();
182: fc.setApproveButtonText(getString("BTN_Approve")); // NOI18N
183: fc.setFileSystemView(new IpeFileSystemView(fc
184: .getFileSystemView()));
185: fc
186: .setDialogTitle(getString("DLG_FILE_CHOOSER_TITLE")); // NOI18N
187: }
188:
189: if (chooserDir == null) {
190: chooserDir = new File(getMakefileData()
191: .getBaseDirectory());
192: }
193: fc.setCurrentDirectory(chooserDir);
194: int returnVal = fc.showDialog(CompilerPathPanel.this ,
195: null);
196:
197: if (returnVal == JFileChooser.APPROVE_OPTION) {
198: chooserDir = fc.getCurrentDirectory();
199: text
200: .setText(fc.getSelectedFile()
201: .getAbsolutePath());
202: }
203: }
204: });
205: }
206:
207: /** Create the widgets if not initialized */
208: public void addNotify() {
209:
210: if (!initialized) {
211: create();
212: initialized = true;
213: }
214:
215: MakefileData md = getMakefileData();
216:
217: c.setText(md.getCCompiler(md.getToolset()));
218: cpp.setText(md.getCppCompiler(md.getToolset()));
219: f95.setText(md.getFCompiler(md.getToolset()));
220: asm.setText(md.getAsmPath());
221:
222: super .addNotify();
223: c.selectAll();
224:
225: IpeUtils.requestFocus(c);
226: }
227:
228: /** Get the data from the panel and update the target */
229: public void removeNotify() {
230: super .removeNotify();
231:
232: if (fc != null && fc.isShowing()) {
233: Object o = fc.getTopLevelAncestor();
234: if (o != null && o instanceof JDialog) {
235: ((JDialog) o).dispose();
236: }
237: }
238:
239: MakefileData md = getMakefileData();
240: int i;
241:
242: if (c.getText().length() > 0) {
243: md.setCCompiler(md.getToolset(), c.getText());
244: }
245:
246: if (cpp.getText().length() > 0) {
247: md.setCppCompiler(md.getToolset(), cpp.getText());
248: }
249:
250: if (f95.getText().length() > 0) {
251: md.setFCompiler(md.getToolset(), f95.getText());
252: }
253:
254: if (asm.getText().length() > 0) {
255: md.setAsmPath(asm.getText());
256: }
257: }
258:
259: public void focusGained(FocusEvent evt) {
260: }
261:
262: public void focusLost(FocusEvent evt) {
263: ((JTextField) evt.getComponent()).setSelectionEnd(0);
264: }
265: }
|