Example usage for org.eclipse.jface.resource JFaceResources getFont

List of usage examples for org.eclipse.jface.resource JFaceResources getFont

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getFont.

Prototype

public static Font getFont(String symbolicName) 

Source Link

Document

Returns the font in JFace's font registry with the given symbolic font name.

Usage

From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractEnumerationPropertySection.java

License:Open Source License

/**
 * @see org.eclipse.ui.views.properties.tabbed.ISection#createControls(org.eclipse.swt.widgets.Composite,
 *      org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
 *///  w w  w  . ja va  2 s.c  om
@Override
public void createControls(final Composite parent, final TabbedPropertySheetPage aTabbedPropertySheetPage) {
    super.createControls(parent, aTabbedPropertySheetPage);

    Composite composite = getWidgetFactory().createFlatFormComposite(parent);
    widget = new Combo(composite, SWT.READ_ONLY);

    FormData data;
    data = new FormData();
    data.left = new FormAttachment(0, getStandardLabelWidth(composite, new String[] { getLabelText() }));
    data.right = new FormAttachment(50, 0);
    data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
    ((Control) widget).setLayoutData(data);

    Font font = JFaceResources.getFont(PreferenceConstants.RODIN_MATH_FONT);
    ((Control) widget).setFont(font);

    CLabel nameLabel = getWidgetFactory().createCLabel(composite, getLabelText());
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(((Control) widget), -ITabbedPropertyConstants.HSPACE);
    data.top = new FormAttachment(((Control) widget), 0, SWT.CENTER);
    nameLabel.setLayoutData(data);
    ((Combo) widget).addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            handleComboModified();
        }
    });
}

From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractTablePropertySection.java

License:Open Source License

/**
 * Some tables need to know the owner when creating the table. Since the selection is not always set (in the supertype)
 * when createControls is called, the main creation of controls is delayed until refresh is invoked.
 *
 **///from  ww  w . ja  v a 2s.co  m

private void doCreateControls() {
    singular = getFeature().getUpperBound() == 1;
    Composite composite = getWidgetFactory().createFlatFormComposite(parent);
    FormData data;
    table = getWidgetFactory().createTable(composite, SWT.FILL | SWT.FULL_SELECTION);
    createTable();
    table.setFont(JFaceResources.getFont(PreferenceConstants.RODIN_MATH_FONT));
    editor = new TableEditor(table);
    editor.grabHorizontal = true;
    Shell shell = new Shell();
    GC gc = new GC(shell);
    gc.setFont(shell.getFont());
    Point point = gc.textExtent("");
    int buttonHeight = point.y + 11;
    gc.dispose();
    shell.dispose();

    FormAttachment leftData = null;

    //label
    if (getTableLabel() != null) {
        CLabel nameLabel = getWidgetFactory().createCLabel(composite, getTableLabel());
        data = new FormData();
        data.left = new FormAttachment(0, 0);
        data.right = new FormAttachment(table, -ITabbedPropertyConstants.HSPACE);
        data.top = new FormAttachment(table, 0, SWT.CENTER);
        nameLabel.setLayoutData(data);
        leftData = new FormAttachment(0, getStandardLabelWidth(composite, new String[] { getTableLabel() }));
    } else {
        leftData = new FormAttachment(0, 0);
    }

    FormAttachment buttonTopData = null;
    FormAttachment buttonBottomData = null;
    if (singular) {
        buttonTopData = new FormAttachment(table, 0);
        buttonBottomData = new FormAttachment(table, buttonHeight + 6, SWT.BOTTOM);
    } else {
        buttonTopData = new FormAttachment(100, -buttonHeight);
        buttonBottomData = new FormAttachment(100, 0);
    }

    //add button
    addButton = getWidgetFactory().createButton(composite,
            MessageFormat.format("Add {0}", new Object[] { getButtonLabelText() }), SWT.PUSH);
    data = new FormData();
    data.left = leftData;
    data.bottom = buttonBottomData;
    data.top = buttonTopData;
    addButton.setLayoutData(data);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            addButtonAction();
        }
    });

    //delete button
    removeButton = getWidgetFactory().createButton(composite,
            MessageFormat.format("Delete {0}", new Object[] { getButtonLabelText() }), SWT.PUSH);
    data = new FormData();
    data.left = new FormAttachment(addButton, ITabbedPropertyConstants.VSPACE, SWT.BOTTOM);
    data.bottom = buttonBottomData;
    data.top = buttonTopData;
    removeButton.setLayoutData(data);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            removeButtonAction();
        }
    });
    Button lastButton = removeButton;

    //move buttons
    if (!singular) {
        //up button
        upButton = getWidgetFactory().createButton(composite, MessageFormat.format("Move Up", new Object[] {}),
                SWT.PUSH);
        data = new FormData();
        data.left = new FormAttachment(lastButton, ITabbedPropertyConstants.VSPACE, SWT.BOTTOM);
        data.bottom = buttonBottomData;
        data.top = buttonTopData;
        upButton.setLayoutData(data);
        upButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent event) {
                upButtonAction();
            }
        });
        //down button
        downButton = getWidgetFactory().createButton(composite,
                MessageFormat.format("Move Down", new Object[] {}), SWT.PUSH);
        data = new FormData();
        data.left = new FormAttachment(upButton, ITabbedPropertyConstants.VSPACE, SWT.BOTTOM);
        data.bottom = buttonBottomData;
        data.top = buttonTopData;
        downButton.setLayoutData(data);
        downButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent event) {
                downButtonAction();
            }
        });
        lastButton = downButton;
    }

    //main table layout and row selection
    data = new FormData();
    data.left = leftData;
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
    if (!singular) {
        data.bottom = new FormAttachment(addButton, -ITabbedPropertyConstants.VSPACE);
    }
    data.width = 400;
    table.setLayoutData(data);
    table.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            rowSelectionAction();
        }
    });

}

