1 11 package org.eclipse.swt.internal; 12 13 14 import java.io.*; 15 import java.text.MessageFormat ; 16 import java.util.MissingResourceException ; 17 import java.util.ResourceBundle ; 18 import java.util.zip.InflaterInputStream ; 19 20 import org.eclipse.swt.SWT; 21 22 44 public final class Compatibility { 45 46 49 public static double PI = Math.PI; 50 51 static double toRadians = PI / 180; 52 53 66 public static int cos(int angle, int length) { 67 return (int)(Math.cos(angle * toRadians) * length); 68 } 69 70 83 public static int sin(int angle, int length) { 84 return (int)(Math.sin(angle * toRadians) * length); 85 } 86 87 96 public static int ceil(int p, int q) { 97 return (int)Math.ceil((float)p / q); 98 } 99 100 109 public static int floor(int p, int q) { 110 return (int)Math.floor((double)p / q); 111 } 112 113 126 public static int round(int p, int q) { 127 return Math.round((float)p / q); 128 } 129 130 140 public static int pow2(int n) { 141 if (n >= 1 && n <= 30) 142 return 2 << (n - 1); 143 else if (n != 0) { 144 SWT.error(SWT.ERROR_INVALID_RANGE); 145 } 146 return 1; 147 } 148 149 156 public static InputStream newFileInputStream(String filename) throws IOException { 157 return new FileInputStream(filename); 158 } 159 160 167 public static OutputStream newFileOutputStream(String filename) throws IOException { 168 return new FileOutputStream(filename); 169 } 170 171 180 public static InputStream newInflaterInputStream(InputStream stream) throws IOException { 181 return new InflaterInputStream (stream); 182 } 183 184 190 public static boolean isLetter(char c) { 191 return Character.isLetter(c); 192 } 193 194 200 public static boolean isLetterOrDigit(char c) { 201 return Character.isLetterOrDigit(c); 202 } 203 204 210 public static boolean isSpaceChar(char c) { 211 return Character.isSpaceChar(c); 212 } 213 214 220 public static boolean isWhitespace(char c) { 221 return Character.isWhitespace(c); 222 } 223 224 238 public static void exec(String prog) throws java.io.IOException { 239 Runtime.getRuntime().exec(prog); 240 } 241 242 256 public static void exec(String [] progArray) throws java.io.IOException { 257 Runtime.getRuntime().exec(progArray); 258 } 259 260 private static ResourceBundle msgs = null; 261 262 271 public static String getMessage(String key) { 272 String answer = key; 273 274 if (key == null) { 275 SWT.error (SWT.ERROR_NULL_ARGUMENT); 276 } 277 if (msgs == null) { 278 try { 279 msgs = ResourceBundle.getBundle("org.eclipse.swt.internal.SWTMessages"); } catch (MissingResourceException ex) { 281 answer = key + " (no resource bundle)"; } 283 } 284 if (msgs != null) { 285 try { 286 answer = msgs.getString(key); 287 } catch (MissingResourceException ex2) {} 288 } 289 return answer; 290 } 291 292 public static String getMessage(String key, Object [] args) { 293 String answer = key; 294 295 if (key == null || args == null) { 296 SWT.error (SWT.ERROR_NULL_ARGUMENT); 297 } 298 if (msgs == null) { 299 try { 300 msgs = ResourceBundle.getBundle("org.eclipse.swt.internal.SWTMessages"); } catch (MissingResourceException ex) { 302 answer = key + " (no resource bundle)"; } 304 } 305 if (msgs != null) { 306 try { 307 MessageFormat formatter = new MessageFormat (""); 308 formatter.applyPattern(msgs.getString(key)); 309 answer = formatter.format(args); 310 } catch (MissingResourceException ex2) {} 311 } 312 return answer; 313 } 314 315 321 public static void interrupt() { 322 Thread.currentThread().interrupt(); 323 } 324 325 333 public static boolean equalsIgnoreCase(String s1, String s2) { 334 return s1.equalsIgnoreCase(s2); 335 } 336 337 } 338 | Popular Tags |