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 javax.swing.BorderFactory;
046: import javax.swing.JCheckBox;
047: import javax.swing.JComboBox;
048: import javax.swing.JLabel;
049: import javax.swing.JPanel;
050: import javax.swing.JScrollPane;
051: import javax.swing.border.Border;
052: import org.netbeans.modules.cnd.api.utils.IpeUtils;
053:
054: /**
055: * Create the standard libraries panel in the Makefile wizard.
056: */
057:
058: public class StandardLibsPanel extends MakefileWizardPanel {
059:
060: /** Serial version number */
061: static final long serialVersionUID = -1354448784992649011L;
062:
063: // the fields in the panel...
064: private JLabel libsLabel;
065:
066: private JPanel mainPanel;
067: private JPanel currentCheckBoxPanel;
068: private JPanel solarisCheckBoxPanel;
069: private JPanel linuxCheckBoxPanel;
070: private JPanel macosxCheckBoxPanel;
071:
072: private JCheckBox[] solarisCheckBoxes;
073: private JCheckBox[] linuxCheckBoxes;
074: private JCheckBox[] macosxCheckBoxes;
075:
076: private JComboBox linkModeCB;
077:
078: /** Store the target key */
079: private int key;
080:
081: private boolean initialized;
082:
083: /**
084: * Constructor for the Standard Libs panel.
085: */
086: public StandardLibsPanel(MakefileWizard wd) {
087: super (wd);
088: String subtitle = new String(getString("LBL_StandardLibsPanel")); // NOI18N
089: setSubTitle(subtitle);
090: this .getAccessibleContext().setAccessibleDescription(subtitle);
091: initialized = false;
092: }
093:
094: /** Defer widget creation until the panel needs to be displayed */
095: private void create() {
096: GridBagConstraints gridBagConstraints;
097: setLayout(new java.awt.GridBagLayout());
098:
099: JPanel panel = new javax.swing.JPanel();
100: mainPanel = new javax.swing.JPanel();
101: panel.setLayout(new java.awt.FlowLayout(
102: java.awt.FlowLayout.LEFT, 0, 0));
103: mainPanel.setLayout(new java.awt.GridBagLayout());
104:
105: libsLabel = new JLabel(getString("LBL_StdLibs")); // NOI18N
106: gridBagConstraints = new java.awt.GridBagConstraints();
107: gridBagConstraints.gridx = 0;
108: gridBagConstraints.gridy = 0;
109: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
110: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
111: mainPanel.add(libsLabel, gridBagConstraints);
112:
113: // checkboxes will be added dynamically in addNotify
114:
115: JPanel linkPanel = new JPanel();
116: linkPanel.setLayout(new java.awt.GridBagLayout());
117: //linkPanel.setLayout(new FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
118: JLabel linkLabel = new JLabel(getString("LBL_LinkMode"));
119: linkLabel.setDisplayedMnemonic(getString("MNEM_LinkMode")
120: .charAt(0)); // NOI18N
121: gridBagConstraints = new java.awt.GridBagConstraints();
122: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
123: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
124: linkPanel.add(linkLabel, gridBagConstraints);
125: //linkPanel.add(linkLabel);
126: linkModeCB = new JComboBox();
127: linkLabel.setLabelFor(linkModeCB);
128: gridBagConstraints = new java.awt.GridBagConstraints();
129: gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
130: gridBagConstraints.gridheight = 1;
131: gridBagConstraints.gridx = 1;
132: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133: gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
134: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
135: linkPanel.add(linkModeCB, gridBagConstraints);
136: //linkPanel.add(linkModeCB);
137:
138: gridBagConstraints = new java.awt.GridBagConstraints();
139: gridBagConstraints.gridx = 0;
140: gridBagConstraints.gridy = 2;
141: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
142: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
143: mainPanel.add(linkPanel, gridBagConstraints);
144:
145: panel.add(mainPanel);
146:
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.gridx = 0;
149: gridBagConstraints.gridy = 0;
150: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
151: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
152: gridBagConstraints.weightx = 1.0;
153: gridBagConstraints.weighty = 1.0;
154:
155: JScrollPane scrollPane = new JScrollPane();
156: scrollPane.setViewportView(panel);
157: scrollPane.setBorder(BorderFactory.createEmptyBorder());
158:
159: add(scrollPane, gridBagConstraints);
160: }
161:
162: /**
163: * Will add the checkbox panel to the main panel
164: */
165: private void addCheckBoxPanel(JPanel checkBoxPanel) {
166: GridBagConstraints gridBagConstraints;
167: gridBagConstraints = new java.awt.GridBagConstraints();
168: gridBagConstraints.gridx = 0;
169: gridBagConstraints.gridy = 1;
170: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
171: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
172: mainPanel.add(checkBoxPanel, gridBagConstraints);
173: }
174:
175: /**
176: * Will remove the checkbox panel from the main panel
177: */
178: private void removeCheckBoxPanel(JPanel checkBoxPanel) {
179: if (checkBoxPanel != null)
180: mainPanel.remove(checkBoxPanel);
181: }
182:
183: /**
184: * Returns a platform dependent checkbox panel
185: */
186: private JPanel getCheckBoxPanel() {
187: JPanel p;
188: if (getMakefileData().getMakefileOS() == MakefileData.SOLARIS_OS_TYPE) {
189: if (solarisCheckBoxPanel == null) {
190: StdLib[] stdLibs = getMakefileData().getCurrentTarget()
191: .getStdLibFlags().getSolarisStdLibs();
192: solarisCheckBoxes = new JCheckBox[stdLibs.length];
193: solarisCheckBoxPanel = constructCheckBoxPanel(stdLibs,
194: solarisCheckBoxes);
195: }
196: p = solarisCheckBoxPanel;
197: } else if (getMakefileData().getMakefileOS() == MakefileData.MACOSX_OS_TYPE) {
198: if (macosxCheckBoxPanel == null) {
199: StdLib[] stdLibs = getMakefileData().getCurrentTarget()
200: .getStdLibFlags().getMacOSXStdLibs();
201: macosxCheckBoxes = new JCheckBox[stdLibs.length];
202: macosxCheckBoxPanel = constructCheckBoxPanel(stdLibs,
203: macosxCheckBoxes);
204: }
205: p = macosxCheckBoxPanel;
206: } else {
207: if (linuxCheckBoxPanel == null) {
208: StdLib[] stdLibs = getMakefileData().getCurrentTarget()
209: .getStdLibFlags().getLinuxStdLibs();
210: linuxCheckBoxes = new JCheckBox[stdLibs.length];
211: linuxCheckBoxPanel = constructCheckBoxPanel(stdLibs,
212: linuxCheckBoxes);
213: }
214: p = linuxCheckBoxPanel;
215: }
216: return p;
217: }
218:
219: /**
220: * Returns platform dependent checkboxes
221: */
222: private JCheckBox[] getCheckBoxes() {
223: if (getMakefileData().getMakefileOS() == MakefileData.SOLARIS_OS_TYPE) {
224: return solarisCheckBoxes;
225: } else if (getMakefileData().getMakefileOS() == MakefileData.MACOSX_OS_TYPE) {
226: return macosxCheckBoxes;
227: } else {
228: return linuxCheckBoxes;
229: }
230: }
231:
232: /**
233: * Constructs the checkbox panel
234: */
235: private JPanel constructCheckBoxPanel(StdLib[] stdLibs,
236: JCheckBox[] checkBoxes) {
237: JPanel panel = new JPanel();
238: panel.setLayout(new java.awt.GridBagLayout());
239: GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
240: gridBagConstraints.gridx = 0;
241: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
242: gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
243: for (int i = 0; i < stdLibs.length; i++) {
244: checkBoxes[i] = new JCheckBox(stdLibs[i].getName()); // NOI18N
245: checkBoxes[i].setMnemonic(stdLibs[i].getMnemonic()); // NOI18N
246: panel.add(checkBoxes[i], gridBagConstraints);
247: }
248: return panel;
249: }
250:
251: /** Create the widgets if not already created */
252: public void addNotify() {
253: TargetData target = getMakefileData().getCurrentTarget();
254: StdLibFlags stdLibFlags = target.getStdLibFlags();
255: StdLib[] stdLibs;
256: if (getMakefileData().getMakefileOS() == MakefileData.SOLARIS_OS_TYPE) {
257: stdLibs = stdLibFlags.getSolarisStdLibs();
258: } else if (getMakefileData().getMakefileOS() == MakefileData.MACOSX_OS_TYPE) {
259: stdLibs = stdLibFlags.getMacOSXStdLibs();
260: } else {
261: stdLibs = stdLibFlags.getLinuxStdLibs();
262: }
263: key = target.getKey();
264:
265: if (!initialized) {
266: create();
267: initialized = true;
268: }
269:
270: // Update checkbox panel dynamically depending on platform
271: if (getCheckBoxPanel() != currentCheckBoxPanel) {
272: removeCheckBoxPanel(currentCheckBoxPanel);
273: currentCheckBoxPanel = getCheckBoxPanel();
274: addCheckBoxPanel(currentCheckBoxPanel);
275: }
276: IpeUtils.requestFocus(getCheckBoxes()[0]);
277:
278: // Preset certain libs if x-designer
279: if (target.containsXdFiles()) {
280: stdLibFlags.motif.setUsed(true);
281: stdLibFlags.socketnsl.setUsed(true);
282: stdLibFlags.genlib.setUsed(true);
283: }
284:
285: // Set checkboxes according to data
286: for (int i = 0; i < stdLibs.length; i++) {
287: getCheckBoxes()[i].setSelected(stdLibs[i].isUsed());
288: }
289:
290: // Link Mode
291: linkModeCB.removeAllItems();
292: if (getMakefileData().getToolset() == MakefileData.SUN_TOOLSET_TYPE) {
293: linkModeCB.addItem(getString("CB_Static_Sun")); // NOI18N
294: linkModeCB.addItem(getString("CB_Dynamic_Sun")); // NOI18N
295: } else {
296: linkModeCB.addItem(getString("CB_Static_GNU")); // NOI18N
297: linkModeCB.addItem(getString("CB_Dynamic_GNU")); // NOI18N
298: }
299: linkModeCB.setSelectedIndex(stdLibFlags.getLinkType());
300:
301: super .addNotify();
302: }
303:
304: /** Get the data from the panel and update the target */
305: public void removeNotify() {
306: super .removeNotify();
307:
308: TargetData target = getMakefileData().getTarget(key);
309: StdLibFlags stdLibFlags = target.getStdLibFlags();
310:
311: StdLib[] stdLibs;
312: if (getMakefileData().getMakefileOS() == MakefileData.SOLARIS_OS_TYPE) {
313: stdLibs = stdLibFlags.getSolarisStdLibs();
314: } else if (getMakefileData().getMakefileOS() == MakefileData.MACOSX_OS_TYPE) {
315: stdLibs = stdLibFlags.getMacOSXStdLibs();
316: } else {
317: stdLibs = stdLibFlags.getLinuxStdLibs();
318: }
319: for (int i = 0; i < stdLibs.length; i++) {
320: stdLibs[i].setUsed(getCheckBoxes()[i].isSelected());
321: }
322:
323: // Link Mode
324: stdLibFlags.setLinkType(linkModeCB.getSelectedIndex());
325: }
326: }
|