KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > studio > LanguagesManagerPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.languages.studio;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Set JavaDoc;
29 import javax.swing.DefaultListModel JavaDoc;
30 import org.netbeans.api.languages.LanguagesManager;
31
32 import org.openide.ErrorManager;
33 import org.openide.cookies.OpenCookie;
34 import org.openide.filesystems.FileObject;
35 import org.openide.filesystems.FileSystem;
36 import org.openide.filesystems.Repository;
37 import org.openide.loaders.DataObject;
38 import org.openide.loaders.DataObjectNotFoundException;
39
40
41 /**
42  *
43  * @author Jan Jancura
44  */

45 public class LanguagesManagerPanel extends javax.swing.JPanel JavaDoc {
46     
47     private Map JavaDoc nameToMimeType = new HashMap JavaDoc ();
48     
49     
50     /** Creates new form LanguagesManagerPanel */
51     public LanguagesManagerPanel () {
52         initComponents ();
53         LanguagesManager lm = LanguagesManager.getDefault ();
54         Set JavaDoc mimeTypes = lm.getSupportedMimeTypes ();
55         List JavaDoc names = new ArrayList JavaDoc ();
56         Iterator JavaDoc it = mimeTypes.iterator ();
57         while (it.hasNext ()) {
58             String JavaDoc mimeType = (String JavaDoc) it.next ();
59             String JavaDoc name = mimeType;
60             names.add (name);
61             nameToMimeType.put (name, mimeType);
62         }
63         Collections.sort (names);
64         DefaultListModel JavaDoc model = new DefaultListModel JavaDoc ();
65         it = names.iterator ();
66         while (it.hasNext ()) {
67             String JavaDoc name = (String JavaDoc) it.next ();
68             model.addElement (name);
69         }
70         ltLanguages.setModel (model);
71     }
72     
73     /** This method is called from within the constructor to
74      * initialize the form.
75      * WARNING: Do NOT modify this code. The content of this method is
76      * always regenerated by the Form Editor.
77      */

78     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
79
private void initComponents() {
80         spLanguages = new javax.swing.JScrollPane JavaDoc();
81         ltLanguages = new javax.swing.JList JavaDoc();
82         lLanguages = new javax.swing.JLabel JavaDoc();
83         bEdit = new javax.swing.JButton JavaDoc();
84         lMimeType = new javax.swing.JLabel JavaDoc();
85         tfMimeType = new javax.swing.JTextField JavaDoc();
86         lExtensions = new javax.swing.JLabel JavaDoc();
87         tfExtensions = new javax.swing.JTextField JavaDoc();
88         jButton1 = new javax.swing.JButton JavaDoc();
89         jButton2 = new javax.swing.JButton JavaDoc();
90
91         ltLanguages.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
92             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
93                 ltLanguagesValueChanged(evt);
94             }
95         });
96
97         spLanguages.setViewportView(ltLanguages);
98
99         lLanguages.setText("Languages:");
100
101         bEdit.setText("Edit...");
102         bEdit.addActionListener(new java.awt.event.ActionListener JavaDoc() {
103             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
104                 bEditActionPerformed(evt);
105             }
106         });
107
108         lMimeType.setText("Mime Type:");
109
110         tfMimeType.setEditable(false);
111
112         lExtensions.setText("Extensions:");
113
114         jButton1.setText("Create...");
115         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
116             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
117                 jButton1ActionPerformed(evt);
118             }
119         });
120
121         jButton2.setText("Delete");
122         jButton2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
123             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
124                 jButton2ActionPerformed(evt);
125             }
126         });
127
128         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
129         this.setLayout(layout);
130         layout.setHorizontalGroup(
131             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
132             .add(layout.createSequentialGroup()
133                 .addContainerGap()
134                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
135                     .add(lLanguages)
136                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
137                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
138                             .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
139                                 .add(lExtensions)
140                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
141                                 .add(tfExtensions, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))
142                             .add(layout.createSequentialGroup()
143                                 .add(lMimeType)
144                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
145                                 .add(tfMimeType, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE))
146                             .add(spLanguages, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
147                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
148                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
149                             .add(org.jdesktop.layout.GroupLayout.LEADING, jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
150                             .add(org.jdesktop.layout.GroupLayout.LEADING, jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
151                             .add(org.jdesktop.layout.GroupLayout.LEADING, bEdit, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
152                 .addContainerGap())
153         );
154         layout.setVerticalGroup(
155             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
156             .add(layout.createSequentialGroup()
157                 .addContainerGap()
158                 .add(lLanguages)
159                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
160                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
161                     .add(layout.createSequentialGroup()
162                         .add(bEdit)
163                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
164                         .add(jButton1)
165                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
166                         .add(jButton2))
167                     .add(spLanguages, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))
168                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
169                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
170                     .add(lMimeType)
171                     .add(tfMimeType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
172                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
173                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
174                     .add(lExtensions)
175                     .add(tfExtensions, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
176                 .addContainerGap())
177         );
178     }// </editor-fold>//GEN-END:initComponents
179

180     private void ltLanguagesValueChanged (javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_ltLanguagesValueChanged
181
String JavaDoc name = (String JavaDoc) ltLanguages.getSelectedValue ();
182         if (name == null) return;
183         String JavaDoc mimeType = (String JavaDoc) nameToMimeType.get (name);
184         tfMimeType.setText (mimeType);
185         List JavaDoc ext = Collections.singletonList (mimeType);
186         StringBuilder JavaDoc sb = new StringBuilder JavaDoc ();
187         Iterator JavaDoc it = ext.iterator ();
188         while (it.hasNext ()) {
189             sb.append (it.next ());
190             if (it.hasNext ()) sb.append (", ");
191         }
192         tfExtensions.setText (sb.toString ());
193     }//GEN-LAST:event_ltLanguagesValueChanged
194

195     private void jButton2ActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton2ActionPerformed
196
// TODO add your handling code here:
197
}//GEN-LAST:event_jButton2ActionPerformed
198

199     private void jButton1ActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
200
// TODO add your handling code here:
201
}//GEN-LAST:event_jButton1ActionPerformed
202

203     private void bEditActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_bEditActionPerformed
204
String JavaDoc name = (String JavaDoc) ltLanguages.getSelectedValue ();
205         if (name == null) return;
206         String JavaDoc mimeType = (String JavaDoc) nameToMimeType.get (name);
207         FileSystem fs = Repository.getDefault ().getDefaultFileSystem ();
208         FileObject fo = fs.findResource ("Editors/" + mimeType + "/language.nbs");
209         try {
210             DataObject dob = DataObject.find (fo);
211             OpenCookie oc = (OpenCookie) dob.getCookie (OpenCookie.class);
212             oc.open ();
213         } catch (DataObjectNotFoundException ex) {
214             ErrorManager.getDefault ().notify (ex);
215         }
216     }//GEN-LAST:event_bEditActionPerformed
217

218     
219     // Variables declaration - do not modify//GEN-BEGIN:variables
220
private javax.swing.JButton JavaDoc bEdit;
221     private javax.swing.JButton JavaDoc jButton1;
222     private javax.swing.JButton JavaDoc jButton2;
223     private javax.swing.JLabel JavaDoc lExtensions;
224     private javax.swing.JLabel JavaDoc lLanguages;
225     private javax.swing.JLabel JavaDoc lMimeType;
226     private javax.swing.JList JavaDoc ltLanguages;
227     private javax.swing.JScrollPane JavaDoc spLanguages;
228     private javax.swing.JTextField JavaDoc tfExtensions;
229     private javax.swing.JTextField JavaDoc tfMimeType;
230     // End of variables declaration//GEN-END:variables
231

232 }
233
Popular Tags