/**
  * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and
  * underline flags are also supported.
  *
  * @param name the name of the font
  * @param size the size of the font
  * @param style the style of the font
  * @param strikeout the strikeout flag (warning: Windows only)
  * @param underline the underline flag (warning: Windows only)
  * @return {@link Font} The font matching the name, height, style, strikeout and underline
  */
 public static Font getFont(
     String name, int size, int style, boolean strikeout, boolean underline) {
   String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
   Font font = m_fontMap.get(fontName);
   if (font == null) {
     FontData fontData = new FontData(name, size, style);
     if (strikeout || underline) {
       try {
         Class<?> logFontClass =
             Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); // $NON-NLS-1$
         Object logFont = FontData.class.getField("data").get(fontData); // $NON-NLS-1$
         if (logFont != null && logFontClass != null) {
           if (strikeout) {
             logFontClass
                 .getField("lfStrikeOut")
                 .set(logFont, Byte.valueOf((byte) 1)); // $NON-NLS-1$
           }
           if (underline) {
             logFontClass
                 .getField("lfUnderline")
                 .set(logFont, Byte.valueOf((byte) 1)); // $NON-NLS-1$
           }
         }
       } catch (Throwable e) {
         System.err.println(
             "Unable to set underline or strikeout"
                 + " (probably on a non-Windows platform). "
                 + e); //$NON-NLS-1$ //$NON-NLS-2$
       }
     }
     font = new Font(Display.getCurrent(), fontData);
     m_fontMap.put(fontName, font);
   }
   return font;
 }
Пример #2
0
 private void updateCursor(final String selection) {
   Cursor cursor = null;
   Class swtClass = SWT.class;
   if (selection != null) {
     try {
       Field field = swtClass.getField(selection);
       int cursorStyle = field.getInt(swtClass);
       cursor = Display.getCurrent().getSystemCursor(cursorStyle);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setCursor(cursor);
   }
 }