Search in sources :

Example 86 with FontData

use of org.eclipse.swt.graphics.FontData in project MonjaDB by Kanatoko.

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

use of org.eclipse.swt.graphics.FontData in project MonjaDB by Kanatoko.

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

use of org.eclipse.swt.graphics.FontData in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method createDialogArea.

/**
     * Create contents of the dialog.
     * @param parent
     */
@Override
protected Control createDialogArea(Composite parent) {
    setMessage("Select App Service to deploy to:");
    setTitle("Deploy Web App");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    GridData gd_container = new GridData(GridData.FILL_BOTH);
    gd_container.widthHint = 750;
    container.setLayoutData(gd_container);
    table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION);
    GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_table.heightHint = 300;
    table.setLayoutData(gd_table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn tblclmnName = new TableColumn(table, SWT.LEFT);
    tblclmnName.setWidth(230);
    tblclmnName.setText("Name");
    TableColumn tblclmnJdk = new TableColumn(table, SWT.LEFT);
    tblclmnJdk.setWidth(60);
    tblclmnJdk.setText("JDK");
    TableColumn tblclmnWebContainer = new TableColumn(table, SWT.LEFT);
    tblclmnWebContainer.setWidth(110);
    tblclmnWebContainer.setText("Web container");
    TableColumn tblclmnResourceGroup = new TableColumn(table, SWT.LEFT);
    tblclmnResourceGroup.setWidth(190);
    tblclmnResourceGroup.setText("Resource group");
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayout(new RowLayout(SWT.VERTICAL));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    Button btnCreate = new Button(composite, SWT.NONE);
    btnCreate.setLayoutData(new RowData(90, SWT.DEFAULT));
    btnCreate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sendTelemetry("CREATE");
            createAppService();
        //cleanError();
        }
    });
    btnCreate.setText("Create...");
    btnDelete = new Button(composite, SWT.NONE);
    btnDelete.setEnabled(false);
    btnDelete.setLayoutData(new RowData(90, SWT.DEFAULT));
    btnDelete.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sendTelemetry("DELETE");
            deleteAppService();
        //cleanError();
        }
    });
    btnDelete.setText("Delete...");
    Button btnRefresh = new Button(composite, SWT.NONE);
    btnRefresh.setLayoutData(new RowData(90, SWT.DEFAULT));
    btnRefresh.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sendTelemetry("REFRESH");
            //cleanError();
            table.removeAll();
            //browserAppServiceDetailes.setText("");
            fillAppServiceDetails();
            AzureModel.getInstance().setResourceGroupToWebAppMap(null);
            fillTable();
        }
    });
    btnRefresh.setText("Refresh");
    Group grpAppServiceDetails = new Group(container, SWT.NONE);
    grpAppServiceDetails.setLayout(new FillLayout(SWT.HORIZONTAL));
    GridData gd_grpAppServiceDetails = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_grpAppServiceDetails.heightHint = 150;
    grpAppServiceDetails.setLayoutData(gd_grpAppServiceDetails);
    grpAppServiceDetails.setText("App service details");
    browserAppServiceDetailes = new Browser(grpAppServiceDetails, SWT.NONE);
    FontData browserFontData = btnRefresh.getFont().getFontData()[0];
    //browserFontStyle = String.format("font-family: '%s';", browserFontData.getHeight(), browserFontData.getName());
    browserFontStyle = String.format("font-family: '%s'; font-size: 9pt;", browserFontData.getName());
    browserAppServiceDetailes.addLocationListener(new LocationListener() {

        public void changing(LocationEvent event) {
            try {
                //System.out.println("LocationEvent.location: " + event.location);
                if (event.location.contains(ftpLinkString)) {
                    event.doit = false;
                    showFtpCreadentialsWindow();
                }
                if (event.location.contains("http")) {
                    event.doit = false;
                    PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(event.location));
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "changing@LocationListener@browserAppServiceDetailes@AppServiceCreateDialog", ex));
            }
        }

        public void changed(LocationEvent event) {
        }
    });
    new Label(container, SWT.NONE);
    btnDeployToRoot = new Button(container, SWT.CHECK);
    btnDeployToRoot.setText("Deploy to root");
    new Label(container, SWT.NONE);
    table.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            fillAppServiceDetails();
        }
    });
    return area;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Listener(org.eclipse.swt.widgets.Listener) LocationListener(org.eclipse.swt.browser.LocationListener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException) CanceledByUserException(com.microsoft.azuretools.utils.CanceledByUserException) IOException(java.io.IOException) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) LocationListener(org.eclipse.swt.browser.LocationListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) LocationEvent(org.eclipse.swt.browser.LocationEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 89 with FontData

use of org.eclipse.swt.graphics.FontData in project tdi-studio-se by Talend.

the class DebugProcessTosComposite method setConsoleFont.

private boolean setConsoleFont() {
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    String fontType = preferenceStore.getString(RunProcessPrefsConstants.CONSOLE_FONT);
    if (StringUtils.isNotEmpty(fontType)) {
        FontData fontData = new FontData(fontType);
        if (consoleText.getFont() != null) {
            FontData oldFont = consoleText.getFont().getFontData()[0];
            // font is same
            if (oldFont.equals(fontData)) {
                return false;
            }
        }
        Font font = new Font(this.getDisplay(), fontData);
        consoleText.setFont(font);
        return true;
    }
    return false;
}
Also used : FontData(org.eclipse.swt.graphics.FontData) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Font(org.eclipse.swt.graphics.Font)

Example 90 with FontData

use of org.eclipse.swt.graphics.FontData in project tdi-studio-se by Talend.

the class ProcessComposite method setConsoleFont.

/**
     * DOC chuang Comment method "setConsoleFont".
     */
private void setConsoleFont() {
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    FontData fontData = PreferenceConverter.getFontData(preferenceStore, TalendDesignerPrefConstants.CONSOLT_TEXT_FONT);
    if (fontData != null) {
        if (consoleText.getFont() != null) {
            FontData oldFont = consoleText.getFont().getFontData()[0];
            // font is same
            if (!oldFont.equals(fontData)) {
                Font font = new Font(this.getDisplay(), fontData);
                consoleText.setFont(font);
            }
        // else no need to change the font it is the same
        } else {
            Font font = new Font(this.getDisplay(), fontData);
            consoleText.setFont(font);
        }
    } else {
        // should never happend
        //$NON-NLS-1$
        log.info("Could not find default font for the console");
    }
}
Also used : FontData(org.eclipse.swt.graphics.FontData) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) 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