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:ext.org.eclipse.jdt.internal.ui.infoviews.JavadocView.java

License:Open Source License

/**
 * Registers a listener for the Java editor font.
 *
 * @since 3.3//www. j  ava2 s.  c  o  m
 */
private void listenForFontChanges() {
    fFontListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (PreferenceConstants.APPEARANCE_JAVADOC_FONT.equals(event.getProperty())) {
                fgStyleSheetLoaded = false;
                // trigger reloading, but make sure other listeners have already run, so that
                // the style sheet gets reloaded only once.
                final Display display = getSite().getPage().getWorkbenchWindow().getWorkbench().getDisplay();
                if (!display.isDisposed()) {
                    display.asyncExec(new Runnable() {
                        public void run() {
                            if (!display.isDisposed()) {
                                initStyleSheet();
                                refresh();
                            }
                        }
                    });
                }
            }
        }
    };
    JFaceResources.getFontRegistry().addListener(fFontListener);
}

From source file:ext.org.eclipse.jdt.internal.ui.infoviews.JavadocView.java

License:Open Source License

private static String loadStyleSheet() {
    Bundle bundle = Platform.getBundle(JavaPlugin.getPluginId());
    URL styleSheetURL = bundle.getEntry("/JavadocViewStyleSheet.css"); //$NON-NLS-1$
    if (styleSheetURL == null)
        return null;

    BufferedReader reader = null;
    try {//from   w  w w  .  j a  va2 s.com
        reader = new BufferedReader(new InputStreamReader(styleSheetURL.openStream()));
        StringBuffer buffer = new StringBuffer(1500);
        String line = reader.readLine();
        while (line != null) {
            buffer.append(line);
            buffer.append('\n');
            line = reader.readLine();
        }

        FontData fontData = JFaceResources.getFontRegistry()
                .getFontData(PreferenceConstants.APPEARANCE_JAVADOC_FONT)[0];
        return HTMLPrinter.convertTopLevelFont(buffer.toString(), fontData);
    } catch (IOException ex) {
        JavaPlugin.log(ex);
        return null;
    } finally {
        try {
            if (reader != null)
                reader.close();
        } catch (IOException e) {
        }
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.infoviews.JavadocView.java

License:Open Source License

@Override
protected void internalDispose() {
    fText = null;/*from  w  w  w  .  j a v a 2  s .  c om*/
    fBrowser = null;
    if (fFontListener != null) {
        JFaceResources.getFontRegistry().removeListener(fFontListener);
        fFontListener = null;
    }

    if (fOpenBrowserAction != null) {
        fInputSelectionProvider.removeSelectionChangedListener(fOpenBrowserAction);
        fOpenBrowserAction = null;
    }
}

From source file:ext.org.eclipse.jdt.internal.ui.infoviews.SourceView.java

License:Open Source License

@Override
protected void internalCreatePartControl(Composite parent) {
    IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
    fViewer = new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL, store);
    fViewerConfiguration = new SimpleJavaSourceViewerConfiguration(
            JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, null,
            IJavaPartitions.JAVA_PARTITIONING, false);
    fViewer.configure(fViewerConfiguration);
    fViewer.setEditable(false);/*from w  w  w .j  av a2 s .co  m*/

    setViewerFont();
    JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);

    store.addPropertyChangeListener(fPropertyChangeListener);

    getViewSite().setSelectionProvider(fViewer);
}

From source file:ext.org.eclipse.jdt.internal.ui.infoviews.SourceView.java

License:Open Source License

@Override
protected void internalDispose() {
    fViewer = null;//  ww w. jav a2 s  . co m
    fViewerConfiguration = null;
    JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
    JavaPlugin.getDefault().getCombinedPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
}

From source file:ext.org.eclipse.jdt.internal.ui.preferences.JavaSourcePreviewerUpdater.java

License:Open Source License

/**
 * Creates a Java source preview updater for the given viewer, configuration and preference store.
 *
 * @param viewer the viewer/*from w w w . j  a v a 2  s  .  c  o  m*/
 * @param configuration the configuration
 * @param preferenceStore the preference store
 */
public JavaSourcePreviewerUpdater(final SourceViewer viewer, final JavaSourceViewerConfiguration configuration,
        final IPreferenceStore preferenceStore) {
    Assert.isNotNull(viewer);
    Assert.isNotNull(configuration);
    Assert.isNotNull(preferenceStore);
    final IPropertyChangeListener fontChangeListener = new IPropertyChangeListener() {
        /*
         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
         */
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(PreferenceConstants.EDITOR_TEXT_FONT)) {
                Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
                viewer.getTextWidget().setFont(font);
            }
        }
    };
    final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
        /*
         * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
         */
        public void propertyChange(PropertyChangeEvent event) {
            if (configuration.affectsTextPresentation(event)) {
                configuration.handlePropertyChangeEvent(event);
                viewer.invalidateTextPresentation();
            }
        }
    };
    viewer.getTextWidget().addDisposeListener(new DisposeListener() {
        /*
         * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
         */
        public void widgetDisposed(DisposeEvent e) {
            preferenceStore.removePropertyChangeListener(propertyChangeListener);
            JFaceResources.getFontRegistry().removeListener(fontChangeListener);
        }
    });
    JFaceResources.getFontRegistry().addListener(fontChangeListener);
    preferenceStore.addPropertyChangeListener(propertyChangeListener);
}