From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractTableViewPropertySection.java

License:Open Source License

/**
 * @see org.eclipse.ui.views.properties.tabbed.ISection#createControls(org.eclipse.swt.widgets.Composite,
 *      org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
 *//*from   w ww. j  a v a 2  s.  c om*/
@Override
public void createControls(final Composite parent, final TabbedPropertySheetPage aTabbedPropertySheetPage) {
    super.createControls(parent, aTabbedPropertySheetPage);
    Composite composite = getWidgetFactory().createFlatFormComposite(parent);

    FormData data;

    table = getWidgetFactory().createTable(composite, SWT.FULL_SELECTION | SWT.READ_ONLY | SWT.SCROLL_LOCK); //SWT.H_SCROLL | SWT.V_SCROLL

    Font font = JFaceResources.getFont(PreferenceConstants.RODIN_MATH_FONT);
    table.setFont(font);

    data = new FormData();
    data.left = new FormAttachment(0, getStandardLabelWidth(composite, new String[] { getTableLabel() }));
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
    table.setLayoutData(data);

    CLabel nameLabel = getWidgetFactory().createCLabel(composite, getTableLabel());
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(table, -ITabbedPropertyConstants.HSPACE);
    data.top = new FormAttachment(table, 0, SWT.CENTER);
    nameLabel.setLayoutData(data);

    List<?> labels = getColumnLabelText();
    columns = new ArrayList<TableColumn>();

    for (Iterator<?> i = labels.iterator(); i.hasNext();) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText((String) i.next());
        columns.add(column);
    }

    if (columns.size() > 2) {
        table.setHeaderVisible(true);
    } else {
        table.setHeaderVisible(false);
    }

    table.setLinesVisible(false);
    table.setEnabled(false);

    Shell shell = new Shell();
    GC gc = new GC(shell);
    gc.setFont(shell.getFont());

    gc.dispose();
    shell.dispose();

}

From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractTextPropertySection.java

License:Open Source License

@Override
public void createControls(final Composite parent, final TabbedPropertySheetPage tabbedPropertySheetPage) {
    super.createControls(parent, tabbedPropertySheetPage);
    Composite composite = getWidgetFactory().createFlatFormComposite(parent);
    FormData data;// ww w .j  a va  2 s . c o m
    widget = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$
    data = new FormData();
    data.left = new FormAttachment(0, getStandardLabelWidth(composite, new String[] { getLabelText() }));
    data.right = new FormAttachment(getTextWidth(), 0);
    data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
    ((Control) widget).setLayoutData(data);

    CLabel nameLabel = getWidgetFactory().createCLabel(composite, getLabelText());
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(((Control) widget), -ITabbedPropertyConstants.HSPACE);
    data.top = new FormAttachment(((Control) widget), 0, SWT.CENTER);
    nameLabel.setLayoutData(data);
    ((Text) widget).addModifyListener(eventBListener);
    // Using a special fonts for showing Event-B symbols.
    Font font = JFaceResources.getFont(PreferenceConstants.RODIN_MATH_FONT);
    ((Control) widget).setFont(font);

    listener = new TextChangeHelper() {

        @Override
        public void textChanged(final Control control) {
            handleTextModified();
        }
    };
    listener.startListeningTo(((Text) widget));
    listener.startListeningForEnter(((Text) widget));
}

