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

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

Introduction

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

Prototype

public static Font getDefaultFont() 

Source Link

Document

Returns JFace's standard font.

Usage

From source file:edu.tsinghua.lumaqq.widgets.rich.LineStyler.java

License:Open Source License

public Font getLineFont(int lineIndex) {
    LineStyle style = getLineStyle(lineIndex);
    String symbolic = style.getFontString();
    Font f = JFaceResources.getFont(symbolic);
    if (f == JFaceResources.getDefaultFont()) {
        FontData[] fd = style.createFontData();
        JFaceResources.getFontRegistry().put(symbolic, fd);
    }/*from   www. j a v  a2 s .  c o  m*/
    return JFaceResources.getFont(symbolic);
}

From source file:eu.aniketos.wp1.ststool.diagram.preferences.DiagramAppearancePreferencePage.java

License:Open Source License

/**
 * Set the default font for this preference store. Assumes that the method executed on the UI thread
 * /*  w w w . j a va 2  s.  c om*/
 * @param store
 *           IPreferenceStore
 */
private static void initDefaultFontProc(IPreferenceStore store) {

    FontData fontDataArray[] = JFaceResources.getDefaultFont().getFontData();
    FontData fontData = fontDataArray[0];
    fontData.setHeight(9);
    PreferenceConverter.setDefault(store, IPreferenceConstants.PREF_DEFAULT_FONT, fontData);
}

From source file:eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider.java

License:Open Source License

/**
 * Create the font to use for the figures.
 * // w w w.ja  v a  2  s.  c  o  m
 * @return the figure font or <code>null</code>
 */
protected Font createFigureFont() {
    FontData[] defFontData = JFaceResources.getDefaultFont().getFontData();
    return resources.createFont(FontDescriptor.createFrom(defFontData[0].getName(), 9, SWT.NORMAL));
}

From source file:fr.lip6.move.coloane.core.model.AttributeGraphicInfo.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w ww .j  av a  2  s  .  c o m
public final Dimension getSize() {
    String text = attribute.getValue();
    Font font = JFaceResources.getDefaultFont();
    return FigureUtilities.getTextExtents(text, font);
}

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 a v a  2  s  . 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.AbstractNodeFigure.java

License:Open Source License

/**
 * Solves an issue related to Figure instances with no font set: if this is the case, return system default font.
 * Note that in Shape implementation, if there is no "local" font asks the parent shape to provide one.
 * {@inheritDoc}/*from   w  ww. j  av a  2 s  .com*/
 */
@Override
public final Font getFont() {
    Font f = super.getFont();
    if (f != null) {
        return f;
    } else {
        return JFaceResources.getDefaultFont();
    }
}

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

License:Open Source License

/**
 * Create a tip with a unmodifiable text.
 * @param tip text of the tip/*  w w  w .  j a va  2 s.c o  m*/
 */
public TipFigure(ICoreTip tip) {
    setBorder(new MarginBorder(MARGIN));
    setCornerDimensions(new Dimension(10, 10));

    Label label = new Label(tip.getName() + " : " + tip.getValue()); //$NON-NLS-1$
    // TODO : sortir la police dans les prfrences
    label.setFont(JFaceResources.getDefaultFont());

    setSize(label.getTextBounds().getSize().expand(MARGIN * 2, MARGIN * 2));
    setBackgroundColor(ColorsPrefs.getColor("COLORTIP_BACKGROUND")); //$NON-NLS-1$
    setForegroundColor(ColorsPrefs.getColor("COLORTIP_FOREGROUND")); //$NON-NLS-1$
    setLineWidth(2);
    setLayoutManager(new StackLayout());
    add(label);
}

From source file:fr.lip6.move.coloane.extensions.exporttosvg.ExportToSVG.java

License:Open Source License

/**
 * Create attribute figures/*from   w  ww.jav a2  s.com*/
 * 
 * @param attributes
 *            list of attribute
 * @return list of figure for each attributes
 */
private Collection<IFigure> createAttributeFigures(Collection<IAttribute> attributes) {
    List<IFigure> list = new ArrayList<IFigure>();
    for (IAttribute attr : attributes) {
        if (attr.getAttributeFormalism().isDrawable()
                && !attr.getValue().equals(attr.getAttributeFormalism().getDefaultValue())) {
            final Point location = attr.getGraphicInfo().getLocation();
            Label label = new Label() {
                @Override
                public void paint(Graphics graphics) {
                    graphics.setFont(getFont());
                    graphics.setForegroundColor(getForegroundColor());
                    graphics.setBackgroundColor(getBackgroundColor());
                    graphics.fillText(getText(), location);
                }
            };
            label.setOpaque(true);
            label.setText(attr.getValue());
            label.setLocation(attr.getGraphicInfo().getLocation());
            label.setForegroundColor(attr.getGraphicInfo().getForeground());
            label.setBackgroundColor(attr.getGraphicInfo().getBackground());

            Font font = JFaceResources.getDefaultFont();
            if (attr.getAttributeFormalism().isBold()) {
                font = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
            } else if (attr.getAttributeFormalism().isItalic()) {
                font = JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
            }
            label.setFont(font);
            label.setBounds(label.getTextBounds());

            list.add(label);
        }
    }
    return list;
}

