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

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

Introduction

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

Prototype

public static FontRegistry getFontRegistry() 

Source Link

Document

Returns the font registry for JFace itself.

Usage

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);/*from   w  w w .j  ava2s.  c om*/
    }
    return fr.get(key);
}

From source file:ch.elexis.Desk.java

License:Open Source License

public static void updateFont(String cfgName) {
    FontRegistry fr = JFaceResources.getFontRegistry();
    FontData[] fd = PreferenceConverter.getFontDataArray(new SettingsPreferenceStore(Hub.userCfg), cfgName);
    fr.put(cfgName, fd);/*from   w ww. j a  v a  2  s  .  co m*/
}

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  a  2s  . c o  m
    }
    return fr.get(cfgName);
}

From source file:chuck.terran.admin.ui.jface.LineFieldEditor.java

License:Open Source License

/**
 * Computes the size of the color image displayed on the button.
 * <p>//from   ww w .ja  v a 2 s .c o  m
 * This is an internal method and should not be called by clients.
 * </p>
 *
 * @param window
 *            the window to create a GC on for calculation.
 * @return Point The image size
 *
 */
protected Point computeImageSize(Control window) {
    // Make the image height as high as a corresponding character. This
    // makes sure that the button has the same size as a "normal" text
    // button.
    GC gc = new GC(window);
    Font f = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
    gc.setFont(f);
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();
    Point p = new Point(height * 3 - 6, height);
    return p;
}

From source file:chuck.terran.admin.ui.jface.LineSelector.java

License:Open Source License

/**
 * Compute the size of the image to be displayed.
 *
 * @param window -/*from   w ww . j  a  v a 2  s .co  m*/
 *            the window used to calculate
 * @return <code>Point</code>
 */
private Point computeImageSize(Control window) {
    GC gc = new GC(window);
    Font f = JFaceResources.getFontRegistry().get(JFaceResources.DIALOG_FONT);
    gc.setFont(f);
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();
    Point p = new Point(height * 3 - 6, height);
    return p;
}

From source file:com.amalto.workbench.widgets.FilteredCheckboxTree.java

License:Open Source License

/**
 * Return a bold font if the given element matches the given pattern. Clients can opt to call this method from a
 * Viewer's label provider to get a bold font for which to highlight the given element in the tree.
 * /*from   ww w .j  a  va  2  s  .  c  om*/
 * @param element element for which a match should be determined
 * @param tree FilteredTree in which the element resides
 * @param filter PatternFilter which determines a match
 * 
 * @return bold font
 */
public static Font getBoldFont(Object element, FilteredCheckboxTree tree, PatternFilter filter) {
    String filterText = tree.getFilterString();

    if (filterText == null) {
        return null;
    }

    // Do nothing if it's empty string
    String initialText = tree.getInitialText();
    if (!("".equals(filterText) || initialText.equals(filterText))) {//$NON-NLS-1$
        boolean initial = initialText != null && initialText.equals(filterText);
        if (initial) {
            filter.setPattern(null);
        } else if (filterText != null) {
            filter.setPattern(filterText);
        }

        if (filter.isElementVisible(tree.getViewer(), element)) {
            return JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
        }
    }
    return null;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.AccordionControl.java

License:Open Source License

/**
 * Create the composite.//from   w  w  w.  j a va 2s .  c o m
 *
 * @param parent the parent widget to add the accordion to
 * @param style the SWT style mask to use
 * @param headers a list of headers, whose {@link Object#toString} method should
 *            produce the heading label
 * @param greedy if true, grow vertically as much as possible
 * @param wrapChildren if true, configure the child area to be horizontally laid out
 *            with wrapping
 * @param expand Set of headers to expand initially
 */
public AccordionControl(Composite parent, int style, List<?> headers, boolean greedy, boolean wrapChildren,
        Set<String> expand) {
    super(parent, style);
    mWrap = wrapChildren;

    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.verticalSpacing = HEADER_SPACING;
    gridLayout.horizontalSpacing = 0;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    setLayout(gridLayout);

    Font labelFont = null;

    mOpen = IconFactory.getInstance().getIcon("open-folder"); //$NON-NLS-1$
    mClosed = IconFactory.getInstance().getIcon("closed-folder"); //$NON-NLS-1$
    List<CLabel> expandLabels = new ArrayList<CLabel>();

    for (Object header : headers) {
        final CLabel label = new CLabel(this, SWT.SHADOW_OUT);
        label.setText(header.toString().replace("&", "&&")); //$NON-NLS-1$ //$NON-NLS-2$
        updateBackground(label, false);
        if (labelFont == null) {
            labelFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
        }
        label.setFont(labelFont);
        label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        setHeader(header, label);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseUp(MouseEvent e) {
                if (e.button == 1 && (e.stateMask & SWT.MODIFIER_MASK) == 0) {
                    toggle(label, true, mSingle);
                }
            }
        });
        label.addMouseTrackListener(new MouseTrackListener() {
            @Override
            public void mouseEnter(MouseEvent e) {
                updateBackground(label, true);
            }

            @Override
            public void mouseExit(MouseEvent e) {
                updateBackground(label, false);
            }

            @Override
            public void mouseHover(MouseEvent e) {
            }
        });

        // Turn off border?
        final ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
        ScrollBar verticalBar = scrolledComposite.getVerticalBar();
        verticalBar.setIncrement(20);
        verticalBar.setPageIncrement(100);

        // Do we need the scrolled composite or can we just look at the next
        // wizard in the hierarchy?

        setContentArea(label, scrolledComposite);
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);
        GridData scrollGridData = new GridData(SWT.FILL, greedy ? SWT.FILL : SWT.TOP, false, greedy, 1, 1);
        scrollGridData.exclude = true;
        scrollGridData.grabExcessHorizontalSpace = wrapChildren;
        scrolledComposite.setLayoutData(scrollGridData);

        if (wrapChildren) {
            scrolledComposite.addControlListener(new ControlAdapter() {
                @Override
                public void controlResized(ControlEvent e) {
                    Rectangle r = scrolledComposite.getClientArea();
                    Control content = scrolledComposite.getContent();
                    if (content != null && r != null) {
                        Point minSize = content.computeSize(r.width, SWT.DEFAULT);
                        scrolledComposite.setMinSize(minSize);
                        ScrollBar vBar = scrolledComposite.getVerticalBar();
                        vBar.setPageIncrement(r.height);
                    }
                }
            });
        }

        updateIcon(label);
        if (expand != null && expand.contains(label.getText())) {
            // Comparing "label.getText()" rather than "header" because we make some
            // tweaks to the label (replacing & with && etc) and in the getExpandedCategories
            // method we return the label texts
            expandLabels.add(label);
        }
    }

    // Expand the requested categories
    for (CLabel label : expandLabels) {
        toggle(label, false, false);
    }
}

