Esempio n. 1
0
 public static int getTableHeightHint(Table table, int rows) {
   if (table.getFont().equals(JFaceResources.getDefaultFont()))
     table.setFont(JFaceResources.getDialogFont());
   int result = table.getItemHeight() * rows + table.getHeaderHeight();
   if (table.getLinesVisible()) result += table.getGridLineWidth() * (rows - 1);
   return result;
 }
  /**
   * Given a label figure object, this will calculate the correct Font needed to display into screen
   * coordinates, taking into account the current mapmode. This will typically be used by direct
   * edit cell editors that need to display independent of the zoom or any coordinate mapping that
   * is taking place on the drawing surface.
   *
   * @param label the label to use for the font calculation
   * @return the <code>Font</code> that is scaled to the screen coordinates. Note: the returned
   *     <code>Font</code> should not be disposed since it is cached by a common resource manager.
   */
  protected Font getScaledFont(IFigure label) {
    Font scaledFont = label.getFont();
    FontData data = scaledFont.getFontData()[0];
    Dimension fontSize = new Dimension(0, MapModeUtil.getMapMode(label).DPtoLP(data.getHeight()));
    label.translateToAbsolute(fontSize);

    if (Math.abs(data.getHeight() - fontSize.height) < 2) fontSize.height = data.getHeight();

    try {
      FontDescriptor fontDescriptor = FontDescriptor.createFrom(data);
      cachedFontDescriptors.add(fontDescriptor);
      return getResourceManager().createFont(fontDescriptor);
    } catch (DeviceResourceException e) {
      Trace.catching(
          DiagramUIPlugin.getInstance(),
          DiagramUIDebugOptions.EXCEPTIONS_CATCHING,
          getClass(),
          "getScaledFont",
          e); //$NON-NLS-1$
      Log.error(
          DiagramUIPlugin.getInstance(),
          DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING,
          "getScaledFont",
          e); //$NON-NLS-1$
    }
    return JFaceResources.getDefaultFont();
  }
Esempio n. 3
0
  /**
   * Gets the default small font from the JFace font registry.
   *
   * @return default small font
   */
  public static Font getDefaultSmallFont() {
    Font small = JFaceResources.getFontRegistry().get(SMALL_FONT);
    if (small != null) {
      return small;
    }

    Font f = JFaceResources.getDefaultFont();
    FontData[] smaller = resizeFont(f, -2);
    JFaceResources.getFontRegistry().put(SMALL_FONT, smaller);
    return JFaceResources.getFontRegistry().get(SMALL_FONT);
  }
Esempio n. 4
0
  public static TextStyleData getTextStyleData(
      IGraphicalPart part, IStyleSelector ss, TextStyleData defaultData) {
    Object cache = MindMapUtils.getCache(part, MindMapUI.CACHE_TEXT_STYLE);
    if (cache instanceof TextStyleData) return (TextStyleData) cache;

    TextStyleData data;
    if (defaultData == null) {
      data = new TextStyleData();
      defaultData = data;
    } else {
      data = new TextStyleData(defaultData);
    }

    String name = getString(part, ss, Styles.FontFamily, defaultData.name);
    if (Styles.SYSTEM.equals(name)) {
      name = JFaceResources.getDefaultFont().getFontData()[0].getName();
    }
    data.name = name;

    data.height = getInteger(part, ss, Styles.FontSize, defaultData.height);

    String weight = getString(part, ss, Styles.FontWeight, null);
    if (weight != null) {
      data.bold = weight.contains(Styles.FONT_WEIGHT_BOLD);
    }

    String style = getString(part, ss, Styles.FontStyle, null);
    if (style != null) {
      data.italic = style.contains(Styles.FONT_STYLE_ITALIC);
    }

    RGB c = getRGB(part, ss, Styles.TextColor, null);
    if (c != null) {
      data.color = c;
    }

    String decoration = getString(part, ss, Styles.TextDecoration, null);
    if (decoration != null) {
      data.underline = decoration.contains(Styles.TEXT_DECORATION_UNDERLINE);
      data.strikeout = decoration.contains(Styles.TEXT_DECORATION_LINE_THROUGH);
    }

    int align = getAlignValue(part, ss, Styles.TextAlign);
    data.align = align;
    return data;
  }
 /**
  * Initialize default fonts. Causes this to re-read font preferences from the preference store.
  * Calling this method should only be necessary if font preferences have changed, or if the font
  * preference keys have changed.
  *
  * @since 1.3
  * @see #getFontPreference()
  * @see #getMonospaceFontPreference()
  */
 public void initializeDefaultFonts() {
   Font defaultFont = null;
   Font defaultMonospaceFont = null;
   if (WikiTextUiPlugin.getDefault() != null) {
     IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
     FontRegistry fontRegistry = themeManager.getCurrentTheme().getFontRegistry();
     defaultFont = fontRegistry.get(fontPreference);
     defaultMonospaceFont = fontRegistry.get(monospaceFontPreference);
   }
   if (defaultFont == null) {
     // could be the case when running stand-alone
     defaultFont = JFaceResources.getDefaultFont();
   }
   if (this.defaultFont != defaultFont || this.defaultMonospaceFont != defaultMonospaceFont) {
     this.defaultFont = defaultFont;
     this.defaultMonospaceFont = defaultMonospaceFont;
     if (scanner != null) {
       scanner.resetFonts(defaultFont, defaultMonospaceFont);
     }
   }
 }
Esempio n. 6
0
 public static Font getCompositeFont(IGraphicalPart part, IStyleSelector ss, Font defaultFont) {
   if (defaultFont == null) defaultFont = JFaceResources.getDefaultFont();
   TextStyleData data =
       getTextStyleData(part, ss, new TextStyleData(defaultFont.getFontData()[0]));
   return data.createFont();
 }
 // Default Font
 private SwtFonts() {
   this(JFaceResources.getDefaultFont().getFontData()[0]);
 }