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.j2me.cdc.project.nokiaS80;
043:
044: import java.io.File;
045: import javax.swing.JFileChooser;
046: import javax.swing.JPanel;
047: import javax.swing.JTextField;
048: import javax.swing.filechooser.FileFilter;
049: import org.netbeans.api.mobility.project.ui.customizer.ProjectProperties;
050: import org.netbeans.spi.mobility.project.ui.customizer.CustomizerPanel;
051: import org.netbeans.spi.mobility.project.ui.customizer.VisualPropertyGroup;
052: import org.netbeans.spi.mobility.project.ui.customizer.support.VisualPropertySupport;
053: import org.openide.filesystems.FileUtil;
054: import org.openide.util.NbBundle;
055:
056: /**
057: *
058: * @author suchys
059: */
060: public class NokiaS80ProjectCategoryCustomizer extends JPanel implements
061: CustomizerPanel, VisualPropertyGroup {
062:
063: private static String[] PROPERTY_NAMES = new String[] { NokiaPropertiesDescriptor.NOKIA_APP_ICON };
064:
065: private VisualPropertySupport vps;
066: private String projectDir = ""; //NOI18N
067:
068: /** Creates new form SavaJeProjectCategoryCustomizer */
069: public NokiaS80ProjectCategoryCustomizer() {
070: initComponents();
071: }
072:
073: public void initValues(ProjectProperties props, String configuration) {
074: vps = VisualPropertySupport.getDefault(props);
075: vps.register(jCheckBox1, configuration, this );
076: projectDir = FileUtil.toFile(props.getProjectDirectory())
077: .getAbsolutePath();
078: }
079:
080: public String[] getGroupPropertyNames() {
081: return PROPERTY_NAMES;
082: }
083:
084: public void initGroupValues(boolean useDefault) {
085: vps.register(applicationIcon,
086: NokiaPropertiesDescriptor.NOKIA_APP_ICON, useDefault);
087: jLabel3.setEnabled(!useDefault);
088: browseIcon.setEnabled(!useDefault);
089: }
090:
091: /** This method is called from within the constructor to
092: * initialize the form.
093: * WARNING: Do NOT modify this code. The content of this method is
094: * always regenerated by the Form Editor.
095: */
096: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
097: private void initComponents() {
098:
099: jLabel3 = new javax.swing.JLabel();
100: applicationIcon = new javax.swing.JTextField();
101: browseIcon = new javax.swing.JButton();
102: jCheckBox1 = new javax.swing.JCheckBox();
103:
104: jLabel3.setLabelFor(applicationIcon);
105: org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
106: org.openide.util.NbBundle.getMessage(
107: NokiaS80ProjectCategoryCustomizer.class,
108: "LBL_AppIcon")); // NOI18N
109:
110: org.openide.awt.Mnemonics.setLocalizedText(browseIcon,
111: org.openide.util.NbBundle.getMessage(
112: NokiaS80ProjectCategoryCustomizer.class,
113: "LBL_Browse")); // NOI18N
114: browseIcon
115: .addActionListener(new java.awt.event.ActionListener() {
116: public void actionPerformed(
117: java.awt.event.ActionEvent evt) {
118: browseIconActionPerformed(evt);
119: }
120: });
121:
122: org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, NbBundle
123: .getMessage(NokiaS80ProjectCategoryCustomizer.class,
124: "LBL_UseDefault")); // NOI18N
125: jCheckBox1.setBorder(javax.swing.BorderFactory
126: .createEmptyBorder(0, 0, 0, 0));
127: jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
128:
129: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
130: this );
131: this .setLayout(layout);
132: layout
133: .setHorizontalGroup(layout
134: .createParallelGroup(
135: org.jdesktop.layout.GroupLayout.LEADING)
136: .add(
137: layout
138: .createSequentialGroup()
139: .addContainerGap()
140: .add(
141: layout
142: .createParallelGroup(
143: org.jdesktop.layout.GroupLayout.LEADING)
144: .add(
145: layout
146: .createSequentialGroup()
147: .add(
148: jLabel3)
149: .addPreferredGap(
150: org.jdesktop.layout.LayoutStyle.RELATED)
151: .add(
152: applicationIcon,
153: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
154: 237,
155: Short.MAX_VALUE)
156: .addPreferredGap(
157: org.jdesktop.layout.LayoutStyle.RELATED)
158: .add(
159: browseIcon,
160: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
161: 69,
162: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
163: .add(jCheckBox1))
164: .addContainerGap()));
165: layout
166: .setVerticalGroup(layout
167: .createParallelGroup(
168: org.jdesktop.layout.GroupLayout.LEADING)
169: .add(
170: layout
171: .createSequentialGroup()
172: .addContainerGap()
173: .add(jCheckBox1)
174: .add(14, 14, 14)
175: .add(
176: layout
177: .createParallelGroup(
178: org.jdesktop.layout.GroupLayout.BASELINE)
179: .add(
180: applicationIcon,
181: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
182: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
183: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
184: .add(browseIcon)
185: .add(jLabel3))
186: .addContainerGap(253,
187: Short.MAX_VALUE)));
188:
189: applicationIcon.getAccessibleContext().setAccessibleName(
190: org.openide.util.NbBundle.getMessage(
191: NokiaS80ProjectCategoryCustomizer.class,
192: "ASCN_CustomizerNokia_AppIcon")); // NOI18N
193: applicationIcon
194: .getAccessibleContext()
195: .setAccessibleDescription(
196: org.openide.util.NbBundle
197: .getMessage(
198: NokiaS80ProjectCategoryCustomizer.class,
199: "ASCD_CustomizerNokia_AppIcon")); // NOI18N
200: browseIcon.getAccessibleContext().setAccessibleName(
201: org.openide.util.NbBundle.getMessage(
202: NokiaS80ProjectCategoryCustomizer.class,
203: "ASCN_CustomizerNokia_Browse")); // NOI18N
204: browseIcon.getAccessibleContext().setAccessibleDescription(
205: org.openide.util.NbBundle.getMessage(
206: NokiaS80ProjectCategoryCustomizer.class,
207: "ASCD_CustomizerNokia_Browse")); // NOI18N
208:
209: getAccessibleContext().setAccessibleName(
210: org.openide.util.NbBundle.getMessage(
211: NokiaS80ProjectCategoryCustomizer.class,
212: "ASCN_CustomizerNokia")); // NOI18N
213: getAccessibleContext().setAccessibleDescription(
214: org.openide.util.NbBundle.getMessage(
215: NokiaS80ProjectCategoryCustomizer.class,
216: "ASCD_CustomizerNokia")); // NOI18N
217: }// </editor-fold>//GEN-END:initComponents
218:
219: private void browseIconActionPerformed(
220: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseIconActionPerformed
221: chooseIcon(applicationIcon);
222: }//GEN-LAST:event_browseIconActionPerformed
223:
224: // Variables declaration - do not modify//GEN-BEGIN:variables
225: private javax.swing.JTextField applicationIcon;
226: private javax.swing.JButton browseIcon;
227: private javax.swing.JCheckBox jCheckBox1;
228: private javax.swing.JLabel jLabel3;
229:
230: // End of variables declaration//GEN-END:variables
231:
232: private void chooseIcon(JTextField field) {
233: JFileChooser chooser = new JFileChooser();
234: FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
235: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
236: chooser.setMultiSelectionEnabled(false);
237: chooser.setFileFilter(new FileFilter() {
238: public boolean accept(File f) {
239: if (f.isDirectory())
240: return true;
241: String ext = f.toString().toLowerCase();
242: int i = ext.lastIndexOf('.');
243: if (i != -1) {
244: ext = ext.substring(i + 1);
245: }
246: if (ext.equalsIgnoreCase("gif")
247: || ext.equalsIgnoreCase("png")) { //NOI18N
248: return true;
249: }
250: return false;
251: }
252:
253: public String getDescription() {
254: return NbBundle.getMessage(
255: NokiaS80ProjectCategoryCustomizer.class,
256: "LBL_LogoImageFiles");
257: }
258: });
259: String workDir = field.getText();
260: if (workDir.trim().length() == 0)
261: workDir = projectDir;
262: chooser.setSelectedFile(new File(workDir));
263: chooser.setDialogTitle(NbBundle.getMessage(
264: NokiaS80ProjectCategoryCustomizer.class,
265: "TITLE_BrowseLogo"));
266: if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this )) { //NOI18N
267: File file = FileUtil.normalizeFile(chooser
268: .getSelectedFile());
269: field.setText(file.getAbsolutePath());
270: }
271: }
272: }
|