From source file:com.android.ide.eclipse.adt.internal.wizards.templates.ActivityPage.java

License:Open Source License

@SuppressWarnings("unused") // SWT constructors have side effects and aren't unused
private void onEnter() {
    Composite container = (Composite) getControl();
    container.setLayout(new GridLayout(3, false));

    if (mAskCreate) {
        mCreateToggle = new Button(container, SWT.CHECK);
        mCreateToggle.setSelection(true);
        mCreateToggle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
        mCreateToggle.setText("Create Activity");
        mCreateToggle.addSelectionListener(this);
    }/*from  w ww .  j av  a2 s .c o  m*/

    mList = new List(container, SWT.BORDER | SWT.V_SCROLL);
    mList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    TemplateManager manager = mValues.template.getManager();
    java.util.List<File> templates = manager.getTemplates(CATEGORY_ACTIVITIES);

    if (!mOnlyActivities) {
        templates.addAll(manager.getTemplates(CATEGORY_OTHER));
    }
    java.util.List<String> names = new ArrayList<String>(templates.size());
    File current = mValues.activityValues.getTemplateLocation();
    mTemplates = Lists.newArrayListWithExpectedSize(templates.size());
    int index = -1;
    for (int i = 0, n = templates.size(); i < n; i++) {
        File template = templates.get(i);
        TemplateMetadata metadata = manager.getTemplate(template);
        if (metadata == null) {
            continue;
        }
        if (mLauncherActivitiesOnly) {
            Parameter parameter = metadata.getParameter(IS_LAUNCHER);
            if (parameter == null) {
                continue;
            }
        }
        mTemplates.add(template);
        names.add(metadata.getTitle());
        if (template.equals(current)) {
            index = names.size();
        }
    }
    String[] items = names.toArray(new String[names.size()]);
    mList.setItems(items);
    if (index == -1 && !mTemplates.isEmpty()) {
        mValues.activityValues.setTemplateLocation(mTemplates.get(0));
        index = 0;
    }
    if (index >= 0) {
        mList.setSelection(index);
        mList.addSelectionListener(this);
    }

    // Preview
    mPreview = new ImageControl(container, SWT.NONE, null);
    mPreview.setDisposeImage(false); // Handled manually in this class
    GridData gd_mImage = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
    gd_mImage.widthHint = PREVIEW_WIDTH + 2 * PREVIEW_PADDING;
    mPreview.setLayoutData(gd_mImage);
    new Label(container, SWT.NONE);

    mHeading = new Label(container, SWT.NONE);
    mHeading.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    new Label(container, SWT.NONE);

    mDescription = new Label(container, SWT.WRAP);
    mDescription.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));

    Font font = JFaceResources.getFontRegistry().getBold(JFaceResources.BANNER_FONT);
    if (font != null) {
        mHeading.setFont(font);
    }

    updatePreview();
}

From source file:com.android.ide.eclipse.auidt.internal.wizards.templates.ActivityPage.java

License:Open Source License