From source file:gov.nasa.ensemble.core.detail.emf.binding.UniqueMultiselectWidget.java

License:Open Source License

/** Method for creating the styled text box, button and listeners
 * @param parent/*from   w w w .j  a v a 2  s .  c  om*/
 *       composite to create widget in
 * @param toolkit
 *       FormToolkit 
 */
public void createControl(final Composite parent, FormToolkit toolkit) {

    parent.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = 0;
    layout.marginRight = 0;
    layout.horizontalSpacing = 0;

    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.FILL_HORIZONTAL);
    parent.setLayoutData(gridData);
    parent.setLayout(layout);

    valueStyledText = new StyledText(parent, SWT.BORDER | SWT.FILL | SWT.WRAP) {
        //set a small width but fill horizontally so it doesn't stretch the parent composite (SPF-7038)
        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Point size = super.computeSize(wHint, hHint, changed);
            size.x = 15;
            return size;
        }
    };
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, true).applyTo(valueStyledText);
    valueStyledText.setFont(JFaceResources.getDefaultFont());
    valueStyledText.setEditable(false);

    button = toolkit.createButton(parent, "", SWT.ARROW | SWT.DOWN);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).applyTo(button);

    if (!this.propertyDescriptor.canSetProperty(target)) {
        button.setEnabled(false);
    }

    //adding multiselect widget button listener
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (propertyDescriptor.canSetProperty(target)) {
                InPlaceCheckBoxTreeDialog multiselectDialog = new InPlaceCheckBoxTreeDialog(parent.getShell(),
                        button, getCheckedValues(), getGreyedValues(), getContentList()) {

                    @Override
                    public void dialogButtonPressOK() {
                        checkedValues = this.getSelectedValues();
                        greyedValues = this.getPartialValues();
                        Map<Object, TriState> newMap = createMapFromDialogSelection();
                        executeOperation(newMap);
                    }

                    @Override
                    public void dialogButtonPressDeselect() {
                        checkedValues = new ArrayList<String>();
                        greyedValues = new ArrayList<String>();
                        Map<Object, TriState> newMap = createMapFromDialogSelection();
                        executeOperation(newMap);
                    }

                    private void executeOperation(Map<Object, TriState> newMap) {
                        IUndoableOperation operation = new UniqueMultiSelectSetOperation(parameter, map,
                                newMap);
                        operation = addContributorOperations(operation, newMap);
                        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
                        try {
                            history.execute(operation, null, null);
                        } catch (org.eclipse.core.commands.ExecutionException e) {
                            LogUtil.error(e);
                        }
                    }

                    @Override
                    public boolean close() {
                        updateTreeDialogWithMap();
                        return super.close();
                    }
                };
                multiselectDialog.open();
            }
        }
    });

    toolkit.adapt(valueStyledText, false, false);

    //adding tooltips
    EMFDetailUtils.addDescriptionTooltip(propertyDescriptor, target, this.getControl());
    EMFDetailUtils.addDescriptionTooltip(propertyDescriptor, target, valueStyledText);
    EMFDetailUtils.addDescriptionTooltip(propertyDescriptor, target, button);

}

From source file:gov.redhawk.diagram.ui.tools.ComboDirectEditManager.java

License:Open Source License

/**
 * Given a label figure object, this will calculate the 
 * correct Font needed to display into screen coordinates, taking into 
 * account the current mapmode.  This will typically be used by direct
 * edit cell editors that need to display independent of the zoom or any
 * coordinate mapping that is taking place on the drawing surface.
 * //  w w  w. ja v a 2s. com
 * @param label the label to use for the font calculation
 * @return the <code>Font</code> that is scaled to the screen coordinates.
 * Note: the returned <code>Font</code> should not be disposed since it is
 * cached by a common resource manager.
 */
protected Font getScaledFont(final IFigure label) {
    final Font scaledFont = label.getFont();
    final FontData data = scaledFont.getFontData()[0];
    final Dimension fontSize = new Dimension(0, MapModeUtil.getMapMode(label).DPtoLP(data.getHeight()));
    label.translateToAbsolute(fontSize);

    if (Math.abs(data.getHeight() - fontSize.height) < 2) {
        fontSize.height = data.getHeight();
    }

    try {
        final FontDescriptor fontDescriptor = FontDescriptor.createFrom(data);
        this.cachedFontDescriptors.add(fontDescriptor);
        return getResourceManager().createFont(fontDescriptor);
    } catch (final DeviceResourceException e) {
        Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(),
                "getScaledFont", e); //$NON-NLS-1$
        Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING,
                "getScaledFont", e); //$NON-NLS-1$
    }
    return JFaceResources.getDefaultFont();
}