List of usage examples for org.eclipse.jface.resource FontDescriptor createFrom
public static FontDescriptor createFrom(String name, int height, int style)
From source file:eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider.java
License:Open Source License
/** * Create the font to use for the figures. * //from w w w. ja v a2s . co 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:net.karlmartens.ui.widget.Calendar.java
License:Apache License
public Calendar(Composite parent, int style, Locale locale) { super(parent, style); final DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale); _cal = java.util.Calendar.getInstance(locale); _titlePrinter = new DateTimeFormatterBuilder()// .appendMonthOfYearText()// .appendLiteral(' ')// .appendYear(4, 4)// .toFormatter();/*from w w w . j ava 2 s . c om*/ _resourceManger = new LocalResourceManager(JFaceResources.getResources(getDisplay())); _date = new YearMonthDay(_cal); _month = _date.toYearMonth(); _minimum = _month.addYears(-100); _maximum = _month.addYears(100); final String[] weekdays = createCalendarWeekdays(_cal, symbols); _weekdayCount = weekdays.length; final Display display = getDisplay(); _alternateBackgroundColor = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); _selectionColor = display.getSystemColor(SWT.COLOR_LIST_SELECTION); final GridLayout layout = new GridLayout(_weekdayCount, false); layout.horizontalSpacing = 0; layout.marginHeight = 1; layout.marginWidth = 1; layout.verticalSpacing = 0; super.setLayout(layout); super.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); final Font titleFont = _resourceManger.createFont(FontDescriptor.createFrom("Arial", 12, SWT.BOLD)); _title = createBlock(); _title.setLayoutData(createLayoutData().span(_weekdayCount, 1).create()); _title.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); _title.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); _title.setFont(titleFont); final Font calendarFont = _resourceManger.createFont(FontDescriptor.createFrom("Arial", 10, SWT.NONE)); _blocks = new Block[_weekdayCount * ROW_COUNT]; for (int i = 0; i < _blocks.length; i++) { if (i == _weekdayCount) createSeparator(); final Block block = _blocks[i] = createBlock(); block.setLayoutData(createLayoutData().create()); block.setFont(calendarFont); if (i < _weekdayCount) { block.setText(weekdays[i]); continue; } } _requiresRefresh = true; new ListenerImpl(); final PassthoughEventListener pListener = new PassthoughEventListener(this); pListener.addSource(_title); for (int i = 0; i < _blocks.length; i++) pListener.addSource(_blocks[i]); }
From source file:net.yatomiya.e4.ui.util.UIResourceManager.java
License:Open Source License
public Font getFont(String name, int height, int style) { return resMgr.createFont(FontDescriptor.createFrom(name, height, style)); }
From source file:org.eclipse.ease.ui.view.ScriptShell.java
License:Open Source License
@Override public final void createPartControl(final Composite parent) { // setup resource manager mResourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); // setup layout parent.setLayout(new GridLayout()); sashForm = new SashForm(parent, SWT.NONE); sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); mOutputText = new StyledText(sashForm, SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER); // set monospaced font final Object os = Platform.getOS(); if ("win32".equals(os)) mOutputText/* ww w . j a v a 2 s. c o m*/ .setFont(mResourceManager.createFont(FontDescriptor.createFrom("Courier New", 10, SWT.NONE))); else if ("linux".equals(os)) mOutputText.setFont(mResourceManager.createFont(FontDescriptor.createFrom("Monospace", 10, SWT.NONE))); mOutputText.setEditable(false); mOutputText.addMouseListener(new MouseListener() { @Override public void mouseUp(final MouseEvent e) { } @Override public void mouseDown(final MouseEvent e) { } @Override public void mouseDoubleClick(final MouseEvent e) { // copy line under cursor in input box String selected = mOutputText.getLine(mOutputText.getLineIndex(e.y)); if (!selected.isEmpty()) { mInputCombo.setText(selected); mInputCombo.setFocus(); mInputCombo.setSelection(new Point(0, selected.length())); } } }); fScriptComposite = new ScriptComposite(this, getSite(), sashForm, SWT.NONE); fScriptComposite.setEngine(fScriptEngine.getDescription().getID()); sashForm.setWeights(mSashWeights); mInputCombo = new Combo(parent, SWT.NONE); mInputCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(final SelectionEvent e) { final String input = mInputCombo.getText(); mInputCombo.setText(""); addToHistory(input); fScriptEngine.executeAsync(input); } }); mInputCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); // restore command history if (mInitMemento != null) { for (final IMemento node : mInitMemento.getChildren(XML_HISTORY_NODE)) { if (node.getTextData() != null) mInputCombo.add(node.getTextData()); } } // clear reference as we are done with initialization mInitMemento = null; // add DND support ShellDropTarget.addDropSupport(mOutputText, this); // set view title setPartName(fScriptEngine.getName() + " " + super.getTitle()); // read default preferences Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID) .node(IPreferenceConstants.NODE_SHELL); fHistoryLength = prefs.getInt(IPreferenceConstants.SHELL_HISTORY_LENGTH, IPreferenceConstants.DEFAULT_SHELL_HISTORY_LENGTH); fAutoFocus = prefs.getBoolean(IPreferenceConstants.SHELL_AUTOFOCUS, IPreferenceConstants.DEFAULT_SHELL_AUTOFOCUS); fKeepCommand = prefs.getBoolean(IPreferenceConstants.SHELL_KEEP_COMMAND, IPreferenceConstants.DEFAULT_SHELL_KEEP_COMMAND); if (fAutoFocus) { if (fAutoFocusListener == null) fAutoFocusListener = new AutoFocus(); mOutputText.addKeyListener(fAutoFocusListener); } // run startup commands, do this for all supported script types runStartupCommands(); }
From source file:org.eclipse.graphiti.ui.tests.ResourceManagerTest.java
License:Open Source License
@Test public void testFontCreation() throws Exception { Font font = diagramBehavior.getResourceManager() .createFont(FontDescriptor.createFrom("Arial", 10, SWT.NORMAL)); assertNotNull(font);/*w w w . j a v a2 s . c o m*/ }
From source file:org.eclipse.graphiti.ui.tests.ResourceManagerTest.java
License:Open Source License
@Test public void testFontReuse() throws Exception { Font f1 = diagramBehavior.getResourceManager() .createFont(FontDescriptor.createFrom("Arial", 10, SWT.NORMAL)); Font f2 = diagramBehavior.getResourceManager() .createFont(FontDescriptor.createFrom("Arial", 10, SWT.NORMAL)); assertSame(f1, f2);/*www. ja v a2s. c om*/ }
From source file:org.eclipse.graphiti.ui.tests.ResourceManagerTest.java
License:Open Source License
@Test public void testDisposal() throws Exception { FontDescriptor fontDescr = FontDescriptor.createFrom("Arial", 10, SWT.NORMAL); Font f1 = diagramBehavior.getResourceManager().createFont(fontDescr); RGB colorDescr = new RGB(100, 100, 100); Color c1 = diagramBehavior.getResourceManager().createColor(colorDescr); diagramBehavior.disposeAfterGefDispose(); Font f2 = diagramBehavior.getResourceManager().createFont(fontDescr); Color c2 = diagramBehavior.getResourceManager().createColor(colorDescr); assertNotSame(f1, f2);/* w w w . j a v a 2 s . com*/ assertNotSame(c1, c2); }
From source file:org.eclipse.incquery.tooling.localsearch.ui.debugger.provider.OperationListLabelProvider.java
License:Open Source License
@Override public void update(final ViewerCell cell) { localResourceManager = new LocalResourceManager(JFaceResources.getResources(Display.getCurrent())); final SearchOperationViewerNode node = (SearchOperationViewerNode) cell.getElement(); StyledString text = new StyledString(); text.append(node.getLabelText());/*from www. ja v a 2 s. c o m*/ switch (node.getOperationStatus()) { case EXECUTED: cell.setImage(appliedOperationImage); text.setStyle(0, text.length(), new Styler() { public void applyStyles(TextStyle textStyle) { textStyle.font = localResourceManager .createFont(FontDescriptor.createFrom("Arial", 10, SWT.BOLD)); doColoring(node, textStyle); } }); break; case CURRENT: cell.setImage(currentOperationImage); text.setStyle(0, text.length(), new Styler() { public void applyStyles(TextStyle textStyle) { LocalResourceManager localResMan = new LocalResourceManager( JFaceResources.getResources(Display.getCurrent())); textStyle.font = localResMan .createFont(FontDescriptor.createFrom("Arial", 10, SWT.BOLD | SWT.ITALIC)); doColoring(node, textStyle); textStyle.background = localResourceManager.createColor(new RGB(200, 235, 255)); } }); break; case QUEUED: cell.setImage(notAppliedOperationImage); text.setStyle(0, text.length(), new Styler() { public void applyStyles(TextStyle textStyle) { LocalResourceManager localResMan = new LocalResourceManager( JFaceResources.getResources(Display.getCurrent())); textStyle.font = localResMan.createFont(FontDescriptor.createFrom("Arial", 10, SWT.NORMAL)); doColoring(node, textStyle); } }); break; default: throw new UnsupportedOperationException("Unknown operation status: " + node.getOperationStatus()); } cell.setText(text.toString()); cell.setStyleRanges(text.getStyleRanges()); super.update(cell); }
From source file:org.eclipse.scada.vi.ui.draw2d.primitives.TextController.java
License:Open Source License
private Font convertFont(final String fontName, final Integer fontSize, final Boolean bold, final Boolean italic) { if (fontName == null && fontSize == null && bold == null && italic == null) { return null; }/*from ww w. j a va 2 s . co m*/ FontData[] fontData; Font font = this.figure.getFont(); if (font == null) { font = this.canvas.getFont(); } if (font == null) { font = Display.getDefault().getSystemFont(); } fontData = FontDescriptor.copy(font.getFontData()); if (fontName != null) { if (fontSize != null && fontSize > 0) { fontData = FontDescriptor.createFrom(fontName, fontSize, SWT.NORMAL).getFontData(); } else { // we need to get the original font size and change the font only int origFontSize = 0; for (final FontData fd : fontData) { origFontSize = fd.getHeight(); } fontData = FontDescriptor.createFrom(fontName, origFontSize, SWT.NORMAL).getFontData(); } } for (final FontData fd : fontData) { if (fontName != null) { fd.setName(fontName); } if (fontSize != null && fontSize > 0) { fd.setHeight(fontSize); } int style = fd.getStyle(); if (bold != null) { if (bold) { style = style | SWT.BOLD; } else { style = style & ~SWT.BOLD; } } if (italic != null) { if (italic) { style = style | SWT.ITALIC; } else { style = style & ~SWT.ITALIC; } } fd.setStyle(style); } return this.manager.createFont(FontDescriptor.createFrom(fontData)); }
From source file:org.eclipse.triquetrum.workflow.editor.shapes.ptolemy.TextDrawingStrategy.java
License:Open Source License
@Override public void draw(TextAttribute textAttr, Graphics graphics, ResourceManager resourceManager) { Color fgColor = graphics.getForegroundColor(); java.awt.Color color = textAttr.textColor.asColor(); if (color != null) { Color rgb = resourceManager.createColor(new RGB(color.getRed(), color.getGreen(), color.getBlue())); graphics.setForegroundColor(rgb); }/* w w w .ja v a2 s .c om*/ try { String text = textAttr.text.getExpression(); int fontSize = ((IntToken) textAttr.textSize.getToken()).intValue(); String fontFamily = textAttr.fontFamily.stringValue(); boolean italic = ((BooleanToken) textAttr.italic.getToken()).booleanValue(); boolean bold = ((BooleanToken) textAttr.bold.getToken()).booleanValue(); int style = SWT.NORMAL | (italic ? SWT.ITALIC : SWT.NORMAL) | (bold ? SWT.BOLD : SWT.NORMAL); Font f = resourceManager.createFont(FontDescriptor.createFrom(fontFamily, fontSize, style)); graphics.setFont(f); Point tlp = getTopLeftLocation(textAttr, graphics); graphics.drawText(text, tlp); } catch (IllegalActionException e) { LOGGER.error("Error reading properties for " + textAttr.getFullName(), e); } graphics.setForegroundColor(fgColor); }