1 package com.opensymphony.workflow.designer; 2 3 import java.io.*; 4 import java.util.ResourceBundle ; 5 import javax.swing.*; 6 7 import com.opensymphony.workflow.designer.swing.EnhancedResourceBundle; 8 9 public final class ResourceManager 10 { 11 private static final ResourceManager INSTANCE = new ResourceManager(); 12 13 private EnhancedResourceBundle bundle; 14 15 private ResourceManager() 16 { 17 bundle = new EnhancedResourceBundle("com.opensymphony.workflow.designer.resources"); 18 } 19 20 public static ResourceBundle getBundle() 21 { 22 return INSTANCE.bundle.getBundle(); 23 } 24 25 public static String getString(String key) 26 { 27 return getString(key, key); 28 } 29 30 public static String getString(String key, String defaultValue) 31 { 32 return INSTANCE.bundle.getString(key, defaultValue); 33 } 34 35 public static String getString(String key, Object args) 36 { 37 return INSTANCE.bundle.getString(key, args); 38 } 39 40 public static ImageIcon getIcon(String key) 41 { 42 return INSTANCE.bundle.getIcon(key); 43 } 44 45 public static InputStream getInputStream(String path) 46 { 47 return INSTANCE.bundle.getInputStream(path); 48 } 49 50 public static ImageIcon readImageIcon(String path) 51 { 52 return INSTANCE.bundle.readImageIcon(path); 53 } 54 55 public static String readTextFromFile(String path) 56 { 57 InputStream in = getInputStream(path); 58 if(null == in) 59 return null; 60 BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 61 StringBuffer result = new StringBuffer (); 62 try 63 { 64 String line = reader.readLine(); 65 while(line != null) 66 { 67 result.append(line); 68 line = reader.readLine(); 69 if(line != null) 70 result.append('\n'); 71 } 72 return result.toString(); 73 } 74 catch(IOException e) 75 { 76 return null; 77 } 78 finally 79 { 80 try 81 { 82 reader.close(); 83 } 84 catch(IOException e) 85 { 86 } 87 } 88 } 89 } | Popular Tags |