org.eclipse.swt.graphics.FontData Java Examples

The following examples show how to use org.eclipse.swt.graphics.FontData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SWTFactory.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new label widget
 * @param parent the parent composite to add this label widget to
 * @param text the text for the label
 * @param hspan the horizontal span to take up in the parent composite
 * @param fontstyle - SWT style
 * @param gdStyle - GridData style
 * @return the new label
 */
public static Label createLabel(Composite parent, String text, int hspan, int fontstyle, int gdStyle) {
    Label l = new Label(parent, SWT.NONE);
    if (fontstyle != SWT.NONE){
        FontData fd = parent.getFont().getFontData()[0];
        l.setFont(new Font(Display.getDefault(), fd.getName(), fd.getHeight(), fontstyle));
    } else {
        l.setFont(parent.getFont());
    }
    l.setText(text);
    GridData gd = new GridData(gdStyle);
    gd.horizontalSpan = hspan;
    gd.grabExcessHorizontalSpace = false;
    l.setLayoutData(gd);
    return l;
}
 
Example #2
Source File: SyntaxColoringLabel.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected int getTextExtend(Font font, String string) {
	if (string.isEmpty())
		return 0;
	if (zoom != 1.0) {
		FontData data = font.getFontData()[0];
		FontDescriptor newFontDescriptor = FontDescriptor.createFrom(font)
				.setHeight((int) (data.getHeight() * zoom));
		font = newFontDescriptor.createFont(Display.getDefault());
	}
	if (gc.getFont() != font)
		gc.setFont(font);
	int offset = gc.textExtent(string).x;
	if (zoom != 1.0) {
		font.dispose();
	}
	return (int) Math.ceil((offset / zoom));
}
 
Example #3
Source File: PreferenceInitializer.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Diese Funktion wird nach dem Erstellen des Display aufgerufen und dient zum Initialiseren
 * früh benötigter Einstellungen, die bereits ein Display benötigen
 * 
 */
public void initializeDisplayPreferences(Display display){
	UiDesk.getColorRegistry().put(UiDesk.COL_RED, new RGB(255, 0, 0));
	UiDesk.getColorRegistry().put(UiDesk.COL_GREEN, new RGB(0, 255, 0));
	UiDesk.getColorRegistry().put(UiDesk.COL_DARKGREEN, new RGB(0, 88, 0));
	UiDesk.getColorRegistry().put(UiDesk.COL_BLUE, new RGB(0, 0, 255));
	UiDesk.getColorRegistry().put(UiDesk.COL_SKYBLUE, new RGB(135, 206, 250));
	UiDesk.getColorRegistry().put(UiDesk.COL_LIGHTBLUE, new RGB(0, 191, 255));
	UiDesk.getColorRegistry().put(UiDesk.COL_BLACK, new RGB(0, 0, 0));
	UiDesk.getColorRegistry().put(UiDesk.COL_GREY, new RGB(0x60, 0x60, 0x60));
	UiDesk.getColorRegistry().put(UiDesk.COL_WHITE, new RGB(255, 255, 255));
	UiDesk.getColorRegistry().put(UiDesk.COL_DARKGREY, new RGB(50, 50, 50));
	UiDesk.getColorRegistry().put(UiDesk.COL_LIGHTGREY, new RGB(180, 180, 180));
	UiDesk.getColorRegistry().put(UiDesk.COL_GREY60, new RGB(153, 153, 153));
	UiDesk.getColorRegistry().put(UiDesk.COL_GREY20, new RGB(51, 51, 51));
	
	FontData[] small = new FontData[] {
		new FontData("Helvetica", 7, SWT.NORMAL)}; //$NON-NLS-1$
	CoreHub.userCfg
		.set(
			Preferences.USR_SMALLFONT + "_default", PreferenceConverter.getStoredRepresentation(small)); //$NON-NLS-1$
}
 
Example #4
Source File: XLIFFEditorImplWithNatTable.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 配置标签列的显示效果
 * @param configRegistry
 *            配置注册表
 */
