1 19 20 package org.netbeans.modules.languages.studio; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Set ; 29 import javax.swing.DefaultListModel ; 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 45 public class LanguagesManagerPanel extends javax.swing.JPanel { 46 47 private Map nameToMimeType = new HashMap (); 48 49 50 51 public LanguagesManagerPanel () { 52 initComponents (); 53 LanguagesManager lm = LanguagesManager.getDefault (); 54 Set mimeTypes = lm.getSupportedMimeTypes (); 55 List names = new ArrayList (); 56 Iterator it = mimeTypes.iterator (); 57 while (it.hasNext ()) { 58 String mimeType = (String ) it.next (); 59 String name = mimeType; 60 names.add (name); 61 nameToMimeType.put (name, mimeType); 62 } 63 Collections.sort (names); 64 DefaultListModel model = new DefaultListModel (); 65 it = names.iterator (); 66 while (it.hasNext ()) { 67 String name = (String ) it.next (); 68 model.addElement (name); 69 } 70 ltLanguages.setModel (model); 71 } 72 73 78 private void initComponents() { 80 spLanguages = new javax.swing.JScrollPane (); 81 ltLanguages = new javax.swing.JList (); 82 lLanguages = new javax.swing.JLabel (); 83 bEdit = new javax.swing.JButton (); 84 lMimeType = new javax.swing.JLabel (); 85 tfMimeType = new javax.swing.JTextField (); 86 lExtensions = new javax.swing.JLabel (); 87 tfExtensions = new javax.swing.JTextField (); 88 jButton1 = new javax.swing.JButton (); 89 jButton2 = new javax.swing.JButton (); 90 91 ltLanguages.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 92 public void valueChanged(javax.swing.event.ListSelectionEvent 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 () { 103 public void actionPerformed(java.awt.event.ActionEvent 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 () { 116 public void actionPerformed(java.awt.event.ActionEvent evt) { 117 jButton1ActionPerformed(evt); 118 } 119 }); 120 121 jButton2.setText("Delete"); 122 jButton2.addActionListener(new java.awt.event.ActionListener () { 123 public void actionPerformed(java.awt.event.ActionEvent 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 } 180 private void ltLanguagesValueChanged (javax.swing.event.ListSelectionEvent evt) { String name = (String ) ltLanguages.getSelectedValue (); 182 if (name == null) return; 183 String mimeType = (String ) nameToMimeType.get (name); 184 tfMimeType.setText (mimeType); 185 List ext = Collections.singletonList (mimeType); 186 StringBuilder sb = new StringBuilder (); 187 Iterator 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 } 195 private void jButton2ActionPerformed (java.awt.event.ActionEvent evt) { } 199 private void jButton1ActionPerformed (java.awt.event.ActionEvent evt) { } 203 private void bEditActionPerformed (java.awt.event.ActionEvent evt) { String name = (String ) ltLanguages.getSelectedValue (); 205 if (name == null) return; 206 String mimeType = (String ) 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 } 218 219 private javax.swing.JButton bEdit; 221 private javax.swing.JButton jButton1; 222 private javax.swing.JButton jButton2; 223 private javax.swing.JLabel lExtensions; 224 private javax.swing.JLabel lLanguages; 225 private javax.swing.JLabel lMimeType; 226 private javax.swing.JList ltLanguages; 227 private javax.swing.JScrollPane spLanguages; 228 private javax.swing.JTextField tfExtensions; 229 private javax.swing.JTextField tfMimeType; 230 232 } 233 | Popular Tags |