Esempio n. 1
0
  private static void init() {
    BOLD = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
    ITALIC = JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
    BOLD_ITALIC =
        new Font(
            Display.getCurrent(), getModifiedFontData(ITALIC.getFontData(), SWT.BOLD | SWT.ITALIC));

    Font defaultFont = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
    FontData[] defaultData = defaultFont.getFontData();
    if (defaultData != null && defaultData.length == 1) {
      FontData data =
          new FontData(
              defaultData[0].getName(), defaultData[0].getHeight(), defaultData[0].getStyle());

      if ("win32".equals(SWT.getPlatform())) { // $NON-NLS-1$
        // NOTE: Windows only, for: data.data.lfStrikeOut = 1;
        try {
          Field dataField = data.getClass().getDeclaredField("data"); // $NON-NLS-1$
          Object dataObject = dataField.get(data);
          Class<?> clazz = dataObject.getClass().getSuperclass();
          Field strikeOutFiled = clazz.getDeclaredField("lfStrikeOut"); // $NON-NLS-1$
          strikeOutFiled.set(dataObject, (byte) 1);
          CommonFonts.STRIKETHROUGH = new Font(Display.getCurrent(), data);
        } catch (Throwable t) {
          // ignore
        }
      }
    }
    if (CommonFonts.STRIKETHROUGH == null) {
      CommonFonts.HAS_STRIKETHROUGH = false;
      CommonFonts.STRIKETHROUGH = defaultFont;
    } else {
      CommonFonts.HAS_STRIKETHROUGH = true;
    }
  }
Esempio n. 2
0
  private static int getMinimumFontSize(Font ft) {
    if (ft != null && ft.getFontData().length > 0) {
      return ft.getFontData()[0].getHeight();
    }

    return 0;
  }
Esempio n. 3
0
  public CstCanvas(Composite parent, int style) {
    super(parent, style);

    fontSmall = createFontofSize(7);
    fontBig = createFontofSize(12);

    Font initialFont = getDisplay().getSystemFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
      fontData[i].setHeight(7);
    }
    fontA = new Font(getDisplay(), fontData);
    BLUE = UiDesk.getColorFromRGB("1E1EFF");
    GRAY = UiDesk.getColorFromRGB("DDDDDD");
    DARKGRAY = UiDesk.getColorFromRGB("AAAAAA");
    WHITE = UiDesk.getColorFromRGB("FFFFFF");
    BRIGHTGREEN = UiDesk.getColorFromRGB("68FF00");
    ORANGE = UiDesk.getColorFromRGB("FF6800");
    BLACK = UiDesk.getColorFromRGB("000000");

    setBackground(WHITE);

    addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            // TODO: is it necessary to dispose these colors (don't think so, but make sure)
            fontA.dispose();
          }
        });
  }
  private void createLabel(Composite c, int span, String content, Image image, LabelAttributes la) {
    if (content == null && image == null) return;

    Label l = new Label(c, la.getFontStyle());
    GridData gd = new GridData();
    gd.verticalSpan = span;
    gd.horizontalIndent = 5;
    if (content != null) l.setText(content);

    if (image != null) l.setImage(image);
    if (la.getForegroundColor() != null)
      l.setForeground(new Color(DisplayManager.getDefaultDisplay(), la.getForegroundColor()));

    Font initialFont = l.getFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
      fontData[i].setHeight(la.getFontSize());
      fontData[i].setStyle(la.getFontStyle());
    }
    Font newFont = new Font(DisplayManager.getDefaultDisplay(), fontData[0]);
    l.setFont(newFont);
    l.pack();

    l.setBackground(c.getBackground());
    l.setLayoutData(gd);
  }
Esempio n. 5
0
  /**
   * Creates a new {@link FontLnfResource} and adds it to the {@link RienaDefaultLnf}. So next time,
   * a fontDescriptor with this key will be used to fetch the font, the cached instance will be
   * returned.
   *
   * @return the font defined by this descriptor or <code>null</code> if no registered font can be
   *     found by the lnfKeyConstants key.
   */
  private Font updateFont() {
    if (key == null) {
      return null;
    }

    final Font font = lnf.getFont(key);
    if (font == null || font.getFontData().length == 0) {
      return null;
    }

    final String fontName = font.getFontData()[0].getName();
    final FontData fontData = new FontData(fontName, height, style);
    final FontLnfResource fontResource = new FontLnfResource(fontData);
    lnf.putLnfResource(this.toString(), fontResource);
    return getFont();
  }
