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:net.certiv.fluentmark.preferences.PreviewSourceUpdater.java

License:Open Source License

/**
 * Creates a source preview updater for the given viewer, configuration and preference store.
 *
 * @param viewer the viewer//www  .  j av a 2  s . c  o m
 * @param configuration the configuration
 * @param preferenceStore the preference store
 */
public PreviewSourceUpdater(final SourceViewer viewer, final FluentSourceViewerConfiguration configuration,
        final IPreferenceStore preferenceStore) {
    Assert.isNotNull(viewer);
    Assert.isNotNull(configuration);
    Assert.isNotNull(preferenceStore);
    final IPropertyChangeListener fontChangeListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(Prefs.EDITOR_TEXT_FONT)) {
                Font font = JFaceResources.getFont(Prefs.EDITOR_TEXT_FONT);
                viewer.getTextWidget().setFont(font);
            }
        }
    };
    final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (configuration.affectsTextPresentation(event)) {
                configuration.handlePropertyChangeEvent(event);
                viewer.invalidateTextPresentation();
            }
        }
    };
    viewer.getTextWidget().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            preferenceStore.removePropertyChangeListener(propertyChangeListener);
            JFaceResources.getFontRegistry().removeListener(fontChangeListener);
        }
    });
    JFaceResources.getFontRegistry().addListener(fontChangeListener);
    preferenceStore.addPropertyChangeListener(propertyChangeListener);
}

From source file:net.refractions.udig.feature.panel.FeaturePanelTitle.java

License:Open Source License

/**
 * Constructor for TabbedPropertyTitle./*w  ww  .ja  v a  2  s  .  c  o m*/
 * 
 * @param parent the parent composite.
 * @param factory2 the widget factory for the tabbed property sheet
 */
public FeaturePanelTitle(Composite parent, FeaturePanelWidgetFactory factory) {
    super(parent, SWT.NO_FOCUS);
    this.factory = factory;

    this.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            if (image == null && (text == null || text.equals(BLANK))) {
                label.setVisible(false);
            } else {
                label.setVisible(true);
                drawTitleBackground(e);
            }
        }
    });

    factory.getColors().initializeSectionToolBarColors();
    setBackground(factory.getColors().getBackground());
    setForeground(factory.getColors().getForeground());

    FormLayout layout = new FormLayout();
    layout.marginWidth = 1;
    layout.marginHeight = 2;
    setLayout(layout);

    Font font;
    if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
        FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)
                .getFontData();
        /* title font is 2pt larger than that used in the tabs. */
        fontData[0].setHeight(fontData[0].getHeight() + 2);
        JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
    }
    font = JFaceResources.getFont(TITLE_FONT);

    label = factory.createCLabel(this, BLANK);
    label.setBackground(new Color[] { factory.getColors().getColor(IFormColors.H_GRADIENT_END),
            factory.getColors().getColor(IFormColors.H_GRADIENT_START) }, new int[] { 100 }, true);
    label.setFont(font);
    label.setForeground(factory.getColors().getColor(IFormColors.TITLE));
    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.top = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    label.setLayoutData(data);

    /*
     * setImage(PlatformUI.getWorkbench().getSharedImages().getImage(
     * ISharedImages.IMG_OBJ_ELEMENT));
     */
}

From source file:net.sf.colorer.eclipse.editors.ColorerEditor.java

License:LGPL