From source file:ac.soton.eventb.statemachines.diagram.edit.parts.InvariantEditPart.java

License:Open Source License

/**
 * @generated NOT//from  w w w. j  a v a  2 s.co  m
 */
protected DirectEditManager getManager() {
    if (manager == null) {
        setManager(new TextDirectEditManager(this, TextDirectEditManager.getTextCellEditorClass(this),
                StatemachinesEditPartFactory.getTextCellEditorLocator(this)) {
            //FIXME: refactor this to use a custom external class;
            // maybe generate code from templates
            @Override
            protected void initCellEditor() {
                super.initCellEditor();
                Text text = (Text) getCellEditor().getControl();
                Font font = JFaceResources.getFont(PreferenceConstants.RODIN_MATH_FONT);
                text.setFont(font);
                ModifyListener eventBListener = RodinKeyboardUIPlugin.getDefault().createRodinModifyListener();
                text.addModifyListener(eventBListener);
            }
        });
    }
    return manager;
}

From source file:arche.modifChangeImpact.ModifChangeImpactRFView.java

License:Open Source License

/**
 * Called by Eclipse to create the view and initialize it.
 *//* w  w w  . j  av a 2 s. co  m*/
public void createPartControl(Composite parent) {

    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));

    consoleText = new Text(composite, SWT.V_SCROLL | SWT.H_SCROLL);
    consoleText.setLayoutData(new GridData(GridData.FILL_BOTH));
    consoleText.setEditable(false);
    consoleText.setText("RF> Welcome to the Modifiability (Change Impact) Reasoning Framework!!!\n");
    consoleText.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));

    consoleText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    consoleColor = new Color(Display.getDefault(), new RGB(0, 0, 0));
    consoleText.setForeground(consoleColor);

    Composite bottomLine = new Composite(composite, SWT.NULL);
    GridLayout layout2 = new GridLayout();
    layout2.marginHeight = 0;
    layout2.marginWidth = 0;
    layout2.numColumns = 4;
    bottomLine.setLayout(layout2);
    bottomLine.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    startButton = new Button(bottomLine, SWT.PUSH);
    startButton.setText("Start");
    startButton.setEnabled(true);
    startButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent se) {
            consoleText.setText("RF> Service started\n");
            startButton.setEnabled(false);
            stopButton.setEnabled(true);
            startReasoningFramework();
        }

        public void widgetDefaultSelected(SelectionEvent se) {
        }
    });

    stopButton = new Button(bottomLine, SWT.PUSH);
    stopButton.setText("Stop");
    stopButton.setEnabled(false);
    stopButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent se) {
            consoleText.setText("RF> Service stopped\n");
            startButton.setEnabled(true);
            stopButton.setEnabled(false);
            stopReasoningFramework();
        }

        public void widgetDefaultSelected(SelectionEvent se) {
        }
    });

    clearButton = new Button(bottomLine, SWT.PUSH);
    clearButton.setText("Clear");
    clearButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent se) {
            consoleText.setText("");
        }

        public void widgetDefaultSelected(SelectionEvent se) {
        }
    });

    //        jessButton = new Button(bottomLine, SWT.PUSH);
    //        jessButton.setText("JessEngine");
    //        jessButton.addSelectionListener(new SelectionListener() {
    //
    //            public void widgetSelected(SelectionEvent se) {
    //               
    //               if (watchWindow == null) {
    //                  Rete engine = null; //JessDataProvider.getDefaultJessEngine();
    //                  watchWindow = new JessEngineWatchWindow(null,"Jess Watch --> ",rf.getID(),engine);
    //               }
    //              watchWindow.open();
    //            }
    //
    //            public void widgetDefaultSelected(SelectionEvent se) {
    //            }
    //        });

    hookUpToReasoningFramework();
}

