Search in sources :

Example 81 with FontData

use of org.eclipse.swt.graphics.FontData in project dbeaver by serge-rider.

the class HexPreferencesManager method populateFixedCharWidthFontsAsync.

void populateFixedCharWidthFontsAsync() {
    FontData fontData = getNextFontData();
    if (!fontsRejected.contains(fontData.getName())) {
        boolean isScalable = fontsListCurrent == fontsScalable;
        int height = 10;
        if (!isScalable)
            height = fontData.getHeight();
        Font font = new Font(Display.getCurrent(), fontData.getName(), height, SWT.NORMAL);
        fontsGc.setFont(font);
        int width = fontsGc.getAdvanceWidth((char) 0x020);
        boolean isFixedWidth = true;
        for (int j = 0x021; j < 0x0100 && isFixedWidth; ++j) {
            if (((char) j) == '.' && j != '.')
                continue;
            if (width != fontsGc.getAdvanceWidth((char) j))
                isFixedWidth = false;
        }
        font.dispose();
        if (isFixedWidth) {
            if (isScalable) {
                fontsSorted.put(fontData.getName(), scalableSizes);
            } else {
                Set<Integer> heights = fontsSorted.get(fontData.getName());
                if (heights == null) {
                    heights = new TreeSet<>();
                    fontsSorted.put(fontData.getName(), heights);
                }
                heights.add(fontData.getHeight());
            }
            if (!list.isDisposed())
                list.setItems(fontsSorted.keySet().toArray(new String[fontsSorted.keySet().size()]));
            refreshWidgets();
        } else {
            fontsRejected.add(fontData.getName());
        }
    }
    if (fontsNonScalable.size() == 0 && fontsScalable.size() == 0) {
        if (!parent.isDisposed())
            fontsGc.dispose();
        fontsGc = null;
        fontsNonScalable = fontsScalable = fontsListCurrent = null;
        fontsRejected = null;
    } else {
        DBeaverUI.asyncExec(new Runnable() {

            @Override
            public void run() {
                populateFixedCharWidthFontsAsync();
            }
        });
    }
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font)

Example 82 with FontData

use of org.eclipse.swt.graphics.FontData in project dbeaver by serge-rider.

the class HexPreferencesManager method getNextFontData.

FontData getNextFontData() {
    if (fontsListCurrent.size() == 0) {
        fontsListCurrent = fontsScalable;
    }
    FontData aData = fontsListCurrent.get(0);
    fontsListCurrent.remove(0);
    while (fontsRejected.contains(aData.getName()) && fontsScalable.size() > 0) {
        if (fontsListCurrent.size() == 0) {
            fontsListCurrent = fontsScalable;
        }
        aData = fontsListCurrent.get(0);
        fontsListCurrent.remove(0);
    }
    return aData;
}
Also used : FontData(org.eclipse.swt.graphics.FontData)

Example 83 with FontData

use of org.eclipse.swt.graphics.FontData in project dbeaver by serge-rider.

the class HexPreferencesPage method getPrefFontData.

/**
     * Get font data information common to all plugin editors. Data comes from preferences store.
     *
     * @return font data to be used by plugin editors. Returns null for default font data.
     */
public static FontData getPrefFontData() {
    DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
    String fontName = store.getString(DBeaverPreferences.HEX_FONT_NAME);
    int fontStyle = store.getInt(DBeaverPreferences.HEX_FONT_STYLE);
    int fontSize = store.getInt(DBeaverPreferences.HEX_FONT_SIZE);
    if (!CommonUtils.isEmpty(fontName) && fontSize > 0) {
        return new FontData(fontName, fontSize, fontStyle);
    }
    return null;
}
Also used : FontData(org.eclipse.swt.graphics.FontData) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 84 with FontData

use of org.eclipse.swt.graphics.FontData in project otertool by wuntee.

the class SWTResourceManager method getFont.

/**
	 * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
	 * flags are also supported.
	 * 
	 * @param name
	 *            the name of the font
	 * @param size
	 *            the size of the font
	 * @param style
	 *            the style of the font
	 * @param strikeout
	 *            the strikeout flag (warning: Windows only)
	 * @param underline
	 *            the underline flag (warning: Windows only)
	 * @return {@link Font} The font matching the name, height, style, strikeout and underline
	 */
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
    String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
    Font font = m_fontMap.get(fontName);
    if (font == null) {
        FontData fontData = new FontData(name, size, style);
        if (strikeout || underline) {
            try {
                //$NON-NLS-1$
                Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT");
                //$NON-NLS-1$
                Object logFont = FontData.class.getField("data").get(fontData);
                if (logFont != null && logFontClass != null) {
                    if (strikeout) {
                        //$NON-NLS-1$
                        logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1));
                    }
                    if (underline) {
                        //$NON-NLS-1$
                        logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1));
                    }
                }
            } catch (Throwable e) {
                //$NON-NLS-1$ //$NON-NLS-2$
                System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e);
            }
        }
        font = new Font(Display.getCurrent(), fontData);
        m_fontMap.put(fontName, font);
    }
    return font;
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font)

Example 85 with FontData

use of org.eclipse.swt.graphics.FontData in project otertool by wuntee.

the class SWTResourceManager method getBoldFont.

/**
	 * 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;
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font)

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