1 19 package org.netbeans.modules.form.assistant; 20 21 import java.util.*; 22 23 import org.openide.util.NbBundle; 24 25 30 public class AssistantMessages { 31 private static AssistantMessages defaultInstance = new AssistantMessages(); 32 private boolean initialized = false; 33 private Map contextToMessages; 34 35 private AssistantMessages() { 36 } 37 38 public static AssistantMessages getDefault() { 39 return defaultInstance; 40 } 41 42 public String [] getMessages(String context) { 43 if (!initialized) { 44 initialize(); 45 } 46 String [] messages = (String [])contextToMessages.get(context); 47 return messages; 48 } 49 50 private void initialize() { 51 Map contextToSet = new HashMap(); 52 ResourceBundle bundle = NbBundle.getBundle(AssistantMessages.class); 53 Enumeration enumeration = bundle.getKeys(); 54 while (enumeration.hasMoreElements()) { 55 String bundleKey = (String )enumeration.nextElement(); 56 String context = getContext(bundleKey); 57 Set messages = (Set)contextToSet.get(context); 58 if (messages == null) { 59 messages = new HashSet(); 60 contextToSet.put(context, messages); 61 } 62 messages.add(bundle.getString(bundleKey)); 63 } 64 65 contextToMessages = new HashMap(); 67 Iterator iter = contextToSet.entrySet().iterator(); 68 while (iter.hasNext()) { 69 Map.Entry entry = (Map.Entry)iter.next(); 70 String key = (String )entry.getKey(); 71 Set value = (Set)entry.getValue(); 72 String [] messages = (String [])value.toArray(new String [value.size()]); 73 contextToMessages.put(key, messages); 74 } 75 } 76 77 private String getContext(String bundleKey) { 78 int index = bundleKey.indexOf('_'); 79 if (index == -1) { 80 return bundleKey; 81 } else { 82 return bundleKey.substring(0, index); 83 } 84 } 85 86 } 87 | Popular Tags |