@SuppressWarnings("unused") // SWT constructors have side effects and aren't unused
private void onEnter() {
    Composite container = (Composite) getControl();
    container.setLayout(new GridLayout(3, false));

    if (mAskCreate) {
        mCreateToggle = new Button(container, SWT.CHECK);
        mCreateToggle.setSelection(true);
        mCreateToggle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
        mCreateToggle.setText("Create Activity");
        mCreateToggle.addSelectionListener(this);
    }/*from   ww  w . j  ava 2 s. c o  m*/

    mList = new List(container, SWT.BORDER | SWT.V_SCROLL);
    mList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    TemplateManager manager = mValues.template.getManager();
    mTemplates = manager.getTemplates(CATEGORY_ACTIVITIES);
    if (!mOnlyActivities) {
        mTemplates.addAll(manager.getTemplates(CATEGORY_OTHER));
    }
    java.util.List<String> names = new ArrayList<String>(mTemplates.size());
    File current = mValues.activityValues.getTemplateLocation();
    int index = -1;
    for (int i = 0, n = mTemplates.size(); i < n; i++) {
        File template = mTemplates.get(i);
        names.add(template.getName());
        if (template.equals(current)) {
            index = i;
        }
    }
    String[] items = names.toArray(new String[names.size()]);
    mList.setItems(items);
    if (index == -1 && !mTemplates.isEmpty()) {
        mValues.activityValues.setTemplateLocation(mTemplates.get(0));
        index = 0;
    }
    if (index >= 0) {
        mList.setSelection(index);
        mList.addSelectionListener(this);
    }

    // Preview
    mPreview = new ImageControl(container, SWT.NONE, null);
    GridData gd_mImage = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
    gd_mImage.widthHint = PREVIEW_WIDTH + 2 * PREVIEW_PADDING;
    mPreview.setLayoutData(gd_mImage);
    new Label(container, SWT.NONE);

    mHeading = new Label(container, SWT.NONE);
    mHeading.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    new Label(container, SWT.NONE);

    mDescription = new Label(container, SWT.WRAP);
    mDescription.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));

    Font font = JFaceResources.getFontRegistry().getBold(JFaceResources.BANNER_FONT);
    if (font != null) {
        mHeading.setFont(font);
    }

    updatePreview();
}

From source file:com.apicloud.navigator.composite.ThemeUIComposite.java

License:Open Source License

protected void registerWizardFunction(final UZWizardComposite browserComposite) {
    browserComposite.registerFunction("closea", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            shell.setEnabled(true);//from w w w .j  a  v a  2  s.  c  om
            parent.close();
            if (!isHandler) {
                showUZWizard();
            }
            return null;
        }

    });

    browserComposite.registerFunction("initFont", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            defaultFont = JFaceResources.getFontRegistry().get("org.eclipse.jface.textfont");
            if ((defaultFont == null) || (defaultFont.getFontData() == null)
                    || (defaultFont.getFontData().length <= 0)) {
                return "";
            }
            FontData data = defaultFont.getFontData()[0];
            if (PlatformUtil.isWindows()) {
                Browser browser = (Browser) browserComposite.getBrowser();
                browser.execute(
                        "changeFont('" + data.getName() + "'," + Integer.valueOf(data.getHeight()) + ")");
            } else {
                Browser browser = (Browser) browserComposite.getBrowser();
                browser.execute(
                        "changeFont('" + data.getName() + "'," + Integer.valueOf(data.getHeight()) + ")");
            }
            return null;
        }
    });

    browserComposite.registerFunction("setTheme", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            String url;
            try {
                url = FileLocator.toFileURL(super.getClass().getResource("/content/step5.html")).toString();
                browserComposite.redirectTo(url);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

    });

    browserComposite.registerFunction("selectTheme", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            String themeName = (String) arguments[0];
            performDefaultTheme(themeName);
            return null;
        }
    });

    browserComposite.registerFunction("setFont", new UZWizardComposite.IScriptHandler() {
        public Object handle(Object[] arguments) {
            FontDialog fontDialog = new FontDialog(shell);
            fontDialog.setFontList(defaultFont.getFontData());
            FontData data = fontDialog.open();
            if (data == null)
                return null;
            Font newFont = new Font(defaultFont.getDevice(), fontDialog.getFontList());
            if (defaultFont.equals(newFont)) {
                return null;
            }
            FontData newData = newFont.getFontData()[0];
            defaultFont = newFont;
            setDefaultFont(newFont);
            if (PlatformUtil.isWindows()) {
                Browser browser = (Browser) browserComposite.getBrowser();
                browser.execute(
                        "changeFont('" + newData.getName() + "'," + Integer.valueOf(newData.getHeight()) + ")");
            } else {
                Browser browser = (Browser) browserComposite.getBrowser();
                browser.execute(
                        "changeFont('" + newData.getName() + "'," + Integer.valueOf(newData.getHeight()) + ")");
            }
            return null;
        }

    });

}