private void addFlagLableToColumn(IConfigRegistry configRegistry) {
	// Edit by Leakey 实现状态图片的动态显示
	StatusPainter painter = new StatusPainter(bodyDataProvider);
	// CellPainterDecorator flagPainter = new CellPainterDecorator(new BackgroundPainter(), CellEdgeEnum.RIGHT,
	// painter);

	configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, painter, DisplayMode.NORMAL,
			FLAG_CELL_LABEL);

	// Set the color of the cell. This is picked up by the button painter to style the button
	Style style = new Style();
	FontData fd = GUIHelper.DEFAULT_FONT.getFontData()[0];
	fd.setStyle(SWT.BOLD);
	style.setAttributeValue(CellStyleAttributes.FONT, GUIHelper.getFont(fd));

	configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL,
			FLAG_CELL_LABEL);
	configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.SELECT,
			FLAG_CELL_LABEL);
}
 
Example #5
Source File: TableComboPropertyHandler.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private boolean applyCSSPropertyStyle(final Object element, final Control widget, final CSSValue value) throws Exception {
	if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
		final FontData fd = CSSEngineHelper.getFontData(widget);
		boolean modified = false;
		if ("italic".equals(value.getCssText()) || "oblique".equals(value.getCssText())) {
			modified = (fd.getStyle() & SWT.ITALIC) != SWT.ITALIC;
			if (modified) {
				fd.setStyle(fd.getStyle() | SWT.ITALIC);
			}
		} else {
			modified = (fd.getStyle() & SWT.ITALIC) == SWT.ITALIC;
			if (modified) {
				fd.setStyle(fd.getStyle() | ~SWT.ITALIC);
			}
		}
		if (modified) {
			applyFont(widget, fd);
		}

	}
	return true;
}
 
Example #6
Source File: ThemeUIComposite.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void setDefaultFont(Font newFont) {
	String[] fontIds = { "org.eclipse.jface.textfont",
			"org.eclipse.ui.workbench.texteditor.blockSelectionModeFont" };
	FontData[] newData = newFont.getFontData();
	for (String fontId : fontIds) {
		setFont(fontId, newData);
	}

	newData = newFont.getFontData();
	FontData[] smaller = new FontData[newData.length];
	int j = 0;
	for (FontData fd : newData) {
		int height = fd.getHeight();
		if (height >= 12) {
			fd.setHeight(height - 2);
		} else if (height >= 10) {
			fd.setHeight(height - 1);
		}
		smaller[(j++)] = fd;
	}
	setFont("com.aptana.explorer.font", smaller);
}
 
Example #7
Source File: FontPicker.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public FontPicker(final Composite parent, Font originalFont) {
    super(parent, SWT.NONE);
    if (originalFont == null) throw new IllegalArgumentException("null");
    
    update(originalFont.getFontData()[0]);
    
    addSelectionListener(
            new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                	FontDialog dialog = new FontDialog(new Shell(Display.getDefault(), SWT.SHELL_TRIM));
                    dialog.setFontList(fontData);
                    FontData selected = dialog.open();
                    if (selected != null) {                            
                        update(selected);
                        pack(true);
                    }
                }
            });
}
 
Example #8
Source File: JSEditor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the description with the specified text.
 * 
 * @param text
 *            the text to set.
 */
private void setDescriptionText( String text )
{
	Font font = descriptionText.getFont( );
	FontData[] fontData = font.getFontData( );
	String description;

	if ( text != null && text.length( ) > 0 )
	{
		for ( int i = 0; i < fontData.length; i++ )
		{
			fontData[i].setStyle( fontData[i].getStyle( ) & ~SWT.ITALIC );
		}
		description = text;
	}
	else
	{
		for ( int i = 0; i < fontData.length; i++ )
		{
			fontData[i].setStyle( fontData[i].getStyle( ) | SWT.ITALIC );
		}
		description = Messages.getString( "JSEditor.Text.NoDescription" ); //$NON-NLS-1$;
	}
	descriptionText.setFont( new Font( font.getDevice( ), fontData ) );
	descriptionText.setText( description );
}
 
