1 19 package org.netbeans.modules.xml.catalog.lib; 20 21 import java.beans.*; 22 import java.io.File ; 23 import java.util.StringTokenizer ; 24 25 import javax.swing.JFileChooser ; 26 import javax.swing.filechooser.FileFilter ; 27 28 import org.openide.NotifyDescriptor; 29 import org.openide.DialogDisplayer; 30 import org.openide.windows.WindowManager; 31 import org.openide.util.NbBundle; 32 33 import org.netbeans.modules.xml.core.lib.AbstractUtil; 34 35 42 public class Util extends AbstractUtil { 43 44 45 46 public static final Util THIS = new Util(); 47 48 49 private Util () { 50 } 51 52 53 54 58 public static Customizer getProviderCustomizer(Class clazz) { 59 try { 60 Class customizer = 61 Introspector.getBeanInfo(clazz).getBeanDescriptor().getCustomizerClass(); 62 63 return (Customizer) customizer.newInstance(); 64 65 } catch (InstantiationException ex) { 66 return null; 67 } catch (IntrospectionException ex) { 68 return null; 69 } catch (IllegalAccessException ex) { 70 return null; 71 } 72 } 73 74 75 78 public static Object createProvider(Class clazz) { 79 try { 80 return clazz.newInstance(); 81 } catch (InstantiationException ex) { 82 return null; 83 } catch (IllegalAccessException ex) { 84 return null; 85 } 86 } 87 88 private static File lastDirectory; 90 91 96 public static File selectCatalogFile(final String extensions) { 97 return selectFile(extensions, Util.THIS.getString("TITLE_select_catalog"), Util.THIS.getString("PROP_catalog_mask")); 98 } 99 100 107 public static File selectFile(final String extensions, String dialogTitle, final String maskTitle) { 108 JFileChooser chooser = new JFileChooser (); 109 110 chooser.setFileFilter(new FileFilter () { 111 public boolean accept(File f) { 112 if (f.isDirectory()) return true; 113 StringTokenizer token = new StringTokenizer (extensions, " "); while (token.hasMoreElements()) { 115 if (f.getName().endsWith(token.nextToken())) return true; 116 } 117 return false; 118 } 119 public String getDescription() { 120 return maskTitle; } 122 }); 123 124 if (lastDirectory != null) { 125 chooser.setCurrentDirectory(lastDirectory); 126 } 127 128 chooser.setDialogTitle(dialogTitle); 129 while (chooser.showDialog(WindowManager.getDefault().getMainWindow(), 130 Util.THIS.getString("PROP_select_button")) 131 == JFileChooser.APPROVE_OPTION) 132 { 133 File f = chooser.getSelectedFile(); 134 lastDirectory = chooser.getCurrentDirectory(); 135 if (f != null && f.isFile()) { 136 StringTokenizer token = new StringTokenizer (extensions, " "); while (token.hasMoreElements()) { 138 if (f.getName().endsWith(token.nextToken())) return f; 139 } 140 } 141 142 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 143 Util.THIS.getString("MSG_inValidFile"), NotifyDescriptor.WARNING_MESSAGE)); 144 } 145 return null; 146 } 147 148 } 149 | Popular Tags |