Example usage for org.eclipse.jface.resource FontRegistry get

List of usage examples for org.eclipse.jface.resource FontRegistry get

Introduction

In this page you can find the example usage for org.eclipse.jface.resource FontRegistry get.

Prototype

public Font get(String symbolicName) 

Source Link

Document

Returns the font associated with the given symbolic font name.

Usage

From source file:ch.elexis.core.ui.UiDesk.java

License:Open Source License

public static Font getFont(String cfgName) {
    FontRegistry fr = JFaceResources.getFontRegistry();
    if (!fr.hasValueFor(cfgName)) {
        FontData[] fd = PreferenceConverter.getFontDataArray(new SettingsPreferenceStore(CoreHub.userCfg),
                cfgName);/* w  w  w  .  j  a  va 2s.  c o m*/
        fr.put(cfgName, fd);
    }
    return fr.get(cfgName);
}

From source file:ch.elexis.core.ui.UiDesk.java

License:Open Source License

public static Font getFont(String name, int height, int style) {
    String key = name + ":" + Integer.toString(height) + ":" + Integer.toString(style); //$NON-NLS-1$ //$NON-NLS-2$
    FontRegistry fr = JFaceResources.getFontRegistry();
    if (!fr.hasValueFor(key)) {
        FontData[] fd = new FontData[] { new FontData(name, height, style) };
        fr.put(key, fd);//w  w w.  j av  a  2  s.c  o m
    }
    return fr.get(key);
}

From source file:ch.elexis.Desk.java

License:Open Source License

public static Font getFont(String cfgName) {
    FontRegistry fr = JFaceResources.getFontRegistry();
    if (!fr.hasValueFor(cfgName)) {
        FontData[] fd = PreferenceConverter.getFontDataArray(new SettingsPreferenceStore(Hub.userCfg), cfgName);
        fr.put(cfgName, fd);/*from w  w  w.j  a  v a2s  .co m*/
    }
    return fr.get(cfgName);
}

From source file:com.archimatetool.editor.ui.FontFactory.java

License:Open Source License

/**
 * @param fontName// w ww. j  a va2s  . c o  m
 * @return A FOnt for the fontName or the default user font if null or exception occurs
 */
public static Font get(String fontName) {
    if (fontName == null) {
        return getDefaultUserViewFont();
    }

    if (!FontRegistry.hasValueFor(fontName)) {
        try {
            FontData fd = new FontData(fontName);
            FontRegistry.put(fontName, new FontData[] { fd });
        }
        // Can cause exception if using font name from different OS platform
        catch (Exception ex) {
            return getDefaultUserViewFont();
        }
    }

    return FontRegistry.get(fontName);
}

From source file:com.archimatetool.editor.ui.FontFactory.java

License:Open Source License

public static Font getDefaultUserViewFont() {
    // We don't have it, so try to set it
    if (!FontRegistry.hasValueFor(DEFAULT_VIEW_FONT_NAME)) {
        getDefaultUserViewFontData();/*from  w  ww  .  j a v a2s .c  o m*/
    }

    return FontRegistry.get(DEFAULT_VIEW_FONT_NAME);
}

From source file:com.codeaffine.eclipse.ui.swt.theme.FontRegistryUpdater.java

License:Open Source License

private static void updateFontEntry(Display display, FontRegistry fontRegistry, String symbolicName) {
    Font textFont = fontRegistry.get(symbolicName);
    fontRegistry.put(symbolicName, display.getSystemFont().getFontData());
    display.readAndDispatch();//  www  .  j a  va 2  s.c o  m
    fontRegistry.put(symbolicName, textFont.getFontData());
    display.readAndDispatch();
}

From source file:com.essiembre.eclipse.rbe.ui.editor.i18n.BundleEntryComposite.java

License:Apache License

/**
 * Creates the text row./*from  w  ww  . ja  va 2  s  .  co m*/
 */