Esempio n. 6
0
  private java.awt.Font getSelectedFont() {
    // Always use a large font for the rendering, even though user is typically
    // picking small font sizes in the font chooser
    // int dpi = mFontButton.getDisplay().getDPI().y;
    // int height = (int) Math.round(fontData.getHeight() * dpi / 72.0);
    int fontHeight = new TextRenderUtil.Options().fontSize;

    if (mFontButton.getData() == null) {
      // The user has not yet picked a font; look up the default font to use
      // (Helvetica Bold, not whatever font happened to be used for button widgets
      // in SWT on this platform)
      return new java.awt.Font("Helvetica", java.awt.Font.BOLD, fontHeight); // $NON-NLS-1$
    }

    Font font = mFontButton.getFont();
    FontData fontData = font.getFontData()[0];

    int awtStyle = java.awt.Font.PLAIN;
    int swtStyle = fontData.getStyle();

    if ((swtStyle & SWT.ITALIC) != 0) {
      awtStyle |= java.awt.Font.ITALIC;
    }
    if ((swtStyle & SWT.BOLD) != 0) {
      awtStyle = java.awt.Font.BOLD;
    }

    return new java.awt.Font(fontData.getName(), awtStyle, fontHeight);
  }
Esempio n. 7
0
 /**
  * Styles a font.
  *
  * @param font
  * @return styled font data
  */
 public static FontData[] styleFont(Font font, int fontStyle) {
   FontData[] datas = font.getFontData();
   for (FontData data : datas) {
     data.setStyle(data.getStyle() | fontStyle);
   }
   return datas;
 }
  /**
   * 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();
  }
 private FontData createFontDataFromNormal() {
   FontData normalData = NORMAL.getFontData()[0];
   FontData result = new FontData();
   result.setName(normalData.getName());
   result.height = normalData.height;
   return result;
 }
Esempio n. 10
0
  /**
   * Returns a version of the specified font, resized by the requested size.
   *
   * @param font the font to resize
   * @param size the font size
   * @return resized font data
   */
  public static FontData[] resizeFont(Font font, int size) {
    FontData[] datas = font.getFontData();
    for (FontData data : datas) {
      data.setHeight(data.getHeight() + size);
    }

    return datas;
  }
Esempio n. 11
0
 private static void setBoldFont(Label name) {
   if (boldFont == null) {
     Font initialFont = name.getFont();
     FontData[] fontData = initialFont.getFontData();
     for (int i = 0; i < fontData.length; i++) fontData[i].setStyle(SWT.BOLD);
     boldFont = new Font(Display.getCurrent(), fontData);
   }
   name.setFont(boldFont);
 }
Esempio n. 12
0
 private Font createFontofSize(int sizeOfFont) {
   Font initialFont = getDisplay().getSystemFont();
   FontData[] fontData = initialFont.getFontData();
   for (int i = 0; i < fontData.length; i++) {
     fontData[i].setHeight(sizeOfFont);
   }
   Font newFont = new Font(getDisplay(), fontData);
   return newFont;
 }
 /**
  * Returns a bold version of the given {@link Font}.
  *
  * @param baseFont the {@link Font} for which a bold version is desired
  * @return the bold version of the given {@link Font}
  */
 public static Font getBoldFont(Font baseFont) {
   Font font = m_fontToBoldFontMap.get(baseFont);
   if (font == null) {
     FontData fontDatas[] = baseFont.getFontData();
     FontData data = fontDatas[0];
     font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
     m_fontToBoldFontMap.put(baseFont, font);
   }
   return font;
 }
Esempio n. 14
0
  /**
   * Test of the method <code>getFont(String, int, int)</code>.
   *
   * @throws Exception handled by JUnit
   */
  public void testGetFontWithProps() throws Exception {

    lnf.initialize();
    final Font font =
        lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_FONT, 10, SWT.BOLD | SWT.ITALIC);
    FontData data = font.getFontData()[0];
    assertEquals(SWT.BOLD | SWT.ITALIC, data.getStyle());

    final Font font1 = lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_FONT, 12, SWT.BOLD);
    data = font1.getFontData()[0];
    assertEquals(SWT.BOLD, data.getStyle());

    final Font font2 = lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_FONT, 12, SWT.BOLD);
    assertSame(font1, font2);

    final Font fontNull =
        lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND, 12, SWT.BOLD);
    assertNull(fontNull);
  }
