コード例 #1
0
 public static Font getFont(
     String name, int size, int style, boolean strikeout, boolean underline) {
   if (name.equals("Arial") && SWTResourceManager.isMac()) {
     size += 2;
   }
   String fontName = name + "|" + size + "|" + style + "|" + strikeout + "|" + underline;
   if (resources.containsKey(fontName)) return (Font) resources.get(fontName);
   FontData fd = new FontData(name, size, style);
   if (strikeout || underline) {
     try {
       Class<?> lfCls = Class.forName("org.eclipse.swt.internal.win32.LOGFONT");
       Object lf = FontData.class.getField("data").get(fd);
       if (lf != null && lfCls != null) {
         if (strikeout) lfCls.getField("lfStrikeOut").set(lf, new Byte((byte) 1));
         if (underline) lfCls.getField("lfUnderline").set(lf, new Byte((byte) 1));
       }
     } catch (Throwable e) {
       System.err.println(
           "Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e);
     }
   }
   Font font = new Font(Display.getDefault(), fd);
   resources.put(fontName, font);
   return font;
 }
コード例 #2
0
 public static Image getImage(String url) {
   try {
     url = url.replace('\\', '/');
     if (url.startsWith("/")) url = url.substring(1);
     if (resources.containsKey(url)) return (Image) resources.get(url);
     Image img =
         new Image(
             Display.getDefault(), instance.getClass().getClassLoader().getResourceAsStream(url));
     if (img != null) resources.put(url, img);
     return img;
   } catch (Exception e) {
     System.err.println("SWTResourceManager.getImage: Error getting image " + url + ", " + e);
     return null;
   }
 }