Search in sources :

Example 91 with Font

use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_StyledText_VariableLineHeight method testBigFontSeveralRanges.

@Test
public void testBigFontSeveralRanges() {
    styledText.setText("abc\nd");
    // Create little, big font
    Font initialFont = styledText.getFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(fontData[i].getHeight() * 2);
    }
    Font bigFont = new Font(styledText.getDisplay(), fontData);
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(fontData[i].getHeight() / 2);
    }
    Font littleFont = new Font(styledText.getDisplay(), fontData);
    StyleRange[] ranges = new StyleRange[2];
    ranges[0] = new StyleRange();
    ranges[0].start = 0;
    ranges[0].length = 1;
    ranges[0].font = bigFont;
    ranges[1] = new StyleRange();
    ranges[1].start = 1;
    ranges[1].length = 1;
    ranges[1].font = littleFont;
    styledText.replaceStyleRanges(0, 3, ranges);
    // line height is the height of the big font
    assertVariableLineHeightEquals(0, 0, bigFont);
    bigFont.dispose();
    littleFont.dispose();
}
Also used : FontData(org.eclipse.swt.graphics.FontData) StyleRange(org.eclipse.swt.custom.StyleRange) Font(org.eclipse.swt.graphics.Font) Test(org.junit.Test)

Example 92 with Font

use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_StyledText_VariableLineHeight method testLittleFontSeveralRanges.

@Test
public void testLittleFontSeveralRanges() {
    styledText.setText("abc\nd");
    // Create little, big font
    Font initialFont = styledText.getFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(fontData[i].getHeight() / 2);
    }
    Font littleFont1 = new Font(styledText.getDisplay(), fontData);
    fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(fontData[i].getHeight() / 4);
    }
    Font littleFont2 = new Font(styledText.getDisplay(), fontData);
    StyleRange[] ranges = new StyleRange[2];
    ranges[0] = new StyleRange();
    ranges[0].start = 0;
    ranges[0].length = 1;
    ranges[0].font = littleFont1;
    ranges[1] = new StyleRange();
    ranges[1].start = 1;
    ranges[1].length = 1;
    ranges[1].font = littleFont2;
    styledText.replaceStyleRanges(0, 3, ranges);
    // 2 little fonts, line height is the height of the default font of StyledText
    assertVariableLineHeightEquals(0, 0);
    littleFont1.dispose();
    littleFont2.dispose();
}
Also used : FontData(org.eclipse.swt.graphics.FontData) StyleRange(org.eclipse.swt.custom.StyleRange) Font(org.eclipse.swt.graphics.Font) Test(org.junit.Test)

Example 93 with Font

use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.

the class CTableItem method setFont.

/**
 * 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</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 *
 * @since 3.0
 */