Esempio n. 15
0
  private static Font getItalicFont(Font font) {
    if (italicFont == null) {
      FontData data = font.getFontData()[0];

      italicFont =
          new Font(
              Display.getDefault(), new FontData(data.getName(), data.getHeight(), SWT.ITALIC));
    }

    return italicFont;
  }
Esempio n. 16
0
  public TagLabel(Composite parent, int style, String tagName) {
    super(parent, style);
    if (tagName == null || tagName.length() == 0) {
      throw new IllegalArgumentException("tag name is empty");
    }
    this.tagName = tagName;
    GridLayout gl = new GridLayout(2, false);
    GUIUtil.resetGridLayout(gl);
    super.setLayout(gl);

    final CLabel cross = new CLabel(this, 0);
    cross.setText("×");
    GridData data = new GridData(SWT.LEFT, SWT.TOP, false, true);
    cross.setLayoutData(data);
    data = new GridData(SWT.RIGHT, SWT.TOP, true, true);
    CLabel tagText = new CLabel(this, 0);
    tagText.setText(tagName);

    plainFont = cross.getFont();
    FontData fd = plainFont.getFontData()[0];
    boldFont = new Font(cross.getDisplay(), fd.getName(), fd.getHeight(), SWT.BOLD);
    cross.addListener(
        SWT.MouseEnter,
        new Listener() {

          @Override
          public void handleEvent(Event event) {
            cross.setFont(boldFont);
            cross.setCursor(handCursor);
          }
        });
    cross.addListener(
        SWT.MouseExit,
        new Listener() {

          @Override
          public void handleEvent(Event event) {
            cross.setFont(plainFont);
            cross.setCursor(defaultCursor);
          }
        });
    cross.addListener(
        SWT.MouseDown,
        new Listener() {

          @Override
          public void handleEvent(Event event) {
            if (delegate != null) {
              delegate.tagLabelClicked(TagLabel.this);
            }
          }
        });
  }
Esempio n. 17
0
    @Override
    protected void initialize(ColumnViewer viewer, ViewerColumn column) {
      super.initialize(viewer, column);

      Font font = viewer.getControl().getFont();

      if (font != null) {
        FontData data = font.getFontData()[0];

        boldFont = new Font(font.getDevice(), data.getName(), data.getHeight(), SWT.BOLD);
      }
    }
  /**
   * This method obtains the fonts that are being used by the figure at its zoom level.
   *
   * @param gep the associated <code>GraphicalEditPart</code> of the figure
   * @param actualFont font being used by the figure
   * @param display
   * @return <code>actualFont</code> if zoom level is 1.0 (or when there's an error), new Font
   *     otherwise.
   */
  private Font getZoomLevelFont(Font actualFont, Display display) {
    Object zoom = getEditPart().getViewer().getProperty(ZoomManager.class.toString());

    if (zoom != null) {
      double zoomLevel = ((ZoomManager) zoom).getZoom();

      if (zoomLevel == 1.0f) return actualFont;

      FontData[] fd = new FontData[actualFont.getFontData().length];
      FontData tempFD = null;

      for (int i = 0; i < fd.length; i++) {
        tempFD = actualFont.getFontData()[i];

        fd[i] =
            new FontData(
                tempFD.getName(), (int) (zoomLevel * tempFD.getHeight()), tempFD.getStyle());
      }

      try {
        FontDescriptor fontDescriptor = FontDescriptor.createFrom(fd);
        cachedFontDescriptors.add(fontDescriptor);
        return getResourceManager().createFont(fontDescriptor);
      } catch (DeviceResourceException e) {
        Trace.catching(
            DiagramUIPlugin.getInstance(),
            DiagramUIDebugOptions.EXCEPTIONS_CATCHING,
            getClass(),
            "getZoomLevelFonts",
            e); //$NON-NLS-1$
        Log.error(
            DiagramUIPlugin.getInstance(),
            DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING,
            "getZoomLevelFonts",
            e); //$NON-NLS-1$

        return actualFont;
      }
    } else return actualFont;
  }
