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-2006 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.apisupport.project.ui.customizer;
043:
044: import java.awt.EventQueue;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import org.netbeans.modules.apisupport.project.ui.UIUtil;
048: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
049: import org.openide.NotifyDescriptor;
050: import org.openide.modules.SpecificationVersion;
051: import org.openide.util.NbBundle;
052:
053: /**
054: * Represents <em>Sources</em> panel in Netbeans Module customizer.
055: *
056: * @author mkrauskopf
057: */
058: final class CustomizerSources extends NbPropertyPanel.Single {
059:
060: private boolean srcLevelValueBeingUpdated;
061:
062: CustomizerSources(final SingleModuleProperties props,
063: ProjectCustomizer.Category category) {
064: super (props, CustomizerSources.class, category);
065: initComponents();
066: initAccessibility();
067: refresh();
068: srcLevelValue.addActionListener(new ActionListener() { // #66278
069: public void actionPerformed(ActionEvent e) {
070: if (srcLevelValueBeingUpdated) {
071: return;
072: }
073: final String oldLevel = getProperty(SingleModuleProperties.JAVAC_SOURCE);
074: final String newLevel = (String) srcLevelValue
075: .getSelectedItem();
076: SpecificationVersion jdk5 = new SpecificationVersion(
077: "1.5"); // NOI18N
078: if (new SpecificationVersion(oldLevel)
079: .compareTo(jdk5) < 0
080: && new SpecificationVersion(newLevel)
081: .compareTo(jdk5) >= 0) {
082: EventQueue.invokeLater(new Runnable() { // wait for combo to close, at least
083: public void run() {
084: if (!UIUtil
085: .showAcceptCancelDialog(
086: getMessage("CustomizerSources.title.enable_lint"),
087: getMessage("CustomizerSources.text.enable_lint"),
088: getMessage("CustomizerSources.button.enable_lint"),
089: getMessage("CustomizerSources.button.skip_lint"),
090: NotifyDescriptor.QUESTION_MESSAGE)) {
091: return;
092: }
093: String options = getProperty(SingleModuleProperties.JAVAC_COMPILERARGS);
094: String added = "-Xlint -Xlint:-serial"; // NOI18N
095: if (options == null
096: || options.length() == 0) {
097: options = added;
098: } else {
099: options = options + " "
100: + added; // NOI18N
101: }
102: setProperty(
103: SingleModuleProperties.JAVAC_COMPILERARGS,
104: options);
105: }
106: });
107: }
108: }
109: });
110: }
111:
112: void refresh() {
113: if (getProperties().getSuiteDirectoryPath() == null) {
114: moduleSuite.setVisible(false);
115: moduleSuiteValue.setVisible(false);
116: } else {
117: UIUtil.setText(moduleSuiteValue, getProperties()
118: .getSuiteDirectoryPath());
119: }
120: assert !srcLevelValueBeingUpdated;
121: srcLevelValueBeingUpdated = true;
122: try {
123: srcLevelValue.removeAllItems();
124: for (int i = 0; i < SingleModuleProperties.SOURCE_LEVELS.length; i++) {
125: srcLevelValue
126: .addItem(SingleModuleProperties.SOURCE_LEVELS[i]);
127: }
128: srcLevelValue
129: .setSelectedItem(getProperty(SingleModuleProperties.JAVAC_SOURCE));
130: } finally {
131: srcLevelValueBeingUpdated = false;
132: }
133: UIUtil.setText(prjFolderValue, getProperties()
134: .getProjectDirectory());
135: }
136:
137: public void store() {
138: setProperty(SingleModuleProperties.JAVAC_SOURCE,
139: (String) srcLevelValue.getSelectedItem());
140: }
141:
142: /** This method is called from within the constructor to
143: * initialize the form.
144: * WARNING: Do NOT modify this code. The content of this method is
145: * always regenerated by the Form Editor.
146: */
147: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
148: private void initComponents() {
149: java.awt.GridBagConstraints gridBagConstraints;
150:
151: prjFolder = new javax.swing.JLabel();
152: srcLevel = new javax.swing.JLabel();
153: srcLevelValue = new javax.swing.JComboBox();
154: filler = new javax.swing.JLabel();
155: prjFolderValue = new javax.swing.JTextField();
156: moduleSuite = new javax.swing.JLabel();
157: moduleSuiteValue = new javax.swing.JTextField();
158:
159: setLayout(new java.awt.GridBagLayout());
160:
161: prjFolder.setLabelFor(prjFolderValue);
162: org.openide.awt.Mnemonics.setLocalizedText(prjFolder,
163: org.openide.util.NbBundle.getMessage(
164: CustomizerSources.class, "LBL_ProjectFolder"));
165: gridBagConstraints = new java.awt.GridBagConstraints();
166: gridBagConstraints.gridx = 0;
167: gridBagConstraints.gridy = 0;
168: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
169: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
170: add(prjFolder, gridBagConstraints);
171:
172: srcLevel.setLabelFor(srcLevelValue);
173: org.openide.awt.Mnemonics.setLocalizedText(srcLevel,
174: org.openide.util.NbBundle.getMessage(
175: CustomizerSources.class, "LBL_SourceLevel"));
176: gridBagConstraints = new java.awt.GridBagConstraints();
177: gridBagConstraints.gridx = 0;
178: gridBagConstraints.gridy = 2;
179: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
180: gridBagConstraints.insets = new java.awt.Insets(18, 0, 0, 12);
181: add(srcLevel, gridBagConstraints);
182:
183: srcLevelValue.setPrototypeDisplayValue("mmm");
184: gridBagConstraints = new java.awt.GridBagConstraints();
185: gridBagConstraints.gridx = 1;
186: gridBagConstraints.gridy = 2;
187: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
188: gridBagConstraints.insets = new java.awt.Insets(18, 0, 0, 0);
189: add(srcLevelValue, gridBagConstraints);
190:
191: gridBagConstraints = new java.awt.GridBagConstraints();
192: gridBagConstraints.gridx = 0;
193: gridBagConstraints.gridy = 3;
194: gridBagConstraints.weighty = 1.0;
195: add(filler, gridBagConstraints);
196:
197: prjFolderValue.setEditable(false);
198: gridBagConstraints = new java.awt.GridBagConstraints();
199: gridBagConstraints.gridx = 1;
200: gridBagConstraints.gridy = 0;
201: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
202: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
203: gridBagConstraints.weightx = 1.0;
204: add(prjFolderValue, gridBagConstraints);
205:
206: moduleSuite.setLabelFor(moduleSuiteValue);
207: org.openide.awt.Mnemonics.setLocalizedText(moduleSuite,
208: org.openide.util.NbBundle.getMessage(
209: CustomizerSources.class, "LBL_ModeleSuite"));
210: gridBagConstraints = new java.awt.GridBagConstraints();
211: gridBagConstraints.gridx = 0;
212: gridBagConstraints.gridy = 1;
213: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
214: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 12);
215: add(moduleSuite, gridBagConstraints);
216:
217: moduleSuiteValue.setEditable(false);
218: gridBagConstraints = new java.awt.GridBagConstraints();
219: gridBagConstraints.gridx = 1;
220: gridBagConstraints.gridy = 1;
221: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
222: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
223: gridBagConstraints.weightx = 1.0;
224: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
225: add(moduleSuiteValue, gridBagConstraints);
226:
227: }
228:
229: // </editor-fold>//GEN-END:initComponents
230:
231: // Variables declaration - do not modify//GEN-BEGIN:variables
232: private javax.swing.JLabel filler;
233: private javax.swing.JLabel moduleSuite;
234: private javax.swing.JTextField moduleSuiteValue;
235: private javax.swing.JLabel prjFolder;
236: private javax.swing.JTextField prjFolderValue;
237: private javax.swing.JLabel srcLevel;
238: private javax.swing.JComboBox srcLevelValue;
239:
240: // End of variables declaration//GEN-END:variables
241:
242: private static String getMessage(String key) {
243: return NbBundle.getMessage(CustomizerSources.class, key);
244: }
245:
246: private void initAccessibility() {
247: srcLevelValue.getAccessibleContext().setAccessibleDescription(
248: getMessage("ACS_SrcLevelValue"));
249: moduleSuiteValue.getAccessibleContext()
250: .setAccessibleDescription(
251: getMessage("ACS_ModuleSuiteValue"));
252: prjFolderValue.getAccessibleContext().setAccessibleDescription(
253: getMessage("ACS_PrjFolderValue"));
254: }
255:
256: }
|