From source file:ext.org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.java

License:Open Source License

/**
 * Returns the style information for displaying HTML (Javadoc) content.
 *
 * @return the CSS styles//from w  ww.  ja v a 2  s.  c o  m
 * @since 3.3
 */
protected String getCSSStyles() {
    if (fgCSSStyles == null) {
        Bundle bundle = Platform.getBundle(JavaPlugin.getPluginId());
        URL url = bundle.getEntry("/JavadocHoverStyleSheet.css"); //$NON-NLS-1$
        if (url != null) {
            BufferedReader reader = null;
            try {
                url = FileLocator.toFileURL(url);
                reader = new BufferedReader(new InputStreamReader(url.openStream()));
                StringBuffer buffer = new StringBuffer(200);
                String line = reader.readLine();
                while (line != null) {
                    buffer.append(line);
                    buffer.append('\n');
                    line = reader.readLine();
                }
                fgCSSStyles = buffer.toString();
            } catch (IOException ex) {
                JavaPlugin.log(ex);
            } finally {
                try {
                    if (reader != null)
                        reader.close();
                } catch (IOException e) {
                }
            }

        }
    }
    String css = fgCSSStyles;
    if (css != null) {
        FontData fontData = JFaceResources.getFontRegistry()
                .getFontData(PreferenceConstants.APPEARANCE_JAVADOC_FONT)[0];
        css = HTMLPrinter.convertTopLevelFont(css, fontData);
    }
    return css;
}

From source file:fr.lip6.move.coloane.core.ui.editpart.AttributeEditPart.java

License:Open Source License

/**
 * Refresh view side according model information.
 *//*from  www.j  ava2s .co  m*/
@Override
protected final void refreshVisuals() {
    IAttribute attribut = (IAttribute) getModel();
    Label attributeFigure = (Label) getFigure();

    // Update graphical representation
    getFigure().setForegroundColor(attribut.getGraphicInfo().getForeground());
    getFigure().setBackgroundColor(attribut.getGraphicInfo().getBackground());

    // Select state (attribute only or parent ?)
    // TODO: Should be set in a property page
    if (this.select || this.elementSelect) {
        getFigure().setForegroundColor(ColorConstants.blue);
    }
    // Highlight state (mouseover event)
    // TODO: Should be set in a property page
    if (this.highlight) {
        getFigure().setBackgroundColor(ColorConstants.lightGray);
    }
    // Special state (coming from problem view)
    if (special) {
        getFigure().setForegroundColor(ColorConstants.red);
    }

    // Font update
    if (this.font == null || this.font.isDisposed()) {
        this.font = JFaceResources.getDefaultFont();
        if (attribut.getAttributeFormalism().isBold()) {
            this.font = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
        }
        if (attribut.getAttributeFormalism().isItalic()) {
            this.font = JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
        }
        attributeFigure.setFont(this.font);
    }

    // The label is filled with the attribute value !
    attributeFigure.setText(attribut.getValue());

    // Graphical space (i.e. bounds) for the attribute is set here.
    Rectangle bounds = new Rectangle(attribut.getGraphicInfo().getLocation(), new Dimension(
            attributeFigure.getTextBounds().width + EXTRA_SPACE, attributeFigure.getTextBounds().height));
    if (getParent() != null) {
        ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), bounds);
    }
}

From source file:fr.lip6.move.coloane.core.ui.figures.nodes.CircularDelegate.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w  w w. j a v  a 2 s . c o m*/
 */
@Override
protected final void outlineShape(final Graphics graphics) {
    Rectangle r = getBounds();

    boolean isPublic = getModel().getAttribute("visibility").getValue().equals("public");

    int lineWidth = getLineWidth();
    int x = r.x + lineWidth / 2;
    int y = r.y + lineWidth / 2;
    int w = r.width - Math.max(1, lineWidth);
    int h = r.height - Math.max(1, lineWidth);
    graphics.drawRectangle(x, y, w, h);

    // double the line for public transition : gives a "bold" effect.
    if (isPublic) {
        int ix = x + 2;
        int iy = y + 2;
        int iw = Math.max(1, w - 4);
        int ih = Math.max(1, h - 4);
        graphics.drawRectangle(ix, iy, iw, ih);
    }

    String type = "CIRC";
    graphics.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    graphics.drawText(type, getBounds().getTopLeft().translate(5, 3));

}

From source file:fr.lip6.move.coloane.core.ui.figures.nodes.InstanceNode.java

License:Open Source License

private void setTitle() {
    FrameBorder tb = new FrameBorder(instanceName);
    tb.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    setBorder(tb);
}