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:com.nokia.carbide.cpp.internal.news.reader.editor.NewsPageLabelProvider.java

License:Open Source License

public Font getFont(Object element, int columnIndex) {
    Font font = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
    return font;
}

From source file:com.nokia.carbide.cpp.internal.news.reader.ui.NewsControlContribution.java

License:Open Source License

@Override
protected Control createControl(Composite parent) {

    if (parent instanceof ToolBar) {
        toolbar = (ToolBar) parent;/*  w  w  w.  j a  v  a  2 s.c  o  m*/
        ToolItem[] items = toolbar.getItems();
        for (ToolItem item : items) {
            Object data = item.getData();
            if (data instanceof CommandContributionItem
                    && ((CommandContributionItem) data).getId().contains(NEWS_TRIM_COMMAND_ID)) {
                newsIconItem = item;
                break;
            }
        }
    } else {
        toolbar = null;
    }

    container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(2, 0).applyTo(container);

    // Create a label for the trim.
    label = new Label(container, SWT.BOTTOM);
    GridDataFactory.swtDefaults().grab(false, true).applyTo(label);
    String text = MessageFormat.format(Messages.NewsControlContribution_UnreadMessageFormat,
            CarbideNewsReaderPlugin.getFeedManager().getUnreadEntriesCount());
    label.setText(text);
    if (alert) {
        Font font = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
        label.setFont(font);
        alert = false;
    }

    if (newsIconItem != null) {
        // Yuck, toolbars and items have a wonky UI.  We need to do these events on the parent,
        // since the ToolItem itself is just an area inside the parent.  (#getControl() is only for separators ?!)

        // On icon: left click = open view, right click = menu
        if (toolbar != null) {
            if (toolbarListener != null)
                toolbar.removeMouseListener(toolbarListener);

            toolbarListener = new MouseAdapter() {
                /* (non-Javadoc)
                 * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
                 */
                @Override
                public void mouseDown(MouseEvent event) {
                    ToolItem item = toolbar.getItem(new Point(event.x, event.y));
                    if (item == newsIconItem) {
                        if (event.button == 1) {
                            NewsEditor.openEditor();
                        } else if (event.button == 3) {
                            Point screenLoc = toolbar.toDisplay(event.x, event.y);
                            handleNewsMenu(screenLoc);
                        }
                    }
                }
            };
            toolbar.addMouseListener(toolbarListener);
        }
    }

    // On label: left or right click = menu
    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            if (e.button == 1 || e.button == 3) {
                Point screenLoc = label.toDisplay(e.x, e.y);
                handleNewsMenu(screenLoc);
            }
        }
    });

    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, NewsUIHelpIDs.NEWSREADER_TRIM_COMMAND);
    return container;
}

From source file:com.nokia.carbide.internal.discovery.ui.editor.TaskBar.java

License:Open Source License

private void createActions(IActionBar actionBar) {
    listener = new ActionListener();
    linkToActionMap = new HashMap<Hyperlink, IAction>();
    for (IAction action : actionBar.getActions()) {
        Hyperlink link = new Hyperlink(this, SWT.NONE);
        link.setText(action.getText());/*ww  w  . j a v a 2 s.  c o m*/
        String toolTipText = action.getToolTipText();
        if (toolTipText != null)
            link.setToolTipText(toolTipText);
        link.setForeground(link.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE));
        link.setBackground(link.getDisplay().getSystemColor(SWT.COLOR_WHITE));
        String actionId = action.getId();
        String[] highlightedActionIds = actionBar.getHighlightedActionIds();
        if (actionId != null && highlightedActionIds != null) {
            for (String highlightedId : highlightedActionIds) {
                if (highlightedId.equals(actionId)) {
                    link.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
                    break;
                }
            }
        }
        linkToActionMap.put(link, action);
        link.addHyperlinkListener(listener);
    }
}

From source file:com.nokia.carbide.remoteconnections.internal.ui.mylyn.CommonFonts.java

License:Open Source License

private static void init() {
    BOLD = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
    ITALIC = JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
    BOLD_ITALIC = new Font(Display.getCurrent(),
            getModifiedFontData(ITALIC.getFontData(), SWT.BOLD | SWT.ITALIC));

    Font defaultFont = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
    FontData[] defaultData = defaultFont.getFontData();
    if (defaultData != null && defaultData.length == 1) {
        FontData data = new FontData(defaultData[0].getName(), defaultData[0].getHeight(),
                defaultData[0].getStyle());

        if ("win32".equals(SWT.getPlatform())) { //$NON-NLS-1$
            // NOTE: Windows only, for: data.data.lfStrikeOut = 1;
            try {
                Field dataField = data.getClass().getDeclaredField("data"); //$NON-NLS-1$
                Object dataObject = dataField.get(data);
                Class<?> clazz = dataObject.getClass().getSuperclass();
                Field strikeOutFiled = clazz.getDeclaredField("lfStrikeOut"); //$NON-NLS-1$
                strikeOutFiled.set(dataObject, (byte) 1);
                CommonFonts.STRIKETHROUGH = new Font(Display.getCurrent(), data);
            } catch (Throwable t) {
                // ignore
            }/*from   w  w  w .  ja v a2s. c  o  m*/
        }
    }
    if (CommonFonts.STRIKETHROUGH == null) {
        CommonFonts.HAS_STRIKETHROUGH = false;
        CommonFonts.STRIKETHROUGH = defaultFont;
    } else {
        CommonFonts.HAS_STRIKETHROUGH = true;
    }
}