public void propertyChange(PropertyChangeEvent e) {

    if (e == null || e.getProperty().equals(PreferencePage.USE_BACK)
            || e.getProperty().equals(PreferencePage.HRD_SET)
            || e.getProperty().startsWith(ColorerPlugin.HRD_SIGNATURE)) {
        String hrd = ColorerPlugin.getDefault().getPropertyHRD(fTextColorer.getFileType());
        if (hrd == null) {
            hrd = prefStore.getString(PreferencePage.HRD_SET);
        }//from w  ww. j ava  2s  . com
        fTextColorer.setRegionMapper(hrd, prefStore.getBoolean(PreferencePage.USE_BACK));
    }

    if (e == null || e.getProperty().equals(PreferencePage.FULL_BACK)) {
        fTextColorer.setFullBackground(prefStore.getBoolean(PreferencePage.FULL_BACK));
    }

    if (e == null || e.getProperty().equals(PreferencePage.HORZ_CROSS)
            || e.getProperty().equals(PreferencePage.VERT_CROSS)) {
        fTextColorer.setCross(prefStore.getBoolean(PreferencePage.HORZ_CROSS),
                prefStore.getBoolean(PreferencePage.VERT_CROSS));
    }

    if (e == null || e.getProperty().equals(PreferencePage.WORD_WRAP)
            || e.getProperty().startsWith(ColorerPlugin.WORD_WRAP_SIGNATURE)) {
        int ww = ColorerPlugin.getDefault().getPropertyWordWrap(fTextColorer.getFileType());
        if (ww == -1) {
            ww = prefStore.getBoolean(PreferencePage.WORD_WRAP) ? 1 : 0;
        }
        text.setWordWrap(ww == 1);
    }
    if (e == null || e.getProperty().equals(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH))
        if (text.getTabs() != prefStore
                .getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH)) {
            text.setTabs(prefStore.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH));
        }

    if (e == null || e.getProperty().equals(PreferencePage.SPACES_FOR_TABS)) {
        if (prefStore.getBoolean(PreferencePage.SPACES_FOR_TABS))
            text.addVerifyListener(tabReplacer);
        else
            text.removeVerifyListener(tabReplacer);
    }

    if (e == null || e.getProperty().equals(PreferencePage.PAIRS_MATCH)) {
        String pairs = prefStore.getString(PreferencePage.PAIRS_MATCH);
        int pmode = TextColorer.HLS_XOR;
        if (pairs.equals("PAIRS_OUTLINE"))
            pmode = TextColorer.HLS_OUTLINE;
        if (pairs.equals("PAIRS_OUTLINE2"))
            pmode = TextColorer.HLS_OUTLINE2;
        if (pairs.equals("PAIRS_NO"))
            pmode = TextColorer.HLS_NONE;

        if (getSourceViewer() instanceof ITextViewerExtension2) {
            fTextColorer.setPairsPainter(pmode);
        }
    }

    if (e == null || e.getProperty().equals(PreferencePage.TEXT_FONT)) {
        Font textFont = JFaceResources.getFont(PreferencePage.TEXT_FONT);
        text.setFont(textFont);
    }

    if (e == null || e.getProperty().equals(PreferencePage.PROJECTION)) {
        if (prefStore.getBoolean(PreferencePage.PROJECTION))
            ((ProjectionViewer) getSourceViewer()).enableProjection();
        else
            ((ProjectionViewer) getSourceViewer()).disableProjection();
    }

    if (e == null || e.getProperty().equals(PreferencePage.BACK_SCALE)) {
        int back_scale = prefStore.getInt(PreferencePage.BACK_SCALE);
        fTextColorer.setBackgroundScale(back_scale);
    }

}

From source file:net.sf.colorer.eclipse.editors.ColorerSourceViewerInformationControl.java

License:LGPL

private SourceViewer createViewer(Composite parent) {
    SourceViewer viewer = new SourceViewer(parent, null, SWT.NONE);

    SourceViewerConfiguration configuration = new SourceViewerConfiguration();
    viewer.configure(configuration);//from w w  w.  j av  a 2  s.  c o  m
    viewer.setEditable(false);
    Font font = JFaceResources.getFont(JFaceResources.TEXT_FONT);
    viewer.getTextWidget().setFont(font);

    return viewer;
}

From source file:net.sourceforge.eclipsetrader.core.ui.PluginPreferencePage.java

License:Open Source License

/**
 * Creates a composite with a highlighted Note entry and a message text.
 * This is designed to take up the full width of the page.
 * /* w  w  w .  j  a va2s.c  o m*/
 * @param font the font to use
 * @param composite the parent composite
 * @param title the title of the note
 * @param message the message for the note
 * @return the composite for the note
 */
protected Composite createNoteComposite(Font font, Composite composite, String title, String message) {
    Composite messageComposite = new Composite(composite, SWT.NONE);
    GridLayout messageLayout = new GridLayout();
    messageLayout.numColumns = 2;
    messageLayout.marginWidth = 0;
    messageLayout.marginHeight = 0;
    messageComposite.setLayout(messageLayout);
    messageComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    messageComposite.setFont(font);

    final Label noteLabel = new Label(messageComposite, SWT.BOLD);
    noteLabel.setText(title);
    noteLabel.setFont(JFaceResources.getBannerFont());
    noteLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));

    final IPropertyChangeListener fontListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (JFaceResources.BANNER_FONT.equals(event.getProperty())) {
                noteLabel.setFont(JFaceResources.getFont(JFaceResources.BANNER_FONT));
            }
        }
    };
    JFaceResources.getFontRegistry().addListener(fontListener);
    noteLabel.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            JFaceResources.getFontRegistry().removeListener(fontListener);
        }
    });

    Label messageLabel = new Label(messageComposite, SWT.WRAP);
    messageLabel.setText(message);
    messageLabel.setFont(font);
    return messageComposite;
}