From source file:au.gov.ga.earthsci.jface.extras.information.html.BrowserInformationControl.java

License:Open Source License

/**
 * Creates and initializes the text layout used
 * to compute the size hint./*w w w  .  j a  va  2 s.co m*/
 * 
 * @since 3.2
 */
private void createTextLayout() {
    fTextLayout = new TextLayout(fBrowser.getDisplay());

    // Initialize fonts
    String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
    Font font = JFaceResources.getFont(symbolicFontName);
    fTextLayout.setFont(font);
    fTextLayout.setWidth(-1);
    font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
    fBoldStyle = new TextStyle(font, null, null);

    // Compute and set tab width
    fTextLayout.setText("    "); //$NON-NLS-1$
    int tabWidth = fTextLayout.getBounds().width;
    fTextLayout.setTabs(new int[] { tabWidth });
    fTextLayout.setText(""); //$NON-NLS-1$
}

From source file:au.gov.ga.earthsci.jface.extras.information.html.BrowserInformationControl.java

License:Open Source License

public Point computeSizeConstraints(int widthInChars, int heightInChars) {
    if (fSymbolicFontName == null)
        return null;

    GC gc = new GC(fBrowser);
    Font font = fSymbolicFontName == null ? JFaceResources.getDialogFont()
            : JFaceResources.getFont(fSymbolicFontName);
    gc.setFont(font);//w w  w. j  a v  a2s. c om
    int width = gc.getFontMetrics().getAverageCharWidth();
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();

    return new Point(widthInChars * width, heightInChars * height);
}

From source file:ca.edchipman.silverstripepdt.wizards.NewSilverStripeTemplatesWizardPage.java

License:Open Source License

/**
 * Creates, configures and returns a source viewer to present the template
 * pattern on the preference page. Clients may override to provide a
 * custom source viewer featuring e.g. syntax coloring.
 * //from   w  w w. j a va  2s  .c  o  m
 * @param parent
 *            the parent control
 * @return a configured source viewer
 */
private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {
        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationHTML();

        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer viewer = new StructuredTextViewer(parent, null, null, false,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$
    IStructuredModel scratchModel = StructuredModelManager.getModelManager()
            .createUnManagedStructuredModelFor(ContentTypeIdForHTML.ContentTypeID_HTML);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}

From source file:cc.warlock.rcp.ui.WarlockText.java

License:Open Source License

private void loadSettings() {
    if (settingListener != null)
        settingListener.remove();//from w ww.  ja va2s. com

    if (textWidget.isDisposed())
        return;

    IClientSettings settings = null;
    if (client != null)
        settings = client.getClientSettings();

    if (settings == null)
        settings = ClientSettings.getGlobalClientSettings();

    WindowConfigurationProvider provider = WindowConfigurationProvider.getProvider(settings);
    settingListener = new WindowSettingsListener(provider);

    // Set to defaults first, then try window settings later
    Color background = ColorUtil.warlockColorToColor(provider.getWindowBackground(streamName));
    Color foreground = ColorUtil.warlockColorToColor(provider.getWindowForeground(streamName));
    IWarlockFont font = provider.getWindowFont(streamName);

    textWidget.setBackground(background);
    textWidget.setForeground(foreground);

    if (font.isDefaultFont()) {
        String defaultFontFace = GameViewConfiguration.getProvider(settings).getDefaultFontFace();
        int defaultFontSize = GameViewConfiguration.getProvider(settings).getDefaultFontSize();
        textWidget.setFont(new Font(Display.getDefault(), defaultFontFace, defaultFontSize, SWT.NORMAL));
    } else {
        textWidget.setFont(FontUtil.warlockFontToFont(font));
    }

    IWarlockFont columnFont = provider.getWindowMonoFont(streamName);
    if (columnFont == null || columnFont.isDefaultFont()) {
        this.monoFont = JFaceResources.getFont(JFaceResources.TEXT_FONT);
    } else {
        String fontFace = columnFont.getFamilyName();
        int fontSize = columnFont.getSize();
        this.monoFont = new Font(getTextWidget().getDisplay(), fontFace, fontSize, SWT.NORMAL);
    }
}