Example #9
Source File: CopiedWorkbenchLabelProvider.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Font getFont(Object element) {
    IWorkbenchAdapter2 adapter = getAdapter2(element);
    if (adapter == null) {
        return null;
    }

    FontData descriptor = adapter.getFont(element);
    if (descriptor == null) {
        return null;
    }

    try {
        return resourceManager.createFont(FontDescriptor.createFrom(descriptor));
    } catch (Exception e) {
        Log.log(e);
        return null;
    }

}
 
Example #10
Source File: TitleRenderer.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private Font createFont ( final ResourceManager resourceManager )
{
    final Font defaultFont = resourceManager.getDevice ().getSystemFont ();

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

    final FontData fd[] = FontDescriptor.copy ( defaultFont.getFontData () );
    if ( fd == null )
    {
        return null;
    }

    for ( final FontData f : fd )
    {
        if ( this.fontSize > 0 )
        {
            f.setHeight ( this.fontSize );
        }
    }
    return resourceManager.createFont ( FontDescriptor.createFrom ( fd ) );
}
 
Example #11
Source File: ViewLattice.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param parent
 * @param controller
 */
public ViewLattice(final Composite parent, final Controller controller) {

    super(parent, controller);
            
    // Compute font
    FontData[] fd = parent.getFont().getFontData();
    fd[0].setHeight(8);
    this.font = new Font(parent.getDisplay(), fd[0]);

    // Build canvas
    this.canvas = new Canvas(getPrimaryComposite(), SWT.DOUBLE_BUFFERED);
    this.canvas.setLayoutData(SWTUtil.createFillGridData());
    this.canvas.addPaintListener(new PaintListener() {
        @Override
        public void paintControl(PaintEvent e) {
            screen = canvas.getSize();
            e.gc.setAdvanced(true);
            e.gc.setAntialias(SWT.ON);
            draw(e.gc);
        }
    });
    this.canvas.addDisposeListener(new DisposeListener(){
        public void widgetDisposed(DisposeEvent arg0) {
            clearLatticeAndDisposePaths(); // Free resources
        }
    });
    
    // Initialize
    this.initializeToolTipTimer();
    this.initializeListeners();
}
 
Example #12
Source File: PageNumberPrintTest.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void testEquals() {
	PageNumberPrint pageNumber1 = new PageNumberPrint(
			new PageNumberStub(0));
	PageNumberPrint pageNumber2 = new PageNumberPrint(
			new PageNumberStub(0));
	assertEquals(pageNumber1, pageNumber2);

	pageNumber1.setAlign(SWT.CENTER);
	assertFalse(pageNumber1.equals(pageNumber2));
	pageNumber2.setAlign(SWT.CENTER);
	assertEquals(pageNumber1, pageNumber2);

	pageNumber1.setFontData(new FontData("Arial", 12, SWT.BOLD));
	assertFalse(pageNumber1.equals(pageNumber2));
	pageNumber2.setFontData(new FontData("Arial", 12, SWT.BOLD));
	assertEquals(pageNumber1, pageNumber2);

	pageNumber1.setPageNumber(new PageNumberStub(1));
	assertFalse(pageNumber1.equals(pageNumber2));
	pageNumber2.setPageNumber(new PageNumberStub(1));
	assertEquals(pageNumber1, pageNumber2);

	pageNumber1.setPageNumberFormat(new PageNumberFormatStub());
	assertFalse(pageNumber1.equals(pageNumber2));
	pageNumber2.setPageNumberFormat(new PageNumberFormatStub());
	assertEquals(pageNumber1, pageNumber2);
}
 
