List of usage examples for org.eclipse.jface.resource ResourceManager createFont
public final Font createFont(FontDescriptor descriptor)
From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet015DelayTextModifyEvents.java
License:Open Source License
private static void createControls(Shell shell) { final Label field1 = createLabel(shell, SWT.NONE, "Field 1 "); Text text1 = new Text(shell, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT).applyTo(text1); createLabel(shell, SWT.NONE, "200ms delay"); final Label field2 = createLabel(shell, SWT.NONE, "Field 2 "); Text text2 = new Text(shell, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT).applyTo(text2); createLabel(shell, SWT.NONE, "1000ms delay"); final ISWTObservableValue delayed1 = WidgetProperties.text(SWT.Modify).observeDelayed(200, text1); final ISWTObservableValue delayed2 = WidgetProperties.text(SWT.Modify).observeDelayed(1000, text2); // (In a real application,you would want to dispose the resource manager // when you are done with it) ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); final Font shellFont = shell.getFont(); final Font italicFont = resourceManager .createFont(FontDescriptor.createFrom(shellFont).setStyle(SWT.ITALIC)); final IObservableValue stale1 = Observables.observeStale(delayed1); new ControlUpdater(field2) { protected void updateControl() { boolean stale = ((Boolean) stale1.getValue()).booleanValue(); field2.setFont(stale ? italicFont : shellFont); }/*from w ww . j a va2 s.com*/ }; final IObservableValue stale2 = Observables.observeStale(delayed2); new ControlUpdater(field1) { protected void updateControl() { boolean stale = ((Boolean) stale2.getValue()).booleanValue(); field1.setFont(stale ? italicFont : shellFont); } }; String info = "Pending changes are applied immediately if the observed control loses focus"; GridDataFactory.fillDefaults().span(3, 1).applyTo(createLabel(shell, SWT.WRAP, info)); DataBindingContext dbc = new DataBindingContext(); dbc.bindValue(delayed1, delayed2); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet015DelayTextModifyEvents.java
License:Open Source License
private static void createControls(Shell shell) { final Label field1 = createLabel(shell, SWT.NONE, "Field 1 "); Text text1 = new Text(shell, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT).applyTo(text1); createLabel(shell, SWT.NONE, "200 ms delay"); final Label field2 = createLabel(shell, SWT.NONE, "Field 2 "); Text text2 = new Text(shell, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT).applyTo(text2); createLabel(shell, SWT.NONE, "2000 ms delay"); final ISWTObservableValue<String> delayed1 = WidgetProperties.text(SWT.Modify).observeDelayed(200, text1); final ISWTObservableValue<String> delayed2 = WidgetProperties.text(SWT.Modify).observeDelayed(2000, text2); // (In a real application,you would want to dispose the resource manager // when you are done with it) ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); final Font shellFont = shell.getFont(); final Font italicFont = resourceManager .createFont(FontDescriptor.createFrom(shellFont).setStyle(SWT.ITALIC)); final IObservableValue<Boolean> stale1 = Observables.observeStale(delayed1); new ControlUpdater(field2) { @Override/*from w w w . jav a2 s .c o m*/ protected void updateControl() { field2.setFont(stale1.getValue() ? italicFont : shellFont); } }; final IObservableValue<Boolean> stale2 = Observables.observeStale(delayed2); new ControlUpdater(field1) { @Override protected void updateControl() { field1.setFont(stale2.getValue() ? italicFont : shellFont); } }; String info = "Pending changes are applied immediately if the observed control loses focus."; GridDataFactory.fillDefaults().span(3, 1).hint(300, SWT.DEFAULT) .applyTo(createLabel(shell, SWT.WRAP, info)); DataBindingContext dbc = new DataBindingContext(); dbc.bindValue(delayed1, delayed2); // Sometimes it is useful to do a manual value flush when of the delayed // observables. This can be done in the following two ways. text2.addTraverseListener(e -> { if (e.detail == SWT.TRAVERSE_RETURN) { // The DataBindingContext update methods can also be used to update // observables in bulk dbc.updateTargets(); } }); text1.addTraverseListener(e -> { if (e.detail == SWT.TRAVERSE_RETURN) { // When the setValue method is called on a delayed observable // the change is immediately propagated to its listeners without // any delay. All other pending changes are cancelled. delayed1.setValue(text1.getText()); } }); }
From source file:org.eclipse.scada.chart.swt.render.TitleRenderer.java
License:Open Source License
private Font createFont(final ResourceManager resourceManager) { final Font defaultFont = resourceManager.getDevice().getSystemFont(); if (defaultFont == null) { return null; }// www . j a v a2 s . c om 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)); }
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); }/*from w w w .ja va 2 s .co m*/ 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); }
From source file:org.eclipse.triquetrum.workflow.editor.shapes.ptolemy.TextDrawingStrategy.java
License:Open Source License
@Override protected Dimension getDimension(TextAttribute textAttr, Graphics graphics, ResourceManager resourceManager) { try {//from www. ja va 2s . com 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)); Font oldFont = graphics.getFont(); graphics.setFont(f); FontMetrics fm = graphics.getFontMetrics(); final int width = text.length() * fm.getAverageCharWidth(); final int height = fm.getHeight(); graphics.setFont(oldFont); return new Dimension(width, height); } catch (IllegalActionException e) { LOGGER.error("Error reading dimensions for " + textAttr.getFullName(), e); return new Dimension(0, 0); } }