private void createTextViewerRow() {
    //       int vscroll = RBEPreferences.getAutoAdjust() ? 0 : SWT.V_SCROLL;
    textViewer = new TextViewer(this, SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

    textViewer.setDocument(new Document());
    undoManager = new TextViewerUndoManager(20);
    textViewer.setUndoManager(undoManager);
    textViewer.activatePlugins();
    final StyledText textBox = textViewer.getTextWidget();

    textBox.setEnabled(false);
    // Addition by Eric FETTWEIS
    // Note that this does not seem to work... It would however be useful
    // for arabic and some other languages  
    textBox.setOrientation(getOrientation(locale));

    FontRegistry fontRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
    Font font = fontRegistry.get("com.essiembre.eclipse.rbe.ui.preferences.fontDefinition");
    if (font != null) {
        textBox.setFont(font);
    }

    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    //        gridData.heightHint = UIUtils.getHeightInChars(textBox, 3);
    textBox.setLayoutData(gridData);
    textBox.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent event) {
            textBeforeUpdate = textBox.getText();
        }

        public void focusLost(FocusEvent event) {
            updateBundleOnChanges();
        }
    });

    textBox.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent event) {
            if (event.character == SWT.TAB && !RBEPreferences.getFieldTabInserts()) {
                event.doit = true;
                event.detail = SWT.TRAVERSE_NONE;
                if (event.stateMask == 0) {
                    textViewer.setSelectedRange(0, 0);
                    page.focusNextBundleEntryComposite();
                } else if (event.stateMask == SWT.SHIFT) {
                    textViewer.setSelectedRange(0, 0);
                    page.focusPreviousBundleEntryComposite();
                }
            } else if (event.keyCode == SWT.ARROW_DOWN && event.stateMask == SWT.CTRL) {
                event.doit = true;
                event.detail = SWT.TRAVERSE_NONE;
                page.selectNextTreeEntry();
            } else if (event.keyCode == SWT.ARROW_UP && event.stateMask == SWT.CTRL) {
                event.doit = true;
                event.detail = SWT.TRAVERSE_NONE;
                page.selectPreviousTreeEntry();
            }
        }
    });

    textBox.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent event) {
            if (isKeyCombination(event, SWT.CTRL, 'z')) {
                undoManager.undo();
            } else if (isKeyCombination(event, SWT.CTRL, 'y')) {
                undoManager.redo();
            } else if (isKeyCombination(event, SWT.CTRL, 'a')) {
                textViewer.setSelectedRange(0, textViewer.getDocument().getLength());
            } else {
                StyledText eventBox = (StyledText) event.widget;
                final ITextEditor editor = resourceManager.getSourceEditor(locale).getEditor();
                // Text field has changed: make editor dirty if not already
                if (textBeforeUpdate != null && !textBeforeUpdate.equals(eventBox.getText())) {
                    // Make the editor dirty if not already.  If it is, 
                    // we wait until field focus lost (or save) to 
                    // update it completely.
                    if (!editor.isDirty()) {
                        int caretPosition = eventBox.getCaretOffset();
                        updateBundleOnChanges();
                        eventBox.setSelection(caretPosition);
                    }
                    //autoDetectRequiredFont(eventBox.getText());
                }
            }
        }
    });
    // Eric Fettweis : new listener to automatically change the font 
    textViewer.addTextListener(new ITextListener() {

        String _oldText = null;

        @Override
        public void textChanged(TextEvent event) {
            String text = textBox.getText();
            if (text.equals(_oldText))
                return;
            _oldText = text;

            Font f = textBox.getFont();
            String fontName = getBestFont(f.getFontData()[0].getName(), text);
            if (fontName != null) {
                f = getSWTFont(f, fontName);
                textBox.setFont(f);
            }

            //              ScrolledComposite scrolledComposite = 
            //                      (ScrolledComposite)getParent().getParent();
            //              Point newMinSize = getParent().computeSize(
            //                      scrolledComposite.getClientArea().width, SWT.DEFAULT);
            //              if ( !newMinSize.equals(new Point(
            //                      scrolledComposite.getMinWidth(), 
            //                      scrolledComposite.getMinHeight())) ) {
            //                 page.setAutoAdjustNeeded(true);
            //              }
        }
    });

    textBox.addFocusListener(internalFocusListener);
}

From source file:com.google.appraise.eclipse.ui.editor.DiffAttributeEditor.java

License:Open Source License

/**
 * Starts a new {@link StyleRange} given a specific line type.
 *//*from  www  .  ja v  a2  s.c  o m*/
private StyleRange initDiffStyleRangeForLineType(DiffLineType lineType, int startTextOffset) {
    ColorRegistry reg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
    StyleRange range = new StyleRange();
    range.start = startTextOffset;
    switch (lineType) {
    case ADD:
        range.foreground = reg.get(THEME_DiffAddForegroundColor);
        range.background = reg.get(THEME_DiffAddBackgroundColor);
        break;
    case REMOVE:
        range.foreground = reg.get(THEME_DiffRemoveForegroundColor);
        range.background = reg.get(THEME_DiffRemoveBackgroundColor);
        break;
    case HUNK:
        range.foreground = reg.get(THEME_DiffHunkForegroundColor);
        range.background = reg.get(THEME_DiffHunkBackgroundColor);
        break;
    case HEADLINE:
        range.foreground = reg.get(THEME_DiffHeadlineForegroundColor);
        range.background = reg.get(THEME_DiffHeadlineBackgroundColor);
        FontRegistry fontReg = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
        range.font = fontReg.get(THEME_DiffHeadlineFont);
        break;
    default:
        break;
    }
    return range;
}

From source file:com.hudren.woodpile.views.LogEventView.java

License:Open Source License

private void createTextViewer(final Composite parent) {
    // font = new Font( null, "Courier New", 10, SWT.NORMAL );

    IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
    ITheme currentTheme = themeManager.getCurrentTheme();

    FontRegistry fontRegistry = currentTheme.getFontRegistry();
    Font font = fontRegistry.get("org.eclipse.debug.ui.consoleFont");

    text = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
    text.setFont(font);//w  w  w.  j  a v a2  s.  co m
    text.setCaret(null);
}

From source file:com.redhat.ceylon.eclipse.code.editor.CeylonEditor.java

License:Open Source License

private void setSourceFontFromPreference() {
    String fontName = WorkbenchPlugin.getDefault().getPreferenceStore().getString(JFaceResources.TEXT_FONT);
    FontRegistry fontRegistry = CeylonPlugin.getInstance().getFontRegistry();
    if (!fontRegistry.hasValueFor(fontName)) {
        fontRegistry.put(fontName, PreferenceConverter.readFontData(fontName));
    }//from w  w  w . ja  v  a2  s  . c  om
    Font sourceFont = fontRegistry.get(fontName);
    if (sourceFont != null) {
        getSourceViewer().getTextWidget().setFont(sourceFont);
    }
}