Example #13
Source File: CsvSinkNameEditPart.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void refreshFont() {
	FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
	if (style != null) {
		FontData fontData = new FontData(style.getFontName(), style.getFontHeight(),
				(style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
		setFont(fontData);
	}
}
 
Example #14
Source File: SeparatorPanel.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void initComponents(String label) {
       GridLayout gridLayout = new GridLayout(2, false);
	setLayout(gridLayout);
	
	GridData layoutData = new GridData();
	layoutData.grabExcessHorizontalSpace = true;
	layoutData.horizontalAlignment = GridData.FILL;
	setLayoutData(layoutData);

	// Text label
	StyledText gridLinesLabel = new StyledText(this, SWT.NONE);
	gridLinesLabel.setEditable(false);
	Display display = Display.getDefault();
	FontData data = display .getSystemFont().getFontData()[0];
	Font font = new Font(display, data.getName(), data.getHeight(), SWT.BOLD);
	gridLinesLabel.setFont(font);
	gridLinesLabel.setBackground(Display.getCurrent().getSystemColor (SWT.COLOR_WIDGET_BACKGROUND));
	gridLinesLabel.setText(label);

	// Separator line
	Label separator = new Label (this, SWT.SEPARATOR | SWT.HORIZONTAL);
	GridData separatorData = new GridData();
	separatorData.grabExcessHorizontalSpace = true;
	separatorData.horizontalAlignment = GridData.FILL;
	separatorData.horizontalIndent = 5;
	separator.setLayoutData(separatorData);
}
 
Example #15
Source File: TreeNodeLabelProvider.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public TreeNodeLabelProvider ( final TreeViewer viewer, final IObservableMap... attributeMaps )
{
    super ( attributeMaps );
    this.viewer = viewer;

    this.defaultFont = viewer.getControl ().getFont ();

    final FontData[] fds = this.viewer.getControl ().getFont ().getFontData ();
    for ( final FontData fd : fds )
    {
        fd.setStyle ( SWT.ITALIC );
    }
    this.font = new Font ( this.viewer.getControl ().getDisplay (), fds );
}
 
Example #16
Source File: ServiceTaskLabel2EditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
protected void refreshFont() {
	FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
	if (style != null) {
		FontData fontData = new FontData(style.getFontName(), style.getFontHeight(),
				(style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
		setFont(fontData);
	}
}
 
Example #17
Source File: UiDesk.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static Font getFont(String cfgName){
	FontRegistry fr = JFaceResources.getFontRegistry();
	if (!fr.hasValueFor(cfgName)) {
		FontData[] fd =
			PreferenceConverter.getFontDataArray(new SettingsPreferenceStore(CoreHub.userCfg),
				cfgName);
		fr.put(cfgName, fd);
	}
	return fr.get(cfgName);
}
 
Example #18
Source File: CrossflowViewProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
public Node createTask_2010(EObject domainElement, View containerView, int index, boolean persisted,
		PreferencesHint preferencesHint) {
	Shape node = NotationFactory.eINSTANCE.createShape();
	node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
	node.setType(CrossflowVisualIDRegistry.getType(TaskEditPart.VISUAL_ID));
	ViewUtil.insertChildView(containerView, node, index, persisted);
	node.setElement(domainElement);
	stampShortcut(containerView, node);
	// initializeFromPreferences 
	final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();

	org.eclipse.swt.graphics.RGB lineRGB = PreferenceConverter.getColor(prefStore,
			IPreferenceConstants.PREF_LINE_COLOR);
	ViewUtil.setStructuralFeatureValue(node, NotationPackage.eINSTANCE.getLineStyle_LineColor(),
			FigureUtilities.RGBToInteger(lineRGB));
	FontStyle nodeFontStyle = (FontStyle) node.getStyle(NotationPackage.Literals.FONT_STYLE);
	if (nodeFontStyle != null) {
		FontData fontData = PreferenceConverter.getFontData(prefStore, IPreferenceConstants.PREF_DEFAULT_FONT);
		nodeFontStyle.setFontName(fontData.getName());
		nodeFontStyle.setFontHeight(fontData.getHeight());
		nodeFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
		nodeFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
		org.eclipse.swt.graphics.RGB fontRGB = PreferenceConverter.getColor(prefStore,
				IPreferenceConstants.PREF_FONT_COLOR);
		nodeFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
	}
	org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(prefStore,
			IPreferenceConstants.PREF_FILL_COLOR);
	ViewUtil.setStructuralFeatureValue(node, NotationPackage.eINSTANCE.getFillStyle_FillColor(),
			FigureUtilities.RGBToInteger(fillRGB));
	Node label5010 = createLabel(node, CrossflowVisualIDRegistry.getType(TaskNameEditPart.VISUAL_ID));
	return node;
}
 
Example #19
Source File: PTFontEditor.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.propertytable.editor.PTChooserEditor#openWindow(org.eclipse.nebula.widgets.opal.propertytable.PTWidget,
 *      org.eclipse.swt.widgets.Item, org.eclipse.nebula.widgets.opal.propertytable.PTProperty)
 */
@Override
protected void openWindow(final PTWidget widget, final Item item, final PTProperty property) {
	final FontDialog dialog = new FontDialog(widget.getWidget().getShell());
	final FontData result = dialog.open();
	if (result != null && result.getName() != null && !"".equals(result.getName().trim())) {
		property.setValue(result);
		if (item instanceof TableItem) {
			((TableItem) item).setText(1, getTextFor(property));
		} else {
			((TreeItem) item).setText(1, getTextFor(property));
		}
	}
}
 
Example #20
Source File: TypeNameEditPart.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected void refreshFont() {
	FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
	if (style != null) {
		FontData fontData = new FontData(style.getFontName(), style.getFontHeight(),
				(style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
		setFont(fontData);
	}
}
 
Example #21
Source File: ProcessViewProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
public Node createNonInterruptingBoundaryTimerEvent_3065(EObject domainElement, View containerView, int index,
		boolean persisted, PreferencesHint preferencesHint) {
	Shape node = NotationFactory.eINSTANCE.createShape();
	node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
	node.setType(ProcessVisualIDRegistry.getType(NonInterruptingBoundaryTimerEvent2EditPart.VISUAL_ID));
	ViewUtil.insertChildView(containerView, node, index, persisted);
	node.setElement(domainElement);
	// initializeFromPreferences 
	final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();

	org.eclipse.swt.graphics.RGB lineRGB = PreferenceConverter.getColor(prefStore,
			IPreferenceConstants.PREF_LINE_COLOR);
	ViewUtil.setStructuralFeatureValue(node, NotationPackage.eINSTANCE.getLineStyle_LineColor(),
			FigureUtilities.RGBToInteger(lineRGB));
	FontStyle nodeFontStyle = (FontStyle) node.getStyle(NotationPackage.Literals.FONT_STYLE);
	if (nodeFontStyle != null) {
		FontData fontData = PreferenceConverter.getFontData(prefStore, IPreferenceConstants.PREF_DEFAULT_FONT);
		nodeFontStyle.setFontName(fontData.getName());
		nodeFontStyle.setFontHeight(fontData.getHeight());
		nodeFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
		nodeFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
		org.eclipse.swt.graphics.RGB fontRGB = PreferenceConverter.getColor(prefStore,
				IPreferenceConstants.PREF_FONT_COLOR);
		nodeFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
	}
	org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(prefStore,
			IPreferenceConstants.PREF_FILL_COLOR);
	ViewUtil.setStructuralFeatureValue(node, NotationPackage.eINSTANCE.getFillStyle_FillColor(),
			FigureUtilities.RGBToInteger(fillRGB));
	Node label5095 = createLabel(node,
			ProcessVisualIDRegistry.getType(NonInterruptingBoundaryTimerEventName2EditPart.VISUAL_ID));
	label5095.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
	Location location5095 = (Location) label5095.getLayoutConstraint();
	location5095.setX(0);
	location5095.setY(5);
	return node;
}
 
Example #22
Source File: SWTGraphics2D.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the font in form of an awt font created
 * with the parameters of the font of the swt graphic
 * composite.
 * @see java.awt.Graphics#getFont()
 */
public Font getFont() {
    // retrieve the swt font description in an os indept way
    FontData[] fontData = this.gc.getFont().getFontData();
    // create a new awt font with the appropiate data
    return SWTUtils.toAwtFont(this.gc.getDevice(), fontData[0], true);
}
 
Example #23
Source File: PrimitiveQuestionnairePage.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
private Composite getPanel(final Composite parent) {
	final Composite titledPanel = new Composite(parent, SWT.NONE);
	final Font boldFont = new Font(titledPanel.getDisplay(), new FontData("Arial", 9, SWT.BOLD));
	titledPanel.setFont(boldFont);
	final GridLayout layout2 = new GridLayout();

	layout2.numColumns = 4;
	titledPanel.setLayout(layout2);

	return titledPanel;
}
 
Example #24
Source File: WorkbenchLabelProvider.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public Font getFont(Object element) {
	IWorkbenchAdapter2 adapter = getAdapter2(element);
	if (adapter == null) {
		return null;
	}

	FontData descriptor = adapter.getFont(element);
	if (descriptor == null) {
		return null;
	}

	return (Font) getResourceManager().get(FontDescriptor.createFrom(descriptor));
}
 
Example #25
Source File: ProcessViewProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
public Node createEndMessageEvent_3011(EObject domainElement, View containerView, int index, boolean persisted,
		PreferencesHint preferencesHint) {
	Shape node = NotationFactory.eINSTANCE.createShape();
	node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
	node.setType(ProcessVisualIDRegistry.getType(EndMessageEvent2EditPart.VISUAL_ID));
	ViewUtil.insertChildView(containerView, node, index, persisted);
	node.setElement(domainElement);
	// initializeFromPreferences 
	final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();

	org.eclipse.swt.graphics.RGB lineRGB = PreferenceConverter.getColor(prefStore,
			IPreferenceConstants.PREF_LINE_COLOR);
	ViewUtil.setStructuralFeatureValue(node, NotationPackage.eINSTANCE.getLineStyle_LineColor(),
			FigureUtilities.RGBToInteger(lineRGB));
	FontStyle nodeFontStyle = (FontStyle) node.getStyle(NotationPackage.Literals.FONT_STYLE);
	if (nodeFontStyle != null) {
		FontData fontData = PreferenceConverter.getFontData(prefStore, IPreferenceConstants.PREF_DEFAULT_FONT);
		nodeFontStyle.setFontName(fontData.getName());
		nodeFontStyle.setFontHeight(fontData.getHeight());
		nodeFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
		nodeFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
		org.eclipse.swt.graphics.RGB fontRGB = PreferenceConverter.getColor(prefStore,
				IPreferenceConstants.PREF_FONT_COLOR);
		nodeFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
	}
	org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(prefStore,
			IPreferenceConstants.PREF_FILL_COLOR);
	ViewUtil.setStructuralFeatureValue(node, NotationPackage.eINSTANCE.getFillStyle_FillColor(),
			FigureUtilities.RGBToInteger(fillRGB));
	Node label5028 = createLabel(node, ProcessVisualIDRegistry.getType(EndMessageEventLabel2EditPart.VISUAL_ID));
	label5028.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
	Location location5028 = (Location) label5028.getLayoutConstraint();
	location5028.setX(0);
	location5028.setY(5);
	return node;
}
 
Example #26
Source File: ProcessViewProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
public Node createPool_2007(EObject domainElement, View containerView, int index, boolean persisted,
		PreferencesHint preferencesHint) {
	Node node = NotationFactory.eINSTANCE.createNode();
	node.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
	node.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());
	node.getStyles().add(NotationFactory.eINSTANCE.createLineStyle());
	node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
	node.setType(ProcessVisualIDRegistry.getType(PoolEditPart.VISUAL_ID));
	ViewUtil.insertChildView(containerView, node, index, persisted);
	node.setElement(domainElement);
	stampShortcut(containerView, node);
	// initializeFromPreferences 
	final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();

	org.eclipse.swt.graphics.RGB lineRGB = PreferenceConverter.getColor(prefStore,
			IPreferenceConstants.PREF_LINE_COLOR);
	ViewUtil.setStructuralFeatureValue(node, NotationPackage.eINSTANCE.getLineStyle_LineColor(),
			FigureUtilities.RGBToInteger(lineRGB));
	FontStyle nodeFontStyle = (FontStyle) node.getStyle(NotationPackage.Literals.FONT_STYLE);
	if (nodeFontStyle != null) {
		FontData fontData = PreferenceConverter.getFontData(prefStore, IPreferenceConstants.PREF_DEFAULT_FONT);
		nodeFontStyle.setFontName(fontData.getName());
		nodeFontStyle.setFontHeight(fontData.getHeight());
		nodeFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
		nodeFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
		org.eclipse.swt.graphics.RGB fontRGB = PreferenceConverter.getColor(prefStore,
				IPreferenceConstants.PREF_FONT_COLOR);
		nodeFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
	}
	Node label5008 = createLabel(node, ProcessVisualIDRegistry.getType(PoolNameEditPart.VISUAL_ID));
	createCompartment(node, ProcessVisualIDRegistry.getType(PoolPoolCompartmentEditPart.VISUAL_ID), false, false,
			false, false);
	return node;
}
 
Example #27
Source File: SWTUtils.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Create an awt font by converting as much information
 * as possible from the provided swt <code>FontData</code>.
 * <p>Generally speaking, given a font size, an swt font will
 * display differently on the screen than the corresponding awt
 * one. Because the SWT toolkit use native graphical ressources whenever
 * it is possible, this fact is platform dependent. To address
 * this issue, it is possible to enforce the method to return
 * an awt font with the same height as the swt one.
 *
 * @param device The swt device being drawn on (display or gc device).
 * @param fontData The swt font to convert.
 * @param ensureSameSize A boolean used to enforce the same size
 * (in pixels) between the swt font and the newly created awt font.
 * @return An awt font converted from the provided swt font.
 */
public static java.awt.Font toAwtFont(Device device, FontData fontData,
        boolean ensureSameSize) {
    int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
            / 72.0);
    // hack to ensure the newly created awt fonts will be rendered with the
    // same height as the swt one
    if (ensureSameSize) {
        GC tmpGC = new GC(device);
        Font tmpFont = new Font(device, fontData);
        tmpGC.setFont(tmpFont);
        JPanel DUMMY_PANEL = new JPanel();
        java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
                fontData.getStyle(), height);
        if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                > tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    > tmpGC.textExtent(Az).x) {
                height--;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                < tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    < tmpGC.textExtent(Az).x) {
                height++;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        tmpFont.dispose();
        tmpGC.dispose();
    }
    return new java.awt.Font(fontData.getName(), fontData.getStyle(),
            height);
}
 
Example #28
Source File: CordovaPluginWizardResources.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private FontDescriptor createFontDescriptor(int style, float heightMultiplier) {
	Font baseFont = JFaceResources.getDialogFont();
	FontData[] fontData = baseFont.getFontData();
	FontData[] newFontData = new FontData[fontData.length];
	for (int i = 0; i < newFontData.length; i++) {
		newFontData[i] = new FontData(fontData[i].getName(), (int) (fontData[i].getHeight() * heightMultiplier), fontData[i].getStyle() | style);
	}
	return FontDescriptor.createFrom(newFontData);
}
 
Example #29
Source File: MechanicPopup.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private Font createBoldFont(Font font) {
  FontData[] fontDatas = font.getFontData();
  for (FontData fd: fontDatas) {
    fd.setStyle(SWT.BOLD);
  }
  return new Font(font.getDevice(), fontDatas);
}
 
Example #30
Source File: HTMLTypeScriptPrinter.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Returns the Javadoc hover style sheet with the current Javadoc font from
 * the preferences.
 * 
 * @return the updated style sheet
 * @since 3.4
 */
private static String getStyleSheet() {
	if (fgStyleSheet == null) {
		fgStyleSheet = loadStyleSheet("/css/TypeScriptHoverStyleSheet.css"); //$NON-NLS-1$
	}
	String css = fgStyleSheet;
	if (css != null) {
		FontData fontData = JFaceResources.getFontRegistry().getFontData(JFaceResources.DIALOG_FONT)[0];
		css = HTMLPrinter.convertTopLevelFont(css, fontData);
	}

	return css;
}