From source file:com.nokia.carbide.remoteconnections.view.ConnectionsView.java

License:Open Source License

public void createPartControl(Composite parent) {
    viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);

    TreeViewerColumn nameColumn = new TreeViewerColumn(viewer, SWT.LEFT);
    nameColumn.setLabelProvider(new TreeColumnViewerLabelProvider(new NameLabelProvider()));
    nameColumn.getColumn().setText(Messages.getString("ConnectionsView.NameColumnHeader")); //$NON-NLS-1$
    nameColumn.setEditingSupport(new NameEditingSupport(nameColumn.getViewer()));
    ColumnViewerEditorActivationStrategy activationStrategy = new ColumnViewerEditorActivationStrategy(
            nameColumn.getViewer()) {//w  ww .ja v  a  2s. c om
        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    TreeViewerEditor.create(viewer, activationStrategy, ColumnViewerEditor.DEFAULT);

    boldViewerFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);

    TreeViewerColumn typeColumn = new TreeViewerColumn(viewer, SWT.LEFT);
    typeColumn.setLabelProvider(new TypeLabelProvider());
    typeColumn.getColumn().setText(Messages.getString("ConnectionsView.TypeColumnHeader")); //$NON-NLS-1$

    TreeViewerColumn statusColumn = new TreeViewerColumn(viewer, SWT.LEFT);
    statusColumn.setLabelProvider(new StatusLabelProvider());
    statusColumn.getColumn().setText(Messages.getString("ConnectionsView.StatusColumnHeader")); //$NON-NLS-1$

    TreeViewerColumn descriptionColumn = new TreeViewerColumn(viewer, SWT.LEFT);
    descriptionColumn.setLabelProvider(new DescriptionLabelProvider(this, descriptionColumn));
    descriptionColumn.getColumn().setText(Messages.getString("ConnectionsView.DescriptionColumnHeader")); //$NON-NLS-1$

    viewer.setContentProvider(new TreeNodeContentProvider());
    viewer.setInput(loadConnections());
    viewer.expandAll();
    viewer.getTree().setHeaderVisible(true);
    viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
    viewer.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return getNodeDisplayName(e1).compareToIgnoreCase(getNodeDisplayName(e2));
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            enableConnectionSelectedActions(false);
            enableServiceSelectedActions(false);
            ISelection selection = event.getSelection();
            if (!selection.isEmpty()) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                TreeNode treeNode = (TreeNode) structuredSelection.getFirstElement();
                Object value = treeNode.getValue();
                if (value instanceof IConnection) {
                    enableConnectionSelectedActions(true);
                } else if (value instanceof IConnectedService) {
                    enableServiceSelectedActions(true);
                }
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (!selection.isEmpty()) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                TreeNode treeNode = (TreeNode) structuredSelection.getFirstElement();
                Object value = treeNode.getValue();
                if (value instanceof IConnection) {
                    SettingsWizard wizard = new SettingsWizard((IConnection) value);
                    wizard.open(getViewSite().getShell());
                } else if (value instanceof IConnectedService) {
                    if (RemoteConnectionsActivator.getDefault().getShouldTestServices()) {
                        IConnectedService connectedService = (IConnectedService) value;
                        connectedService.setEnabled(true);
                        connectedService.testStatus();
                        ((EnableConnectedServiceAction) getAction(ENABLE_SERVICE_ACTION)).updateLabel();
                    }
                }
            }
        }
    });

    packColumns();

    makeActions();
    hookContextMenu();
    contributeToActionBars();
    hookAccelerators();

    connectionStoreChangedListener = new IConnectionsManagerListener() {
        public void connectionStoreChanged() {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    viewer.setInput(loadConnections());
                    viewer.expandAll();
                    packColumns();
                    if (viewer.getSelection().isEmpty() && viewer.getTree().getItemCount() > 0) {
                        TreeItem item = viewer.getTree().getItem(0);
                        if (item != null) {
                            viewer.getTree().select(item);
                        }
                    }
                    viewer.setSelection(viewer.getSelection()); // force selection changed
                }
            });
        }

        public void displayChanged() {
            refreshViewer();
        }
    };
    Registry.instance().addConnectionStoreChangedListener(connectionStoreChangedListener);

    connectionListener = new IConnectionListener() {

        public void currentConnectionSet(IConnection connection) {
            refreshViewer();
        }

        public void connectionRemoved(IConnection connection) {
            // presumably the viewer itself handles this...
        }

        public void connectionAdded(IConnection connection) {
            // presumably the viewer itself handles this...
        }
    };
    Registry.instance().addConnectionListener(connectionListener);

    RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$
}

