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.compapp.projects.jbi.ui.customizer;
043:
044: import java.awt.Component;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import java.io.File;
048: import java.nio.charset.Charset;
049: import java.nio.charset.CharsetDecoder;
050: import java.nio.charset.CharsetEncoder;
051: import java.nio.charset.IllegalCharsetNameException;
052: import java.util.logging.Logger;
053: import javax.swing.DefaultComboBoxModel;
054: import javax.swing.JLabel;
055: import javax.swing.JList;
056:
057: import javax.swing.JPanel;
058: import javax.swing.ListCellRenderer;
059: import javax.swing.plaf.UIResource;
060:
061: import org.openide.filesystems.FileObject;
062: import org.openide.filesystems.FileUtil;
063:
064: import org.openide.util.HelpCtx;
065: import org.openide.util.NbBundle;
066:
067: /** Customizer for general project attributes.
068: *
069: * @author phrebejk
070: */
071: public class CustomizerGeneral extends JPanel implements
072: JbiJarCustomizer.Panel, HelpCtx.Provider {
073:
074: private JbiProjectProperties projProperties;
075: private VisualPropertySupport vps;
076:
077: // private String originalEncoding;
078:
079: /** Creates new form CustomizerCompile */
080: public CustomizerGeneral(JbiProjectProperties projProperties) {
081: initComponents();
082: this .getAccessibleContext().setAccessibleDescription(
083: NbBundle.getMessage(CustomizerGeneral.class,
084: "ACS_CustomizeGeneral_A11YDesc")); // NOI18N
085:
086: this .projProperties = projProperties;
087: vps = new VisualPropertySupport(projProperties);
088:
089: // this.originalEncoding = this.projProperties.getProject().evaluator().
090: // getProperty(JbiProjectProperties.SOURCE_ENCODING);
091: // if (this.originalEncoding == null) {
092: // this.originalEncoding = Charset.defaultCharset().name();
093: // }
094: //
095: // this.encoding.setModel(new EncodingModel(this.originalEncoding));
096: // this.encoding.setRenderer(new EncodingRenderer());
097: //
098: // this.encoding.addActionListener(new ActionListener () {
099: // public void actionPerformed(ActionEvent arg0) {
100: // handleEncodingChange();
101: // }
102: // });
103: }
104:
105: // private void handleEncodingChange() {
106: // Charset enc = (Charset) encoding.getSelectedItem();
107: // String encName;
108: // if (enc != null) {
109: // encName = enc.name();
110: // } else {
111: // encName = originalEncoding;
112: // }
113: // //this.projProperties.putAdditionalProperty(JbiProjectProperties.SOURCE_ENCODING, encName);
114: // this.projProperties.put(JbiProjectProperties.SOURCE_ENCODING, encName);
115: // }
116:
117: public void initValues() {
118: FileObject projectFolder = projProperties.getProject()
119: .getProjectDirectory();
120: File pf = FileUtil.toFile(projectFolder);
121: jTextFieldProjectFolder.setText(pf == null ? "" : pf.getPath()); // NOI18N
122:
123: vps.register(jTextFieldServiceAssemblyDescription,
124: JbiProjectProperties.SERVICE_ASSEMBLY_DESCRIPTION);
125: vps.register(jTextFieldServiceUnitDescription,
126: JbiProjectProperties.SERVICE_UNIT_DESCRIPTION);
127:
128: String originalEncoding = projProperties.getProject()
129: .evaluator().getProperty(
130: JbiProjectProperties.SOURCE_ENCODING);
131: if (originalEncoding == null) {
132: originalEncoding = Charset.defaultCharset().name();
133: }
134: vps.register(jComboBoxEncoding, new EncodingModel(
135: originalEncoding), new EncodingRenderer(),
136: JbiProjectProperties.SOURCE_ENCODING, Charset.class);
137: }
138:
139: private static class EncodingRenderer extends JLabel implements
140: ListCellRenderer, UIResource {
141:
142: public EncodingRenderer() {
143: setOpaque(true);
144: }
145:
146: public Component getListCellRendererComponent(JList list,
147: Object value, int index, boolean isSelected,
148: boolean cellHasFocus) {
149: assert value instanceof Charset;
150: setName("ComboBox.listRenderer"); // NOI18N
151: setText(((Charset) value).displayName());
152: setIcon(null);
153: if (isSelected) {
154: setBackground(list.getSelectionBackground());
155: setForeground(list.getSelectionForeground());
156: } else {
157: setBackground(list.getBackground());
158: setForeground(list.getForeground());
159: }
160: return this ;
161: }
162:
163: @Override
164: public String getName() {
165: String name = super .getName();
166: return name == null ? "ComboBox.renderer" : name; // NOI18N
167: }
168:
169: }
170:
171: private static class EncodingModel extends DefaultComboBoxModel {
172:
173: public EncodingModel(String originalEncoding) {
174: Charset defEnc = null;
175: for (Charset c : Charset.availableCharsets().values()) {
176: if (c.name().equals(originalEncoding)) {
177: defEnc = c;
178: }
179: addElement(c);
180: }
181: if (defEnc == null) {
182: //Create artificial Charset to keep the original value
183: //May happen when the project was set up on the platform
184: //which supports more encodings
185: try {
186: defEnc = new UnknownCharset(originalEncoding);
187: addElement(defEnc);
188: } catch (IllegalCharsetNameException e) {
189: //The source.encoding property is completely broken
190: Logger.getLogger(this .getClass().getName()).info(
191: "IllegalCharsetName: " + originalEncoding); // NOI18N
192: }
193: }
194: if (defEnc == null) {
195: defEnc = Charset.defaultCharset();
196: }
197: setSelectedItem(defEnc);
198: }
199: }
200:
201: private static class UnknownCharset extends Charset {
202:
203: UnknownCharset(String name) {
204: super (name, new String[0]);
205: }
206:
207: public boolean contains(Charset c) {
208: throw new UnsupportedOperationException();
209: }
210:
211: public CharsetDecoder newDecoder() {
212: throw new UnsupportedOperationException();
213: }
214:
215: public CharsetEncoder newEncoder() {
216: throw new UnsupportedOperationException();
217: }
218: }
219:
220: /** This method is called from within the constructor to
221: * initialize the form.
222: * WARNING: Do NOT modify this code. The content of this method is
223: * always regenerated by the Form Editor.
224: */
225: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
226: private void initComponents() {
227:
228: jLabelProjectName = new javax.swing.JLabel();
229: jLabelServiceAssemblyDescription = new javax.swing.JLabel();
230: jTextFieldServiceAssemblyDescription = new javax.swing.JTextField();
231: jLabelServiceUnitDescription = new javax.swing.JLabel();
232: jTextFieldServiceUnitDescription = new javax.swing.JTextField();
233: jTextFieldProjectFolder = new javax.swing.JTextField();
234: jLabel1 = new javax.swing.JLabel();
235: jLabel2 = new javax.swing.JLabel();
236: jComboBoxEncoding = new javax.swing.JComboBox();
237:
238: setBorder(javax.swing.BorderFactory.createEtchedBorder());
239:
240: jLabelProjectName.setLabelFor(jTextFieldProjectFolder);
241: org.openide.awt.Mnemonics.setLocalizedText(jLabelProjectName,
242: org.openide.util.NbBundle.getMessage(
243: CustomizerGeneral.class,
244: "LBL_CustomizeGeneral_ProjectFolder_JLabel")); // NOI18N
245:
246: jLabelServiceAssemblyDescription
247: .setLabelFor(jTextFieldServiceAssemblyDescription);
248: org.openide.awt.Mnemonics
249: .setLocalizedText(
250: jLabelServiceAssemblyDescription,
251: org.openide.util.NbBundle
252: .getMessage(CustomizerGeneral.class,
253: "LBL_CustomizeGeneral_AssemblyUnitDescription_JLabel")); // NOI18N
254:
255: jLabelServiceUnitDescription
256: .setLabelFor(jTextFieldServiceUnitDescription);
257: org.openide.awt.Mnemonics
258: .setLocalizedText(
259: jLabelServiceUnitDescription,
260: org.openide.util.NbBundle
261: .getMessage(CustomizerGeneral.class,
262: "LBL_CustomizeGeneral_ApplicationSubAssemblyDescription_JLabel")); // NOI18N
263:
264: jTextFieldProjectFolder.setEditable(false);
265:
266: org.openide.awt.Mnemonics.setLocalizedText(jLabel1, "jLabel1");
267:
268: jLabel2.setLabelFor(jComboBoxEncoding);
269: org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
270: org.openide.util.NbBundle.getMessage(
271: CustomizerGeneral.class, "TXT_Encoding")); // NOI18N
272:
273: jComboBoxEncoding
274: .setModel(new javax.swing.DefaultComboBoxModel(
275: new String[] { "Item 1", "Item 2", "Item 3",
276: "Item 4" }));
277:
278: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
279: this );
280: this .setLayout(layout);
281: layout
282: .setHorizontalGroup(layout
283: .createParallelGroup(
284: org.jdesktop.layout.GroupLayout.LEADING)
285: .add(
286: layout
287: .createSequentialGroup()
288: .addContainerGap()
289: .add(
290: layout
291: .createParallelGroup(
292: org.jdesktop.layout.GroupLayout.LEADING,
293: false)
294: .add(
295: jLabel2,
296: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
297: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
298: Short.MAX_VALUE)
299: .add(
300: jLabelServiceUnitDescription,
301: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
302: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
303: Short.MAX_VALUE)
304: .add(
305: jLabelServiceAssemblyDescription,
306: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
307: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
308: Short.MAX_VALUE)
309: .add(
310: jLabelProjectName,
311: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
312: 164,
313: Short.MAX_VALUE))
314: .add(
315: layout
316: .createParallelGroup(
317: org.jdesktop.layout.GroupLayout.LEADING)
318: .add(
319: layout
320: .createSequentialGroup()
321: .add(
322: 4,
323: 4,
324: 4)
325: .add(
326: layout
327: .createParallelGroup(
328: org.jdesktop.layout.GroupLayout.LEADING)
329: .add(
330: org.jdesktop.layout.GroupLayout.TRAILING,
331: jTextFieldServiceUnitDescription,
332: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
333: 393,
334: Short.MAX_VALUE)
335: .add(
336: org.jdesktop.layout.GroupLayout.TRAILING,
337: jTextFieldServiceAssemblyDescription,
338: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
339: 393,
340: Short.MAX_VALUE)
341: .add(
342: jTextFieldProjectFolder,
343: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
344: 393,
345: Short.MAX_VALUE)))
346: .add(
347: layout
348: .createSequentialGroup()
349: .addPreferredGap(
350: org.jdesktop.layout.LayoutStyle.RELATED)
351: .add(
352: jComboBoxEncoding,
353: 0,
354: 393,
355: Short.MAX_VALUE)))
356: .addContainerGap()));
357: layout
358: .setVerticalGroup(layout
359: .createParallelGroup(
360: org.jdesktop.layout.GroupLayout.LEADING)
361: .add(
362: layout
363: .createSequentialGroup()
364: .addContainerGap()
365: .add(
366: layout
367: .createParallelGroup(
368: org.jdesktop.layout.GroupLayout.BASELINE)
369: .add(
370: jLabelProjectName,
371: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
372: 24,
373: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
374: .add(
375: jTextFieldProjectFolder,
376: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
377: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
378: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
379: .addPreferredGap(
380: org.jdesktop.layout.LayoutStyle.RELATED)
381: .add(
382: layout
383: .createParallelGroup(
384: org.jdesktop.layout.GroupLayout.BASELINE)
385: .add(
386: jTextFieldServiceAssemblyDescription,
387: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
388: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
389: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
390: .add(
391: jLabelServiceAssemblyDescription))
392: .addPreferredGap(
393: org.jdesktop.layout.LayoutStyle.RELATED)
394: .add(
395: layout
396: .createParallelGroup(
397: org.jdesktop.layout.GroupLayout.BASELINE)
398: .add(
399: jTextFieldServiceUnitDescription,
400: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
401: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
402: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
403: .add(
404: jLabelServiceUnitDescription))
405: .addPreferredGap(
406: org.jdesktop.layout.LayoutStyle.UNRELATED)
407: .add(
408: layout
409: .createParallelGroup(
410: org.jdesktop.layout.GroupLayout.BASELINE)
411: .add(jLabel2)
412: .add(
413: jComboBoxEncoding,
414: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
415: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
416: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
417: .addContainerGap(18,
418: Short.MAX_VALUE)));
419:
420: jLabelProjectName.getAccessibleContext()
421: .setAccessibleDescription(
422: org.openide.util.NbBundle.getMessage(
423: CustomizerGeneral.class,
424: "ACS_PROJECT_FOLDER")); // NOI18N
425: jLabelServiceAssemblyDescription.getAccessibleContext()
426: .setAccessibleDescription(
427: org.openide.util.NbBundle.getMessage(
428: CustomizerGeneral.class,
429: "ACS_SA_DESCRIPTION")); // NOI18N
430: java.util.ResourceBundle bundle = java.util.ResourceBundle
431: .getBundle("org/netbeans/modules/compapp/projects/jbi/ui/customizer/Bundle"); // NOI18N
432: jTextFieldServiceAssemblyDescription
433: .getAccessibleContext()
434: .setAccessibleDescription(
435: bundle
436: .getString("ACS_CustomizeGeneral_AssemblyUnitDescription_A11YDesc")); // NOI18N
437: jLabelServiceUnitDescription.getAccessibleContext()
438: .setAccessibleDescription(
439: org.openide.util.NbBundle.getMessage(
440: CustomizerGeneral.class,
441: "ACS_DEFAULT_SU_DESCRIPTION")); // NOI18N
442: jTextFieldServiceUnitDescription
443: .getAccessibleContext()
444: .setAccessibleDescription(
445: bundle
446: .getString("LBL_CustomizeGeneral_ApplicationSubAssemblyDescription_A11YDesc")); // NOI18N
447: jLabel2.getAccessibleContext().setAccessibleDescription(
448: org.openide.util.NbBundle.getMessage(
449: CustomizerGeneral.class, "ACS_ENCODING")); // NOI18N
450: }// </editor-fold>//GEN-END:initComponents
451:
452: // Variables declaration - do not modify//GEN-BEGIN:variables
453: private javax.swing.JComboBox jComboBoxEncoding;
454: private javax.swing.JLabel jLabel1;
455: private javax.swing.JLabel jLabel2;
456: private javax.swing.JLabel jLabelProjectName;
457: private javax.swing.JLabel jLabelServiceAssemblyDescription;
458: private javax.swing.JLabel jLabelServiceUnitDescription;
459: private javax.swing.JTextField jTextFieldProjectFolder;
460: private javax.swing.JTextField jTextFieldServiceAssemblyDescription;
461: private javax.swing.JTextField jTextFieldServiceUnitDescription;
462:
463: // End of variables declaration//GEN-END:variables
464:
465: /** Help context where to find more about the paste type action.
466: * @return the help context for this action
467: */
468: public HelpCtx getHelpCtx() {
469: return new HelpCtx(CustomizerGeneral.class);
470: }
471: }
|