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.io.File;
046: import java.util.LinkedList;
047: import javax.swing.DefaultListModel;
048: import javax.swing.JLabel;
049: import javax.swing.JPanel;
050: import javax.swing.JTextField;
051: import org.netbeans.modules.cnd.makewizard.EnterItemsPanel.ErrorInfo;
052: import org.netbeans.modules.cnd.makewizard.EnterItemsPanel.ListItem;
053: import org.openide.util.NbBundle;
054:
055: /**
056: * Create the user libraries panel in the Makefile wizard.
057: */
058:
059: public class UserLibsPanel extends EnterItemsPanel {
060:
061: /** Serial version number */
062: static final long serialVersionUID = 3971722083122307369L;
063:
064: private int key;
065: private boolean initialized;
066:
067: private JPanel stdLibPanel = null;
068: private JTextField stdLibsText;
069: private JLabel stdLibsLabel = null;
070: private boolean stdLibPanelAdded = false;
071:
072: /**
073: * Constructor for the Makefile sources panel. Remember, most of the panel
074: * is inherited from WizardDescriptor.
075: */
076: UserLibsPanel(MakefileWizard wd) {
077: super (wd);
078: String subtitle = new String(getString("LBL_UserLibsPanel")); // NOI18N
079: setSubTitle(subtitle);
080: this .getAccessibleContext().setAccessibleDescription(subtitle);
081: initialized = false;
082: }
083:
084: /** Defer widget creation until the panel needs to be displayed */
085: private void create() {
086: create(getString("LBL_UserLibs"), getString("MNEM_UserLibs")
087: .charAt(0), // NOI18N
088: DYNAMIC_DEFAULT_BUTTONS | ADD_BEGINNING);
089:
090: // Create (read-only) system libs textfield. Dynamically add it if target is complex exeutable.
091: GridBagConstraints gridBagConstraints;
092:
093: stdLibPanel = new javax.swing.JPanel();
094: stdLibPanel.setLayout(new java.awt.GridBagLayout());
095:
096: stdLibsLabel = new javax.swing.JLabel();
097: gridBagConstraints = new java.awt.GridBagConstraints();
098: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
099: stdLibPanel.add(stdLibsLabel, gridBagConstraints);
100:
101: stdLibsText = new javax.swing.JTextField();
102: stdLibsLabel.setLabelFor(stdLibsText);
103: stdLibsText.setEditable(false);
104: stdLibsText.setFocusable(false);
105: gridBagConstraints = new java.awt.GridBagConstraints();
106: gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
107: gridBagConstraints.gridheight = 1;
108: gridBagConstraints.gridx = 0;
109: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
110: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
111: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
112: gridBagConstraints.weightx = 1.0;
113: stdLibPanel.add(stdLibsText, gridBagConstraints);
114: }
115:
116: /**
117: * Dynamically add stdLibs panel (only for complex executables)
118: */
119: private void addStdLibPanel() {
120: if (!stdLibPanelAdded) {
121: GridBagConstraints grid = new GridBagConstraints();
122: grid.anchor = GridBagConstraints.NORTHWEST;
123: grid.gridx = 0;
124: grid.gridwidth = GridBagConstraints.REMAINDER;
125: grid.gridheight = 1;
126: grid.weightx = 1.0;
127: grid.weighty = 0.0;
128: grid.fill = java.awt.GridBagConstraints.HORIZONTAL;
129: grid.insets.top = 11;
130:
131: addComponent(stdLibPanel, grid);
132: stdLibPanelAdded = true;
133: }
134: }
135:
136: /**
137: * Dynamically remove stdLibs panel (only for complex executables)
138: */
139: private void removeStdLibPanel() {
140: if (stdLibPanelAdded) {
141: remove(stdLibPanel);
142: stdLibPanelAdded = false;
143: }
144: }
145:
146: /** Set the label for the Source List */
147: protected String getListLabel() {
148: return getString("LBL_LibraryList"); // NOI18N
149: }
150:
151: /** Set the mnemonic for the Source List */
152: protected char getListMnemonic() {
153: return getString("MNEM_LibraryList").charAt(0); // NOI18N
154: }
155:
156: /**
157: * Check the input and remove any invalid syntax. If the text starts with
158: * any option other than -L, -l, or -B ignore the option. Any token which
159: * doesn't start with a - is treated as a file and acceted.
160: *
161: * @param token The raw input as typed by the user
162: * @return The validated (and possibly modified) string or null
163: */
164: protected String validateInput(String token) {
165:
166: if (token.charAt(0) == '-') {
167: char c = token.charAt(1);
168:
169: if (c == 'L' || c == 'l' || c == 'B') {
170: return token;
171: } else {
172: return null;
173: }
174: } else {
175: return token;
176: }
177: }
178:
179: /**
180: * Check for an error. Its not an error as long as any items are in the list. We
181: * don't care if something ``exists'' because it might be an alternative library
182: * specification.
183: *
184: * @param tcount The number of tokens
185: * @param list The list of token matches
186: * @param nefiles True if non existant files were specified or matched
187: */
188: protected boolean checkErrorConditions(int tcount, LinkedList list,
189: boolean nefiles) {
190: return tcount == 1 && list.size() == 0;
191: }
192:
193: /** Get the title and message for the error dialog */
194: protected ErrorInfo getErrorInfo() {
195: return new ErrorInfo(getString("DLG_ULP_EmptyRE"), // NOI18N
196: getString("MSG_NoFilesMatched")); // NOI18N
197: }
198:
199: /**
200: * Overridden from EnterItemsPanel
201: * Scan all entered items, and add -l to the ones that looks like system libraries
202: */
203: protected void addMultipleFiles(Object[] objects) {
204: for (int i = 0; i < objects.length; i++) {
205: if (!(objects[i] instanceof ListItem))
206: continue;
207: ListItem item = (ListItem) objects[i];
208: String name = item.getName();
209: if (name.length() == 0)
210: continue;
211: if (name.charAt(0) == '-')
212: continue;
213: if (name.charAt(0) == '$')
214: continue;
215: if (name.indexOf(File.separator) >= 0)
216: continue;
217: if (name.endsWith(".a") || name.endsWith(".so")
218: || name.endsWith(".dylib") || name.endsWith(".dll")) // NOI18N
219: continue;
220:
221: // it is most likely a standard libray. Prefix it with "-l".
222: item.setName("-l" + name); // NOI18N
223: }
224: super .addMultipleFiles(objects);
225: }
226:
227: /** Create and initialized the widgets */
228: public void addNotify() {
229: TargetData target = getMakefileData().getCurrentTarget();
230: int targetType = target.getTargetType();
231: key = target.getKey();
232:
233: if (!initialized) {
234: create();
235: initialized = true;
236: }
237:
238: if (targetType == TargetData.COMPLEX_EXECUTABLE) {
239: }
240:
241: // Set text in read-only stdlibs textfield and change the label
242: if (targetType == TargetData.COMPLEX_EXECUTABLE) {
243: MakeVarName var = new MakeVarName();
244: var.setTargetName(target.getName());
245: String s = var.makeRef("SYSLIBS_"); // NOI18N
246:
247: // If new, add $(SYSLIBS_...) to list
248: if (target.getUserLibsList() == null) {
249: target.setUserLibsList(new String[] { s });
250: }
251:
252: // Get set of sys libraries, and set the text in the read-only text field
253: StdLibFlags flags = target.getStdLibFlags();
254: int os = getMakefileData().getMakefileOS();
255: int toolset = getMakefileData().getToolset();
256: String txt = flags.getSysLibFlags(toolset, os,
257: getMakefileData().getCompilerFlags().is64Bit(),
258: target);
259: stdLibsText.setText(txt);
260: stdLibsText.setToolTipText(txt);
261:
262: // Change the label to include correct target
263: String ltxt = NbBundle.getMessage(UserLibsPanel.class,
264: "LBL_SYSLIB", s); // NOI18N
265: stdLibsLabel.setText(ltxt);
266:
267: addStdLibPanel();
268: } else {
269: removeStdLibPanel();
270: }
271:
272: // Initialize the list. First, remove any from the JList. Then, add any
273: // entries from the target into the JList.
274: DefaultListModel model = (DefaultListModel) getList()
275: .getModel();
276: model.removeAllElements();
277: String[] slist = target.getUserLibsList();
278: if (slist != null) {
279: for (int i = 0; i < slist.length; i++) {
280: model.addElement(slist[i]);
281: }
282: }
283:
284: super .addNotify();
285: }
286:
287: /** Get the data from the panel and update the target */
288: public void removeNotify() {
289: super .removeNotify();
290:
291: TargetData target = getMakefileData().getTarget(key);
292: target.setUserLibsList(getListItems());
293: }
294: }
|