From source file:org.apache.directory.studio.aciitemeditor.widgets.ACIItemSourceEditorComposite.java

License:Apache License

/**
 * Creates and configures the source editor.
 *
 *//*w  w w . j  a va2 s.c  o m*/
private void createSourceEditor() {
    // create source editor
    sourceEditor = new SourceViewer(this, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    sourceEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // setup basic configuration
    configuration = new ACISourceViewerConfiguration();
    sourceEditor.configure(configuration);

    // set text font
    Font font = JFaceResources.getFont(JFaceResources.TEXT_FONT);
    sourceEditor.getTextWidget().setFont(font);

    // setup document
    IDocument document = new Document();
    sourceEditor.setDocument(document);
}

From source file:org.apache.directory.studio.connection.ui.widgets.CertificateInfoComposite.java

License:Apache License

/**
 * Creates the details tab./*from   ww  w .ja  va  2s .  co  m*/
 */
private void createDetailsTab() {
    SashForm detailsForm = new SashForm(tabFolder, SWT.VERTICAL);
    detailsForm.setLayout(new FillLayout());

    Composite hierarchyContainer = new Composite(detailsForm, SWT.NONE);
    GridLayout hierarchyLayout = new GridLayout(1, false);
    hierarchyLayout.marginTop = 10;
    hierarchyLayout.marginWidth = 10;
    hierarchyContainer.setLayout(hierarchyLayout);
    BaseWidgetUtils.createLabel(hierarchyContainer,
            Messages.getString("CertificateInfoComposite.CertificateHierarchyLabel"), 1); //$NON-NLS-1$
    hierarchyTreeViewer = new TreeViewer(hierarchyContainer);
    hierarchyTreeViewer.getTree().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    hierarchyTreeViewer.setContentProvider(new HierarchyContentProvider());
    hierarchyTreeViewer.setLabelProvider(new HierarchyLabelProvider());
    hierarchyTreeViewer.addSelectionChangedListener(event -> populateCertificateTree());

    Composite certificateContainer = new Composite(detailsForm, SWT.NONE);
    GridLayout certificateLayout = new GridLayout(1, false);
    certificateLayout.marginWidth = 10;
    certificateContainer.setLayout(certificateLayout);
    BaseWidgetUtils.createLabel(certificateContainer,
            Messages.getString("CertificateInfoComposite.CertificateFieldsLabel"), 1); //$NON-NLS-1$
    certificateTree = new Tree(certificateContainer, SWT.BORDER);
    certificateTree.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    certificateTree.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            TreeItem item = (TreeItem) event.item;

            if ((item == null) || (item.getData() == null)) {
                valueText.setText(StringUtils.EMPTY);
            } else {
                valueText.setText(item.getData().toString());
            }
        }
    });

    Composite valueContainer = new Composite(detailsForm, SWT.NONE);
    GridLayout valueLayout = new GridLayout(1, false);
    valueLayout.marginWidth = 10;
    valueLayout.marginBottom = 10;
    valueContainer.setLayout(valueLayout);
    BaseWidgetUtils.createLabel(valueContainer, Messages.getString("CertificateInfoComposite.FieldValuesLabel"), //$NON-NLS-1$
            1);
    valueText = new Text(valueContainer, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    valueText.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    valueText.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
    valueText.setBackground(detailsForm.getBackground());

    // create tab
    detailsForm.setWeights(new int[] { 1, 2, 1 });
    TabItem detailsTab = new TabItem(tabFolder, SWT.NONE, DETAILS_TAB_INDEX);
    detailsTab.setText(Messages.getString("CertificateInfoComposite.Details")); //$NON-NLS-1$
    detailsTab.setControl(detailsForm);
}

From source file:org.apache.directory.studio.ldapbrowser.common.dialogs.HexDialog.java

License:Apache License

/**
 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *///from  ww  w  .  ja v a2s  .  c  o  m
protected Control createDialogArea(Composite parent) {
    // create composite
    Composite composite = (Composite) super.createDialogArea(parent);

    hexText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    hexText.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));

    hexText.setText(toFormattedHex(currentData));
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = convertHorizontalDLUsToPixels((int) (IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH * 1.4));
    gd.heightHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2);
    hexText.setLayoutData(gd);

    applyDialogFont(composite);
    return composite;
}

