Search in sources :

Example 56 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

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 57 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

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)

Example 58 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

the class CustomMediaFactory method getFont.

/**
 * Create the <code>Font</code> for the given information.
 *
 * @param name
 *            The font name.
 * @param height
 *            The font height.
 * @param style
 *            The font style.
 * @return The <code>Font</code> for the given information.
 */
public Font getFont(final String name, final int height, final int style) {
    // $NON-NLS-1$
    assert name != null : "name!=null";
    FontData fd = new FontData(name, height, style);
    String key = String.valueOf(fd.hashCode());
    if (!_fontRegistry.hasValueFor(key)) {
        _fontRegistry.put(key, new FontData[] { fd });
    }
    return _fontRegistry.get(key);
}
Also used : FontData(org.eclipse.swt.graphics.FontData)

Example 59 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

the class CustomMediaFactory method getFont.

/**
 * Create the <code>Font</code> for the given <code>FontData</code> and the
 * given style code.
 *
 * @param fontData
 *            The <code>FontData</code>
 * @param style
 *            The style code.
 * @return The <code>Font</code> for the given <code>FontData</code> and the
 *         given style code.
 */
public Font getFont(final FontData[] fontData, final int style) {
    FontData f = fontData[0];
    Font font = getFont(f.getName(), f.getHeight(), style);
    return font;
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font)

Example 60 with FontData

use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.

the class FontProperty method writeToXML.

@Override
public void writeToXML(Element propElement) {
    OPIFont opiFont = (OPIFont) getPropertyValue();
    Element fontElement;
    if (!opiFont.isPreDefined()) {
        fontElement = new Element(XML_ELEMENT_FONT);
    } else {
        fontElement = new Element(XML_ELEMENT_FONTNAME);
        fontElement.setText(opiFont.getFontMacroName());
    }
    FontData fontData = opiFont.getRawFontData();
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_NAME, fontData.getName());
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_HEIGHT, // $NON-NLS-1$
    "" + fontData.getHeight());
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_STYLE, // $NON-NLS-1$
    "" + fontData.getStyle());
    fontElement.setAttribute(XML_ATTRIBUTE_FONT_PIXELS, "" + opiFont.isSizeInPixels());
    propElement.addContent(fontElement);
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) Element(org.jdom.Element) FontData(org.eclipse.swt.graphics.FontData)

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