Пример #1
0
 /**
  * Sets the font that the receiver will use to paint textual information to the font specified by
  * the argument, or to the default font for that kind of control if the argument is null.
  *
  * @param font the new font (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the font has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setFont(Font font) {
   checkWidget();
   if (font != null && font.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   this.font = font;
 }
Пример #2
0
  /**
   * Sets the font that the receiver will use to paint textual information for the specified cell in
   * this item to the font specified by the argument, or to the default font for that kind of
   * control if the argument is null.
   *
   * @param index the column index
   * @param font the new font (or null)
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   *
   * @since 3.0
   */
  public void setFont(int index, Font font) {
    checkWidget();
    if (font != null && font.isDisposed()) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return;
    if (cellFont == null) {
      if (font == null) return;
      cellFont = new Font[count];
    }
    Font oldFont = cellFont[index];
    if (oldFont == font) return;
    cellFont[index] = font;
    if (oldFont != null && oldFont.equals(font)) return;

    int modelIndex =
        parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
    int /*long*/ fontHandle = font != null ? font.handle : 0;
    OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -1);
    /*
     * Bug in GTK.  When using fixed-height-mode,
     * row changes do not cause the row to be repainted.  The fix is to
     * invalidate the row when it is cleared.
     */
    if ((parent.style & SWT.VIRTUAL) != 0) {
      if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
        redraw();
      }
    }
    cached = true;

    if (font != null) {
      boolean customDraw =
          (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns[index].customDraw;
      if (!customDraw) {
        if ((parent.style & SWT.VIRTUAL) == 0) {
          int /*long*/ parentHandle = parent.handle;
          int /*long*/ column = 0;
          if (parent.columnCount > 0) {
            column = parent.columns[index].handle;
          } else {
            column = OS.gtk_tree_view_get_column(parentHandle, index);
          }
          if (column == 0) return;
          int /*long*/ textRenderer = parent.getTextRenderer(column);
          int /*long*/ imageRenderer = parent.getPixbufRenderer(column);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, textRenderer, display.cellDataProc, parentHandle, 0);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, imageRenderer, display.cellDataProc, parentHandle, 0);
        }
        if (parent.columnCount == 0) {
          parent.firstCustomDraw = true;
        } else {
          parent.columns[index].customDraw = true;
        }
      }
    }
  }
 @Override
 public void dispose() {
   if (hintFont != null && !hintFont.isDisposed()) {
     hintFont.dispose();
     hintFont = null;
   }
   super.dispose();
 }
  /*
   * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
   */
  public void widgetDisposed(DisposeEvent event) {
    if (fStatusTextFont != null && !fStatusTextFont.isDisposed()) fStatusTextFont.dispose();
    fStatusTextFont = null;
    if (fStatusTextForegroundColor != null && !fStatusTextForegroundColor.isDisposed())
      fStatusTextForegroundColor.dispose();
    fStatusTextForegroundColor = null;

    fTextFont = null;
    fShell = null;
    fText = null;
  }
Пример #5
0
 /**
  * Sets the font that the receiver will use to paint textual information for this item to the font
  * specified by the argument, or to the default font for that kind of control if the argument is
  * null.
  *
  * @param font the new font (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setFont(final Font font) {
   checkWidget();
   if (font != null && font.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (!equals(this.font, font)) {
     this.font = font;
     markCached();
     if (parent.getColumnCount() == 0) {
       parent.updateScrollBars();
     }
     parent.redraw();
   }
 }
Пример #6
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;
 }
Пример #7
0
 /**
  * Sets the font that the receiver will use to paint textual information for the specified cell in
  * this item to the font specified by the argument, or to the default font for that kind of
  * control if the argument is null.
  *
  * @param index the column index
  * @param font the new font (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setFont(final int index, final Font font) {
   checkWidget();
   if (font != null && font.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   int count = Math.max(1, parent.getColumnCount());
   if (index >= 0 && index < count) {
     ensureData(index, count);
     if (!equals(font, data[index].font)) {
       data[index].font = font;
       markCached();
       parent.redraw();
     }
   }
 }
Пример #8
0
  /**
   * Test of the method <code>uninitialize()</code>.
   *
   * @throws Exception handled by JUnit
   */
  public void testUninitialize() throws Exception {

    final Color color = lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND);
    assertNotNull(color);
    final Font font = lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_FONT);
    assertNotNull(font);

    lnf.uninitialize();

    assertFalse(font.isDisposed());
    assertNull(lnf.getFont(LnfKeyConstants.EMBEDDED_TITLEBAR_FONT));
    assertFalse(color.isDisposed());
    assertNull(lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND));
    assertNotSame(
        color,
        lnf.getColor(LnfKeyConstants.EMBEDDED_TITLEBAR_ACTIVE_FOREGROUND)); // TODO Could be removed
  }
Пример #9
0
  private void checkFontSize(Button b) {
    Font newFont = (Font) b.getData();

    b.setFont(initialFont);
    int charWidth = getFontWidth(b);
    int stringWidth = b.getText().length() * charWidth;
    FontData[] fontData = b.getFont().getFontData();

    int Ssize = fontData[0].getHeight();
    if (stringWidth > b.getBounds().width) {
      while (stringWidth > b.getBounds().width && Ssize > 0) {
        Ssize = fontData[0].getHeight() - 1;
        fontData[0].setHeight(Ssize);
        if (newFont != null && !newFont.isDisposed()) newFont.dispose();
        newFont = new Font(Display.getCurrent(), fontData[0]);
        b.setFont(newFont);
        b.setData(newFont);
        charWidth = getFontWidth(b);
        stringWidth = b.getText().length() * charWidth;
      }
    }
  }
Пример #10
0
 /**
  * Sets the font that the receiver will use to paint textual information for this item to the font
  * specified by the argument, or to the default font for that kind of control if the argument is
  * null.
  *
  * @param font the new font (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 3.0
  */
 public void setFont(Font font) {
   checkWidget();
   if (font != null && font.isDisposed()) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   Font oldFont = this.font;
   if (oldFont == font) return;
   this.font = font;
   if (oldFont != null && oldFont.equals(font)) return;
   int /*long*/ fontHandle = font != null ? font.handle : 0;
   OS.gtk_list_store_set(parent.modelHandle, handle, Table.FONT_COLUMN, fontHandle, -1);
   /*
    * Bug in GTK.  When using fixed-height-mode,
    * row changes do not cause the row to be repainted.  The fix is to
    * invalidate the row when it is cleared.
    */
   if ((parent.style & SWT.VIRTUAL) != 0) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
       redraw();
     }
   }
   cached = true;
 }
Пример #11
0
 private void disposeFont(Button b) {
   Font f = (Font) b.getData();
   if (f != null && !f.isDisposed()) f.dispose();
 }
Пример #12
0
 protected void handleClose() {
   if (infoFont != null && !infoFont.isDisposed()) {
     infoFont.dispose();
   }
   infoFont = null;
 }
Пример #13
0
 /**
  * Gets the font.
  *
  * @return the font
  */
 protected Font getFont() {
   if (font.isDisposed()) {
     font = DEFAULT_FONT;
   }
   return font;
 }