From source file:org.apache.directory.studio.ldapbrowser.ui.dialogs.properties.ValuePropertyPage.java

License:Apache License

/**
 * {@inheritDoc}// w  ww .  j  a v  a 2s . co m
 */
protected Control createContents(Composite parent) {
    IValue value = getValue(getElement());

    Composite composite = BaseWidgetUtils.createColumnContainer(parent, 1, 1);
    Composite mainGroup = BaseWidgetUtils.createColumnContainer(composite, 2, 1);

    BaseWidgetUtils.createLabel(mainGroup, Messages.getString("ValuePropertyPage.AttributeDescription"), 1); //$NON-NLS-1$
    descriptionText = BaseWidgetUtils.createLabeledText(mainGroup, "", 1); //$NON-NLS-1$

    BaseWidgetUtils.createLabel(mainGroup, Messages.getString("ValuePropertyPage.ValueType"), 1); //$NON-NLS-1$
    typeText = BaseWidgetUtils.createLabeledText(mainGroup, "", 1); //$NON-NLS-1$

    BaseWidgetUtils.createLabel(mainGroup, Messages.getString("ValuePropertyPage.ValueSize"), 1); //$NON-NLS-1$
    sizeText = BaseWidgetUtils.createLabeledText(mainGroup, "", 1); //$NON-NLS-1$

    BaseWidgetUtils.createLabel(mainGroup, Messages.getString("ValuePropertyPage.Data"), 1); //$NON-NLS-1$
    if (value != null && value.isString()) {
        valueText = new Text(mainGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
        valueText.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = convertHorizontalDLUsToPixels((int) (IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2));
        gd.heightHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 4);
        valueText.setLayoutData(gd);
        valueText.setBackground(parent.getBackground());
    } else {
        valueText = BaseWidgetUtils.createLabeledText(mainGroup, "", 1); //$NON-NLS-1$
    }

    if (value != null) {
        super.setMessage(Messages.getString("ValuePropertyPage.Value") //$NON-NLS-1$
                + org.apache.directory.studio.connection.core.Utils.shorten(value.toString(), 30));

        descriptionText.setText(value.getAttribute().getDescription());
        // valueText.setText(LdifUtils.mustEncode(value.getBinaryValue())?"Binary":value.getStringValue());
        valueText.setText(
                value.isString() ? value.getStringValue() : Messages.getString("ValuePropertyPage.Binary")); //$NON-NLS-1$
        typeText.setText(value.isString() ? Messages.getString("ValuePropertyPage.String") //$NON-NLS-1$
                : Messages.getString("ValuePropertyPage.Binary")); //$NON-NLS-1$

        int bytes = value.getBinaryValue().length;
        int chars = value.isString() ? value.getStringValue().length() : 0;
        String size = value.isString() ? chars + (chars > 1 ? Messages.getString("ValuePropertyPage.Characters") //$NON-NLS-1$
                : Messages.getString("ValuePropertyPage.Character")) : ""; //$NON-NLS-1$ //$NON-NLS-2$
        size += Utils.formatBytes(bytes);
        sizeText.setText(size);
    }

    return parent;
}

From source file:org.apache.directory.studio.ldifeditor.widgets.LdifEditorWidget.java

License:Apache License

/**
 * Creates the widget./*from  w  w w .  ja v  a 2 s.  c o  m*/
 * 
 * @param parent the parent
 */
public void createWidget(Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    // create source viewer
    // sourceViewer = new ProjectionViewer(parent, ruler,
    // getOverviewRuler(), true, styles);
    sourceViewer = new SourceViewer(composite, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    sourceViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

    // configure
    sourceViewerConfiguration = new LdifSourceViewerConfiguration(this, this.contentAssistEnabled);
    sourceViewer.configure(sourceViewerConfiguration);

    // set font
    Font font = JFaceResources.getFont(JFaceResources.TEXT_FONT);
    sourceViewer.getTextWidget().setFont(font);

    // setup document
    try {
        editorInput = new NonExistingLdifEditorInput();
        documentProvider = new LdifDocumentProvider();
        documentProvider.connect(editorInput);

        IDocument document = documentProvider.getDocument(editorInput);
        document.set(initialLdif);
        sourceViewer.setDocument(document);
    } catch (CoreException e) {
        e.printStackTrace();
    }

    // listener
    sourceViewer.addTextListener(this);

    // focus
    sourceViewer.getControl().setFocus();
}