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: /*
043: * AddAPIPanel.java
044: *
045: * Created on April 21, 2004, 2:12 PM
046: */
047: package org.netbeans.modules.mobility.project.ui.customizer;
048:
049: import java.awt.Component;
050: import java.awt.event.ActionListener;
051: import java.util.*;
052: import java.lang.ref.SoftReference;
053: import java.io.*;
054: import javax.swing.DefaultComboBoxModel;
055: import javax.swing.JTextField;
056: import javax.swing.event.DocumentListener;
057: import org.openide.DialogDescriptor;
058: import org.openide.filesystems.FileObject;
059: import org.openide.filesystems.Repository;
060: import org.openide.util.HelpCtx;
061: import org.openide.util.Utilities;
062:
063: /**
064: *
065: * @author dave
066: */
067: public class AddAPIPanel extends javax.swing.JPanel implements
068: ActionListener, DocumentListener {
069:
070: final private static String[] availableDefaultPermissions = {
071: "javax.microedition.amms.control.camera.enableShutterFeedback", //NOI18N
072: "javax.microedition.amms.control.tuner.setPreset", //NOI18N
073: "javax.microedition.apdu.aid", //NOI18N
074: "javax.microedition.apdu.sat", //NOI18N
075: "javax.microedition.content.ContentHandler", //NOI18N
076: "javax.microedition.io.Connector.bluetooth.client", //NOI18N
077: "javax.microedition.io.Connector.bluetooth.server", //NOI18N
078: "javax.microedition.io.Connector.cbs", //NOI18N
079: "javax.microedition.io.Connector.comm", //NOI18N
080: "javax.microedition.io.Connector.datagram", //NOI18N
081: "javax.microedition.io.Connector.datagramreceiver", //NOI18N
082: "javax.microedition.io.Connector.file.read", //NOI18N
083: "javax.microedition.io.Connector.file.write", //NOI18N
084: "javax.microedition.io.Connector.http", //NOI18N
085: "javax.microedition.io.Connector.https", //NOI18N
086: "javax.microedition.io.Connector.mms", //NOI18N
087: "javax.microedition.io.Connector.obex.client", //NOI18N
088: "javax.microedition.io.Connector.obex.client.tcp",
089: "javax.microedition.io.Connector.obex.server", //NOI18N
090: "javax.microedition.io.Connector.obex.server.tcp",
091: "javax.microedition.io.Connector.serversocket", //NOI18N
092: "javax.microedition.io.Connector.sip", //NOI18N
093: "javax.microedition.io.Connector.sips", //NOI18N
094: "javax.microedition.io.Connector.sms", //NOI18N
095: "javax.microedition.io.Connector.socket", //NOI18N
096: "javax.microedition.io.Connector.ssl", //NOI18N
097: "javax.microedition.io.PushRegistry", //NOI18N
098: "javax.microedition.jcrmi", //NOI18N
099: "javax.microedition.location.LandmarkStore.category", //NOI18N
100: "javax.microedition.location.LandmarkStore.management", //NOI18N
101: "javax.microedition.location.LandmarkStore.read", //NOI18N
102: "javax.microedition.location.LandmarkStore.write", //NOI18N
103: "javax.microedition.location.Location", //NOI18N
104: "javax.microedition.location.Orientation", //NOI18N
105: "javax.microedition.location.ProximityListener", //NOI18N
106: "javax.microedition.media.control.RecordControl", //NOI18N
107: "javax.microedition.media.control.VideoControl.getSnapshot", //NOI18N
108: "javax.microedition.payment.process", //NOI18N
109: "javax.microedition.pim.ContactList.read", //NOI18N
110: "javax.microedition.pim.ContactList.write", //NOI18N
111: "javax.microedition.pim.EventList.read", //NOI18N
112: "javax.microedition.pim.EventList.write", //NOI18N
113: "javax.microedition.pim.ToDoList.read", //NOI18N
114: "javax.microedition.pim.ToDoList.write", //NOI18N
115: "javax.microedition.securityservice.CMSMessageSignatureService", //NOI18N
116: "javax.wireless.messaging.cbs.receive", //NOI18N
117: "javax.wireless.messaging.mms.receive", //NOI18N
118: "javax.wireless.messaging.mms.send", //NOI18N
119: "javax.wireless.messaging.sms.receive", //NOI18N
120: "javax.wireless.messaging.sms.send" //NOI18N
121:
122: };
123:
124: private DialogDescriptor dd;
125: private static SoftReference permissions;
126:
127: /** Creates new form AddAPIPanel */
128: public AddAPIPanel(HashSet<String> set) {
129: initComponents();
130: initAccessibility();
131: String[] availablePermissions = getPermissions();
132: final Vector<String> v = new Vector<String>();
133: for (int a = 0; a < availablePermissions.length; a++)
134: if (!set.contains(availablePermissions[a]))
135: v.add(availablePermissions[a]);
136: combo.setModel(new DefaultComboBoxModel(v));
137: combo.getEditor().addActionListener(this );
138: Component comp = combo.getEditor().getEditorComponent();
139: if (comp instanceof JTextField)
140: ((JTextField) comp).getDocument().addDocumentListener(this );
141: }
142:
143: private static synchronized String[] getPermissions() {
144: String[] result = null;
145: if (permissions != null)
146: result = (String[]) permissions.get();
147: if (result == null) {
148: result = loadPermissions();
149: permissions = new SoftReference<String[]>(result);
150: }
151: return result;
152: }
153:
154: private static String[] loadPermissions() {
155: final FileObject fo = Repository.getDefault()
156: .getDefaultFileSystem().findResource(
157: "j2me/permissions.txt"); // NOI18N
158: if (fo != null) {
159: InputStream is = null;
160: try {
161: is = fo.getInputStream();
162: final BufferedReader reader = new BufferedReader(
163: new InputStreamReader(is));
164: try {
165: String s;
166: final List<String> l = new ArrayList<String>();
167: while ((s = reader.readLine()) != null)
168: l.add(s);
169: return l.toArray(new String[l.size()]);
170: } finally {
171: reader.close();
172: }
173: } catch (IOException e) {
174: }
175: }
176: return availableDefaultPermissions;
177: }
178:
179: public String getAPIName() {
180: return (String) combo.getEditor().getItem();
181: }
182:
183: protected void setDialogDescriptor(final DialogDescriptor desc) {
184: this .dd = desc;
185: dd.setHelpCtx(new HelpCtx(AddAPIPanel.class));
186: actionPerformed(null);
187: }
188:
189: private boolean isValidClassName(final String s) {
190: if (s.startsWith(".") || s.endsWith(".")) //NOI18N
191: return false;
192: final StringTokenizer stk = new StringTokenizer(s, "."); //NOI18N
193: while (stk.hasMoreTokens())
194: if (!Utilities.isJavaIdentifier(stk.nextToken()))
195: return false;
196: return true;
197: }
198:
199: public boolean isValid() {
200: if (getAPIName().length() == 0
201: || !isValidClassName(getAPIName())) {
202: errorPanel.setErrorBundleMessage("ERR_AddAPI_InvPackage");//NOI18N
203: return false;
204: }
205: errorPanel.setErrorBundleMessage(null);
206: return true;
207: }
208:
209: /** This method is called from within the constructor to
210: * initialize the form.
211: * WARNING: Do NOT modify this code. The content of this method is
212: * always regenerated by the Form Editor.
213: */
214: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
215: private void initComponents() {
216: java.awt.GridBagConstraints gridBagConstraints;
217:
218: jLabel1 = new javax.swing.JLabel();
219: combo = new javax.swing.JComboBox();
220: errorPanel = new org.netbeans.modules.mobility.project.ui.customizer.ErrorPanel();
221:
222: setLayout(new java.awt.GridBagLayout());
223:
224: jLabel1.setLabelFor(combo);
225: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
226: org.openide.util.NbBundle.getMessage(AddAPIPanel.class,
227: "LBL_AddAPI_API")); // NOI18N
228: gridBagConstraints = new java.awt.GridBagConstraints();
229: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
230: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 5);
231: add(jLabel1, gridBagConstraints);
232:
233: combo.setEditable(true);
234: combo.setMaximumSize(new java.awt.Dimension(300, 32767));
235: combo.setMinimumSize(new java.awt.Dimension(300, 23));
236: combo.setPreferredSize(new java.awt.Dimension(250, 23));
237: gridBagConstraints = new java.awt.GridBagConstraints();
238: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
239: gridBagConstraints.weightx = 1.0;
240: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12);
241: add(combo, gridBagConstraints);
242: gridBagConstraints = new java.awt.GridBagConstraints();
243: gridBagConstraints.gridx = 0;
244: gridBagConstraints.gridy = 1;
245: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
246: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
247: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
248: gridBagConstraints.weightx = 1.0;
249: gridBagConstraints.weighty = 1.0;
250: add(errorPanel, gridBagConstraints);
251: }// </editor-fold>//GEN-END:initComponents
252:
253: private void initAccessibility() {
254: getAccessibleContext().setAccessibleName(
255: org.openide.util.NbBundle.getMessage(AddAPIPanel.class,
256: "ACSN_AddAPI"));
257: getAccessibleContext().setAccessibleDescription(
258: org.openide.util.NbBundle.getMessage(AddAPIPanel.class,
259: "ACSD_AddAPI"));
260: }
261:
262: public void actionPerformed(@SuppressWarnings("unused")
263: final java.awt.event.ActionEvent e) {
264: dd.setValid(isValid());
265: }
266:
267: public void changedUpdate(@SuppressWarnings("unused")
268: final javax.swing.event.DocumentEvent e) {
269: actionPerformed(null);
270: }
271:
272: public void insertUpdate(@SuppressWarnings("unused")
273: final javax.swing.event.DocumentEvent e) {
274: actionPerformed(null);
275: }
276:
277: public void removeUpdate(@SuppressWarnings("unused")
278: final javax.swing.event.DocumentEvent e) {
279: actionPerformed(null);
280: }
281:
282: // Variables declaration - do not modify//GEN-BEGIN:variables
283: private javax.swing.JComboBox combo;
284: private org.netbeans.modules.mobility.project.ui.customizer.ErrorPanel errorPanel;
285: private javax.swing.JLabel jLabel1;
286: // End of variables declaration//GEN-END:variables
287:
288: }
|