1 19 package org.netbeans.modules.xml.core.lib; 20 21 import org.openide.ErrorManager; 22 import org.openide.util.Lookup; 23 import org.openide.util.NbBundle; 24 25 import java.awt.*; 26 import java.util.StringTokenizer ; 27 import java.util.MissingResourceException ; 28 29 42 public abstract class AbstractUtil { 43 44 private ErrorManager packageErrorManager; 45 46 private static final int DEBUG_SEVERITY = ErrorManager.INFORMATIONAL; 47 48 52 53 58 public final String getString (String key) { 59 if (key == null) throw new NullPointerException (); 60 return NbBundle.getMessage (this.getClass(), key); 61 } 62 63 69 public final String getString (String key, Object param) { 70 if (key == null) throw new NullPointerException (); 71 return NbBundle.getMessage (this.getClass(), key, param); 72 } 73 74 81 public final String getString (String key, Object param1, Object param2) { 82 if (key == null) throw new NullPointerException (); 83 return NbBundle.getMessage (this.getClass(), key, param1, param2); 84 } 85 86 91 public final char getChar (String key) { 92 if (key == null) throw new NullPointerException (); 93 return NbBundle.getMessage (this.getClass(), key).charAt (0); 94 } 95 96 97 104 public final Color getColor(String key) { 105 String raw = null; 106 try { 107 raw = getString(key); 108 } catch (MissingResourceException e) { 109 return null; 110 } 111 StringTokenizer tokenizer = new StringTokenizer (raw, ", \t"); if (tokenizer.countTokens() < 3) { 113 if (tokenizer.countTokens() == 1) { 114 if ("null".equals(tokenizer.nextToken())) return null; } 116 throw new MissingResourceException ("Invalid color format: " + raw, getClass().getName(), key); } 118 119 String red = tokenizer.nextToken(); 120 String green = tokenizer.nextToken(); 121 String blue = tokenizer.nextToken(); 122 int r = Integer.parseInt(red); 123 if (r<0 || r>255) throw new MissingResourceException ("Invalid color format: " + raw, getClass().getName(), key); int g = Integer.parseInt(green); 125 if (g<0 || g>255) throw new MissingResourceException ("Invalid color format: " + raw, getClass().getName(), key); int b = Integer.parseInt(blue); 127 if (b<0 || b>255) throw new MissingResourceException ("Invalid color format: " + raw, getClass().getName(), key); 130 return new Color(r, g, b); 131 } 132 133 137 141 public final boolean isLoggable () { 142 return getErrorManager().isLoggable (DEBUG_SEVERITY); 143 } 144 145 150 public final void debug (String message) { 151 if (message == null) return; 152 getErrorManager().log (DEBUG_SEVERITY, message); 153 } 154 155 160 public final void debug (Throwable ex) { 161 if (ex == null) return; 162 getErrorManager().notify (DEBUG_SEVERITY, ex); 163 } 164 165 171 public final void debug (String message, Throwable ex) { 172 if (ex == null) return; 173 if (message != null) { 174 ex = getErrorManager().annotate(ex, DEBUG_SEVERITY, message, null, null, null); 175 } 176 debug (ex); 177 } 178 179 184 public final synchronized ErrorManager getErrorManager () { 185 if ( packageErrorManager == null ) { 186 String pack = "org.netbeans.modules.xml.core.lib"; packageErrorManager = ErrorManager.getDefault().getInstance(pack); 188 } 189 return packageErrorManager; 190 } 191 192 } 193 | Popular Tags |