From source file:com.nokia.cdt.internal.debug.launch.newwizard.DebugRunProcessDialog.java

License:Open Source License

private void createProcessSelector(Composite composite) {
    Label label;/*from  ww w . ja v  a  2s .c  om*/

    label = new Label(composite, SWT.WRAP);
    label.setText(
            MessageFormat.format(Messages.getString("DebugRunProcessDialog.ModeLabel"), data.getModeLabel())); //$NON-NLS-1$
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));

    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);

    Composite radioGroup = new Composite(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(radioGroup);
    GridLayoutFactory.fillDefaults().extendedMargins(INDENT, 0, 0, 0).numColumns(2).applyTo(radioGroup);

    createProjectExecutableRadioButton(radioGroup);
    createRemoteExecutableRadioButton(radioGroup);

    label = new Label(radioGroup, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(label);

    createAttachToProcessRadioButton(radioGroup);

    String msg;
    if (data.isDebug())
        msg = Messages.getString("DebugRunProcessDialog.DebugConfigureMsg"); //$NON-NLS-1$
    else
        msg = Messages.getString("DebugRunProcessDialog.RunConfigureMsg"); //$NON-NLS-1$
    setMessage(msg);

    switch (debugRunProcessWizardData.getExeSelection()) {
    case USE_PROJECT_EXECUTABLE:
        projectExecutableRadioButton.setSelection(true);
        break;
    case USE_REMOTE_EXECUTABLE:
        remoteExecutableRadioButton.setSelection(true);
        break;
    case ATTACH_TO_PROCESS:
        attachToProcessRadioButton.setSelection(true);
        break;
    }
}

From source file:com.nokia.cdt.internal.debug.launch.newwizard.DebugRunProcessDialog.java

License:Open Source License

private void createPackageConfiguration(Composite composite) {
    Label label;// w w  w  .  j a  v a  2s  .  c  o  m

    label = new Label(composite, SWT.WRAP);
    label.setText(
            MessageFormat.format(Messages.getString("DebugRunProcessDialog.DeployLabel"), data.getModeLabel())); //$NON-NLS-1$
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));

    GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);

    packageInfoLabel = new Label(composite, SWT.WRAP);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(packageInfoLabel);
    composite.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            packageInfoLabel.pack();
        }
    });

    installPackageCheckbox = new Button(composite, SWT.CHECK);
    GridDataFactory.fillDefaults().applyTo(installPackageCheckbox);

    installPackageCheckbox.setText(Messages.getString("DebugRunProcessDialog.InstallBeforeLaunchLabel")); //$NON-NLS-1$
    installPackageCheckbox.setToolTipText(Messages.getString("DebugRunProcessDialog.SISCheckboxTooltip")); //$NON-NLS-1$

    installPackageUI = new Composite(composite, SWT.NONE);
    GridDataFactory.fillDefaults().indent(INDENT, 0).applyTo(installPackageUI);

    createSISContents(installPackageUI);

    installPackageCheckbox.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            debugRunProcessWizardData.setInstallPackage(installPackageCheckbox.getSelection());
            updatePackageUI();
        }
    });

    if (debugRunProcessWizardData.isInstallPackage()) {
        installPackageCheckbox.setSelection(true);
        updatePackageUI();
    }

    updateSisFile();
    updatePackageUI();
}

From source file:com.opcoach.e34.tools.views.PluginDataProvider.java

License:Open Source License

private void initFonts() {
    FontData[] fontData = Display.getCurrent().getSystemFont().getFontData();
    String fontName = fontData[0].getName();
    FontRegistry registry = JFaceResources.getFontRegistry();
    boldFont = registry.getBold(fontName);
}

From source file:com.patrikdufresne.fontawesome.FontAwesome.java

License:Open Source License

/**
 * Return a FontAwesome font for SWT./*www . j  a  v  a  2  s.co m*/
 * 
 * @return the font or null.
 */
public static Font getFont() {
    if (JFaceResources.getFontRegistry().hasValueFor(FONTAWESOME)) {
        return JFaceResources.getFontRegistry().get(FONTAWESOME);
    }
    if (!loadFont()) {
        return null;
    }
    FontData[] data = new FontData[] { new FontData("fontawesome", 14, SWT.NORMAL) };
    JFaceResources.getFontRegistry().put(FONTAWESOME, data);
    return JFaceResources.getFontRegistry().get(FONTAWESOME);
}

From source file:com.patrikdufresne.fontawesome.FontAwesome.java

License:Open Source License

/**
 * Return a FontAwesome font for SWT.//from ww w. j  a  va  2  s. co m
 * 
 * @param size
 * @return
 */
public static Font getFont(int size) {
    String name = FONTAWESOME + size;
    if (!JFaceResources.getFontRegistry().hasValueFor(FONTAWESOME)) {
        // GetFont() may return null, so handle this case.
        Font font = getFont();
        if (font == null) {
            return null;
        }
        FontData[] data = font.getFontData();
        for (FontData d : data) {
            d.setHeight(size);
        }
        JFaceResources.getFontRegistry().put(name, data);
    }
    return JFaceResources.getFontRegistry().get(name);
}