Esempio n. 19
0
  protected void applyFonts(final Composite composite) {
    Dialog.applyDialogFont(composite);

    if (info != null) {
      final Font font = info.getFont();
      final FontData[] fontDatas = font.getFontData();
      for (int i = 0; i < fontDatas.length; i++) {
        fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10);
      }
      infoFont = new Font(info.getDisplay(), fontDatas);
      info.setFont(infoFont);
    }
  }
  /* Init the Theme Font (from UI Thread) */
  private void createFonts() {
    int fontHeight = 10;
    Font newsFont = OwlUI.getThemeFont(OwlUI.NEWS_TEXT_FONT_ID, SWT.NORMAL);
    FontData[] fontData = newsFont.getFontData();
    if (fontData.length > 0) {
      fNewsFontFamily = fontData[0].getName();
      fontHeight = fontData[0].getHeight();
    }

    int normal = fontHeight;
    String fontUnit = "pt"; // $NON-NLS-1$
    fNormalFontCSS = "font-size: " + normal + fontUnit + ";"; // $NON-NLS-1$ //$NON-NLS-2$
  }
Esempio n. 21
0
 protected Font getFont(GC painter) {
   if (this.font == null || this.font.isDisposed()) {
     Font available = painter.getFont();
     if (available == null || available.isDisposed()) {
       available = getDisplay().getSystemFont();
     }
     FontData[] datas = available.getFontData();
     if (datas.length > 0) {
       this.font =
           new Font(getDisplay(), datas[0].getName(), Math.min(7, datas[0].getHeight()), SWT.BOLD);
     }
   }
   return this.font;
 }
Esempio n. 22
0
  /**
   * Takes a font and gives it a bold typeface.
   *
   * @param font Font to modify
   * @return Font with bold typeface
   */
  public static Font applyBoldFont(Font font) {
    if (font == null) return null;

    FontData[] fontDataArray = font.getFontData();
    if (fontDataArray == null) {
      return null;
    }
    for (int index = 0; index < fontDataArray.length; index++) {
      FontData fData = fontDataArray[index];
      fData.setStyle(SWT.BOLD);
    }

    return new Font(Display.getDefault(), fontDataArray);
  }
Esempio n. 23
0
  /**
   * Applies a certain font size to a font.
   *
   * @param font Font to modify
   * @param size New font size
   * @return Font with new font size
   */
  public static Font applyFontSize(Font font, int size) {
    if (font == null) return null;

    FontData[] fontDataArray = font.getFontData();
    if (fontDataArray == null) {
      return null;
    }
    for (int index = 0; index < fontDataArray.length; index++) {
      FontData fData = fontDataArray[index];
      fData.setHeight(size);
    }

    return new Font(Display.getDefault(), fontDataArray);
  }
Esempio n. 24
0
 /**
  * Return a FontAwesome font for SWT.
  *
  * @param size
  * @return
  */
 public static Font getFont(int size) {
   String name = FONTAWESOME + size;
   if (!JFaceResources.getFontRegistry().hasValueFor(name)) {
     // GetFont() may return null, so handle this case.
     Font font = getFont();
     if (font == null) {
       return null;
     }
     FontData[] data = font.getFontData();
     for (FontData d : data) {
       d.setHeight(size);
     }
     JFaceResources.getFontRegistry().put(name, data);
   }
   return JFaceResources.getFontRegistry().get(name);
 }
 @Override
 public Font getFont(Object element) {
   if (fVMList.getChecked(element)) {
     if (bold == null) {
       Font dialogFont = JFaceResources.getDialogFont();
       FontData[] fontData = dialogFont.getFontData();
       for (int i = 0; i < fontData.length; i++) {
         FontData data = fontData[i];
         data.setStyle(SWT.BOLD);
       }
       Display display = JDIDebugUIPlugin.getStandardDisplay();
       bold = new Font(display, fontData);
     }
     return bold;
   }
   return null;
 }
 public TableViewerBuilder(TableViewer viewer, Composite tableContainer) {
   this.viewer = viewer;
   viewer.setComparer(new EqualityComparer());
   this.tableLayout = new TableColumnLayout();
   tableContainer.setLayout(tableLayout);
   normalFont = viewer.getTable().getFont();
   FontData fd = normalFont.getFontData()[0];
   fd.setStyle(SWT.ITALIC);
   italicFont = new Font(null, fd);
   viewer
       .getTable()
       .addDisposeListener(
           new DisposeListener() {
             @Override
             public void widgetDisposed(DisposeEvent e) {
               italicFont.dispose();
             }
           });
 }
