Search in sources :

Example 51 with FontData

use of org.eclipse.swt.graphics.FontData 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 52 with FontData

use of org.eclipse.swt.graphics.FontData 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 53 with FontData

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

the class DialogTab method createButtonSelected.

/**
 * Handle the create button selection event.
 *
 * @param event org.eclipse.swt.events.SelectionEvent
 */
void createButtonSelected(SelectionEvent event) {
    /* Compute the appropriate dialog style */
    int style = getDefaultStyle();
    if (okButton.getEnabled() && okButton.getSelection())
        style |= SWT.OK;
    if (cancelButton.getEnabled() && cancelButton.getSelection())
        style |= SWT.CANCEL;
    if (yesButton.getEnabled() && yesButton.getSelection())
        style |= SWT.YES;
    if (noButton.getEnabled() && noButton.getSelection())
        style |= SWT.NO;
    if (retryButton.getEnabled() && retryButton.getSelection())
        style |= SWT.RETRY;
    if (abortButton.getEnabled() && abortButton.getSelection())
        style |= SWT.ABORT;
    if (ignoreButton.getEnabled() && ignoreButton.getSelection())
        style |= SWT.IGNORE;
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection())
        style |= SWT.ICON_ERROR;
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection())
        style |= SWT.ICON_INFORMATION;
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection())
        style |= SWT.ICON_QUESTION;
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection())
        style |= SWT.ICON_WARNING;
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection())
        style |= SWT.ICON_WORKING;
    if (primaryModalButton.getEnabled() && primaryModalButton.getSelection())
        style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getEnabled() && applicationModalButton.getSelection())
        style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getEnabled() && systemModalButton.getSelection())
        style |= SWT.SYSTEM_MODAL;
    if (sheetButton.getSelection())
        style |= SWT.SHEET;
    if (saveButton.getEnabled() && saveButton.getSelection())
        style |= SWT.SAVE;
    if (openButton.getEnabled() && openButton.getSelection())
        style |= SWT.OPEN;
    if (multiButton.getEnabled() && multiButton.getSelection())
        style |= SWT.MULTI;
    /* Open the appropriate dialog type */
    String name = dialogCombo.getText();
    if (name.equals(ControlExample.getResourceString("ColorDialog"))) {
        ColorDialog dialog = new ColorDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setRGB(colorDialogResult);
            dialog.setRGBs(colorDialogCustomColors);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        RGB result = dialog.open();
        textWidget.append(ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER);
        textWidget.append("getRGBs() =" + Text.DELIMITER);
        RGB[] rgbs = dialog.getRGBs();
        if (rgbs != null) {
            for (RGB rgbColor : rgbs) {
                textWidget.append("\t" + rgbColor + Text.DELIMITER);
            }
        }
        textWidget.append(Text.DELIMITER);
        colorDialogResult = result;
        colorDialogCustomColors = rgbs;
        return;
    }
    if (name.equals(ControlExample.getResourceString("DirectoryDialog"))) {
        DirectoryDialog dialog = new DirectoryDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFilterPath(directoryDialogResult);
        }
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER + Text.DELIMITER);
        directoryDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("FileDialog"))) {
        FileDialog dialog = new FileDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFileName(fileDialogResult);
            dialog.setFilterIndex(fileDialogIndexResult);
        }
        dialog.setFilterNames(FilterNames);
        dialog.setFilterExtensions(FilterExtensions);
        dialog.setText(ControlExample.getResourceString("Title"));
        String result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFilterIndex() =" + dialog.getFilterIndex() + Text.DELIMITER);
        textWidget.append("getFilterPath() =" + dialog.getFilterPath() + Text.DELIMITER);
        textWidget.append("getFileName() =" + dialog.getFileName() + Text.DELIMITER);
        textWidget.append("getFileNames() =" + Text.DELIMITER);
        String[] files = dialog.getFileNames();
        for (String file : files) {
            textWidget.append("\t" + file + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        fileDialogResult = result;
        fileDialogIndexResult = dialog.getFilterIndex();
        return;
    }
    if (name.equals(ControlExample.getResourceString("FontDialog"))) {
        FontDialog dialog = new FontDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setFontList(fontDialogFontListResult);
            dialog.setRGB(fontDialogColorResult);
        }
        dialog.setEffectsVisible(effectsVisibleButton.getSelection());
        dialog.setText(ControlExample.getResourceString("Title"));
        FontData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        textWidget.append("getFontList() =" + Text.DELIMITER);
        FontData[] fonts = dialog.getFontList();
        if (fonts != null) {
            for (FontData font : fonts) {
                textWidget.append("\t" + font + Text.DELIMITER);
            }
        }
        textWidget.append("getEffectsVisible() = " + dialog.getEffectsVisible() + Text.DELIMITER);
        textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
        fontDialogFontListResult = dialog.getFontList();
        fontDialogColorResult = dialog.getRGB();
        return;
    }
    if (name.equals(ControlExample.getResourceString("PrintDialog"))) {
        PrintDialog dialog = new PrintDialog(shell, style);
        if (usePreviousResultButton.getSelection()) {
            dialog.setPrinterData(printDialogResult);
        }
        dialog.setText(ControlExample.getResourceString("Title"));
        PrinterData result = dialog.open();
        textWidget.append(ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
        textWidget.append(ControlExample.getResourceString("Result", "" + result) + Text.DELIMITER);
        if (result != null) {
            textWidget.append("printerData.scope = " + (result.scope == PrinterData.PAGE_RANGE ? "PAGE_RANGE" : result.scope == PrinterData.SELECTION ? "SELECTION" : "ALL_PAGES") + Text.DELIMITER);
            textWidget.append("printerData.startPage = " + result.startPage + Text.DELIMITER);
            textWidget.append("printerData.endPage = " + result.endPage + Text.DELIMITER);
            textWidget.append("printerData.printToFile = " + result.printToFile + Text.DELIMITER);
            textWidget.append("printerData.fileName = " + result.fileName + Text.DELIMITER);
            textWidget.append("printerData.orientation = " + (result.orientation == PrinterData.LANDSCAPE ? "LANDSCAPE" : "PORTRAIT") + Text.DELIMITER);
            textWidget.append("printerData.copyCount = " + result.copyCount + Text.DELIMITER);
            textWidget.append("printerData.collate = " + result.collate + Text.DELIMITER);
            textWidget.append("printerData.duplex = " + (result.duplex == PrinterData.DUPLEX_LONG_EDGE ? "DUPLEX_LONG_EDGE" : result.duplex == PrinterData.DUPLEX_SHORT_EDGE ? "DUPLEX_SHORT_EDGE" : "NONE") + Text.DELIMITER);
        }
        textWidget.append(Text.DELIMITER);
        printDialogResult = result;
        return;
    }
    if (name.equals(ControlExample.getResourceString("MessageBox"))) {
        MessageBox dialog = new MessageBox(shell, style);
        dialog.setMessage(ControlExample.getResourceString("Example_string"));
        dialog.setText(ControlExample.getResourceString("Title"));
        int result = dialog.open();
        textWidget.append(ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
        /*
			 * The resulting integer depends on the original
			 * dialog style.  Decode the result and display it.
			 */
        switch(result) {
            case SWT.OK:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.OK"));
                break;
            case SWT.YES:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.YES"));
                break;
            case SWT.NO:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.NO"));
                break;
            case SWT.CANCEL:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.CANCEL"));
                break;
            case SWT.ABORT:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.ABORT"));
                break;
            case SWT.RETRY:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.RETRY"));
                break;
            case SWT.IGNORE:
                textWidget.append(ControlExample.getResourceString("Result", "SWT.IGNORE"));
                break;
            default:
                textWidget.append(ControlExample.getResourceString("Result", "" + result));
                break;
        }
        textWidget.append(Text.DELIMITER + Text.DELIMITER);
    }
}
Also used : FontDialog(org.eclipse.swt.widgets.FontDialog) PrintDialog(org.eclipse.swt.printing.PrintDialog) FontData(org.eclipse.swt.graphics.FontData) RGB(org.eclipse.swt.graphics.RGB) MessageBox(org.eclipse.swt.widgets.MessageBox) ColorDialog(org.eclipse.swt.widgets.ColorDialog) PrinterData(org.eclipse.swt.printing.PrinterData) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 54 with FontData

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

the class Test_org_eclipse_swt_widgets_FontDialog method test_setFontDataLorg_eclipse_swt_graphics_FontData.

@Test
public void test_setFontDataLorg_eclipse_swt_graphics_FontData() {
    FontData[] fontData = new FontData[1];
    fontData[0] = new FontData();
    assertNull(fontDialog.getFontList());
    fontDialog.setFontList(fontData);
    assertArrayEquals(fontDialog.getFontList(), fontData);
    fontDialog.setFontList(null);
    assertNull(fontDialog.getFontList());
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Test(org.junit.Test)

Example 55 with FontData

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

the class Test_org_eclipse_swt_widgets_List method test_setFontLorg_eclipse_swt_graphics_Font.

@Override
@Test
public void test_setFontLorg_eclipse_swt_graphics_Font() {
    if (SwtTestUtil.isGTK) {
        // TODO Fix GTK failure.
        if (SwtTestUtil.verbose) {
            System.out.println("Excluded test_setFontLorg_eclipse_swt_graphics_Font(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_List)");
        }
        return;
    }
    FontData fontData = list.getFont().getFontData()[0];
    int lineHeight;
    Font font;
    font = new Font(list.getDisplay(), fontData.getName(), 8, fontData.getStyle());
    list.setFont(font);
    lineHeight = list.getItemHeight();
    list.setFont(null);
    font.dispose();
    font = new Font(list.getDisplay(), fontData.getName(), 12, fontData.getStyle());
    list.setFont(font);
    assertEquals(font, list.getFont());
    assertTrue("itemHeight=" + list.getItemHeight() + ", lineHeight=" + lineHeight, list.getItemHeight() > lineHeight);
    list.setFont(null);
    font.dispose();
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font) Test(org.junit.Test)

Aggregations

FontData (org.eclipse.swt.graphics.FontData)147 Font (org.eclipse.swt.graphics.Font)89 GridData (org.eclipse.swt.layout.GridData)30 Label (org.eclipse.swt.widgets.Label)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 Composite (org.eclipse.swt.widgets.Composite)25 Point (org.eclipse.swt.graphics.Point)23 Test (org.junit.Test)21 Color (org.eclipse.swt.graphics.Color)15 FontStyle (org.eclipse.gmf.runtime.notation.FontStyle)14 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)11 Button (org.eclipse.swt.widgets.Button)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 Display (org.eclipse.swt.widgets.Display)9 Text (org.eclipse.swt.widgets.Text)9 GC (org.eclipse.swt.graphics.GC)8 StyleRange (org.eclipse.swt.custom.StyleRange)7 Image (org.eclipse.swt.graphics.Image)7 IOException (java.io.IOException)6