public void setFont(int columnIndex, Font font) {
    checkWidget();
    if (font != null && font.isDisposed()) {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    int validColumnCount = Math.max(1, parent.columns.length);
    if (!(0 <= columnIndex && columnIndex < validColumnCount))
        return;
    if (cellFonts == null) {
        if (font == null)
            return;
        cellFonts = new Font[validColumnCount];
    }
    Font oldFont = cellFonts[columnIndex];
    if (oldFont == font)
        return;
    cellFonts[columnIndex] = font;
    if (oldFont != null && oldFont.equals(font))
        return;
    if ((parent.getStyle() & SWT.VIRTUAL) != 0)
        cached = true;
    /* recompute cached values for string measurements */
    GC gc = new GC(parent);
    gc.setFont(getFont(columnIndex, false));
    if (fontHeights == null)
        fontHeights = new int[validColumnCount];
    fontHeights[columnIndex] = gc.getFontMetrics().getHeight();
    computeDisplayText(columnIndex, gc);
    gc.dispose();
    if (isInViewport()) {
        Rectangle bounds = getCellBounds(columnIndex);
        parent.redraw(bounds.x, bounds.y, bounds.width, bounds.height, false);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 94 with Font

use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.

the class CTableItem method addColumn.

/*
 * Updates internal structures in the receiver and its child items to handle the creation of a new column.
 */
void addColumn(CTableColumn column) {
    int index = column.getIndex();
    int columnCount = parent.columns.length;
    if (columnCount > 1) {
        if (columnCount == 2) {
            texts = new String[2];
        } else {
            String[] newTexts = new String[columnCount];
            System.arraycopy(texts, 0, newTexts, 0, index);
            System.arraycopy(texts, index, newTexts, index + 1, columnCount - index - 1);
            texts = newTexts;
        }
        if (index == 0) {
            texts[1] = super.getText();
            // $NON-NLS-1$
            super.setText("");
        }
        if (columnCount == 2) {
            images = new Image[2];
        } else {
            Image[] newImages = new Image[columnCount];
            System.arraycopy(images, 0, newImages, 0, index);
            System.arraycopy(images, index, newImages, index + 1, columnCount - index - 1);
            images = newImages;
        }
        if (index == 0) {
            images[1] = super.getImage();
            super.setImage(null);
        }
        int[] newTextWidths = new int[columnCount];
        System.arraycopy(textWidths, 0, newTextWidths, 0, index);
        System.arraycopy(textWidths, index, newTextWidths, index + 1, columnCount - index - 1);
        textWidths = newTextWidths;
    } else {
        customWidth = -1;
    /* columnCount == 1 */
    }
    /*
	 * The length of displayTexts always matches the parent's column count, unless this
	 * count is zero, in which case displayTexts is null.
	 */
    String[] newDisplayTexts = new String[columnCount];
    if (columnCount > 1) {
        System.arraycopy(displayTexts, 0, newDisplayTexts, 0, index);
        System.arraycopy(displayTexts, index, newDisplayTexts, index + 1, columnCount - index - 1);
    }
    displayTexts = newDisplayTexts;
    if (cellBackgrounds != null) {
        Color[] newCellBackgrounds = new Color[columnCount];
        System.arraycopy(cellBackgrounds, 0, newCellBackgrounds, 0, index);
        System.arraycopy(cellBackgrounds, index, newCellBackgrounds, index + 1, columnCount - index - 1);
        cellBackgrounds = newCellBackgrounds;
    }
    if (cellForegrounds != null) {
        Color[] newCellForegrounds = new Color[columnCount];
        System.arraycopy(cellForegrounds, 0, newCellForegrounds, 0, index);
        System.arraycopy(cellForegrounds, index, newCellForegrounds, index + 1, columnCount - index - 1);
        cellForegrounds = newCellForegrounds;
    }
    if (cellFonts != null) {
        Font[] newCellFonts = new Font[columnCount];
        System.arraycopy(cellFonts, 0, newCellFonts, 0, index);
        System.arraycopy(cellFonts, index, newCellFonts, index + 1, columnCount - index - 1);
        cellFonts = newCellFonts;
        int[] newFontHeights = new int[columnCount];
        System.arraycopy(fontHeights, 0, newFontHeights, 0, index);
        System.arraycopy(fontHeights, index, newFontHeights, index + 1, columnCount - index - 1);
        fontHeights = newFontHeights;
    }
    if (columnCount > accessibles.length) {
        Accessible[] newAccessibles = new Accessible[columnCount];
        System.arraycopy(accessibles, 0, newAccessibles, 0, index);
        System.arraycopy(accessibles, index, newAccessibles, index + 1, columnCount - index - 1);
        accessibles = newAccessibles;
    }
    if (index == 0 && columnCount > 1) {
        /*
		 * The new second column may have more width available to it than it did when it was
		 * the first column if checkboxes are being shown, so recompute its displayText if needed.
		 */
        if ((parent.getStyle() & SWT.CHECK) != 0) {
            GC gc = new GC(parent);
            gc.setFont(getFont(1, false));
            computeDisplayText(1, gc);
            gc.dispose();
        }
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) GC(org.eclipse.swt.graphics.GC) Accessible(org.eclipse.swt.accessibility.Accessible)

Example 95 with Font

use of org.eclipse.swt.graphics.Font in project eclipse.platform.swt by eclipse.

the class CTabFolderTab method setItemFont.

/**
 * Sets the font of CTabItem 0.
 */
void setItemFont() {
    if (!instance.startup) {
        tabFolder1.getItem(0).setFont(itemFont);
        setExampleWidgetSize();
    }
    /* Set the font item's image to match the font of the item. */
    Font ft = itemFont;
    if (ft == null)
        ft = tabFolder1.getItem(0).getFont();
    TableItem item = colorAndFontTable.getItem(ITEM_FONT);
    Image oldImage = item.getImage();
    if (oldImage != null)
        oldImage.dispose();
    item.setImage(fontImage(ft));
    item.setFont(ft);
    colorAndFontTable.layout();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font)

Aggregations

Font (org.eclipse.swt.graphics.Font)235 FontData (org.eclipse.swt.graphics.FontData)93 GridData (org.eclipse.swt.layout.GridData)52 Point (org.eclipse.swt.graphics.Point)51 Composite (org.eclipse.swt.widgets.Composite)50 GridLayout (org.eclipse.swt.layout.GridLayout)47 Color (org.eclipse.swt.graphics.Color)45 Label (org.eclipse.swt.widgets.Label)38 Test (org.junit.Test)26 GC (org.eclipse.swt.graphics.GC)22 Image (org.eclipse.swt.graphics.Image)22 Rectangle (org.eclipse.swt.graphics.Rectangle)22 Button (org.eclipse.swt.widgets.Button)19 Display (org.eclipse.swt.widgets.Display)19 SelectionEvent (org.eclipse.swt.events.SelectionEvent)17 Text (org.eclipse.swt.widgets.Text)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)15 StyledText (org.eclipse.swt.custom.StyledText)13 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)12 StyleRange (org.eclipse.swt.custom.StyleRange)11