Esempio n. 27
0
  public FontPicker(final Composite parent, Font originalFont) {
    super(parent, SWT.NONE);
    if (originalFont == null) throw new IllegalArgumentException("null");

    update(originalFont.getFontData()[0]);

    addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            FontDialog dialog = new FontDialog(new Shell(Display.getDefault(), SWT.SHELL_TRIM));
            dialog.setFontList(fontData);
            FontData selected = dialog.open();
            if (selected != null) {
              update(selected);
              pack(true);
            }
          }
        });
  }
  @SuppressWarnings("nls")
  private String generateHtml(Font font) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head>");
    if (font != null) {
      FontData[] data = font.getFontData();
      if (data != null && data.length > 0) {
        String fontName = data[0].getName();
        int fontSize = data[0].getHeight();
        sb.append(
            "<style type=\"text/css\">html {font-family:\""
                + fontName
                + "\"; font-size:"
                + fontSize
                + "pt;}</style>");
      }
    }
    sb.append("</head><body>");

    if (GitInformation.isSet()) {
      sb.append("Build time: <b>" + GitInformation.getBuildTime() + "</b><br/>");
      sb.append("<br/>");
      sb.append("Git describe result: <b>" + GitInformation.getGitDescribe() + "</b><br/>");
      sb.append("<br/>");
      sb.append("Build commit:<br/>");
      sb.append(
          "Id: <b><a href=\""
              + GITHUB_COMMIT_URL
              + GitInformation.getCommitId()
              + "\" >"
              + GitInformation.getCommitId()
              + "</a></b><br/>");
      sb.append("Branch: <b>" + GitInformation.getBranch() + "</b><br/>");
      sb.append("Time: <b>" + GitInformation.getCommitTime() + "</b><br/>");
    } else {
      sb.append("No Git version information found.");
    }

    sb.append("</body></html>");
    return sb.toString();
  }
Esempio n. 29
0
  public static void initFormText(FormText formText) {

    formText.setWhitespaceNormalized(false);

    Font formTextFont = formText.getFont();
    FontData formTextFontData = formTextFont.getFontData()[0];

    FontData h1FontData =
        new FontData(formTextFontData.getName(), formTextFontData.getHeight() + 5, SWT.BOLD);
    final Font h1Font = new Font(formTextFont.getDevice(), h1FontData);
    formText.setFont(FONT_H1_KEY, h1Font);

    FontData h3FontData =
        new FontData(formTextFontData.getName(), formTextFontData.getHeight() + 3, SWT.BOLD);
    final Font h3Font = new Font(formTextFont.getDevice(), h3FontData);
    formText.setFont(FONT_H3_KEY, h3Font);

    Font codeFont = JFaceResources.getTextFont();
    formText.setFont(FONT_CODE_KEY, codeFont);

    formText.addDisposeListener(
        new DisposeListener() {

          @Override
          public void widgetDisposed(DisposeEvent e) {
            h1Font.dispose();
            h3Font.dispose();
          }
        });

    // Set fontKeySet = JFaceResources.getFontRegistry().getKeySet();
    // if (fontKeySet != null) {
    // for (Object fontKey : fontKeySet) {
    // System.out.println(fontKey);
    // }
    // }

  }
Esempio n. 30
0
  public void paintCanvas(GC gc, Point point) {
    if (timeSeries != null) {

      Font old = gc.getFont();
      FontData fd = old.getFontData()[0];
      fd.setHeight(20);
      gc.setFont(new Font(display, fd));
      gc.setForeground(new Color(display, 200, 200, 200));
      Painter.drawText(title, gc, 50, 20, PosHorizontal.LEFT, PosVerical.TOP);
      gc.setFont(old);

      if (point != null) {
        updateRangeOfOutputWindow(point.x, point.y);
      }

      updateDataWindowConversionValues();

      Color color_bluegreen = new Color(display, 190, 240, 190);
      int avg = valueToGraph(dataSum / dataCount);
      gc.setForeground(color_bluegreen);
      gc.drawLine(xStart, avg, xEnd, avg);

      drawGrid(gc);

      drawXYAxis(gc);

      if (compare_timeSeries != null) {

        Color color_red = new Color(display, 240, 0, 0);
        Color color_redgrey = new Color(display, 240, 190, 190);

        drawTimeSeries(gc, compare_timeSeries, color_red, color_redgrey);
      }

      drawTimeSeries(gc, timeSeries, color_black, color_grey);
    }
  }