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 ) ); }
/** * Converts the font of the control by adding a single style bit, unless the font already have * that style. * <p> * If the font is converted, it will attach a {@link DisposeListener} * to the <code>control</code> to dispose the font when it's not needed anymore. * <p> * <em>If converting fonts is a frequent operation, this method will create * several {@link DisposeListener}s that can lead to high resource allocation</em> * * @param control whose font will be changed * @param style e.g. SWT.BOLD or SWT.ITALIC */ public static void convertFont(Control control, int style) { for (FontData fontData : control.getFont().getFontData()) { if (hasStyle(fontData, style)) { return; } } FontDescriptor fontDescriptor = FontDescriptor.createFrom(control.getFont()).setStyle(style); final Font newFont = fontDescriptor.createFont(control.getDisplay()); control.setFont(newFont); control.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent event) { newFont.dispose(); } }); }
@Override public Font getFont(Object element) { if (element instanceof PaletteTreeNodeEditPart) { if (BOLD_FONT == null) { Widget widget = ((PaletteEntryEditPart) element).getWidget(); if (widget instanceof TreeItem) { TreeItem treeItem = (TreeItem) widget; Font f = null; // there's something about the order of tree construction logic that causes treeitems to not be // fully ready yet here if (!treeItem.isDisposed()) { f = treeItem.getFont(); } else { f = new Font(Display.getCurrent(), viewer.getPaletteViewerPreferences().getFontData()); } FontDescriptor boldDescriptor = FontDescriptor.createFrom(f).setStyle(SWT.BOLD); BOLD_FONT = boldDescriptor.createFont(Display.getCurrent()); } } return BOLD_FONT; } return null; }
@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); } 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.drawText(text, tlp); } catch (IllegalActionException e) { LOGGER.error("Error reading properties for " + textAttr.getFullName(), e); } graphics.setForegroundColor(fgColor); }
@Override protected Dimension getDimension(TextAttribute textAttr, ResourceManager resourceManager) { 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)); return FigureUtilities.getTextExtents(text, f); } catch (IllegalActionException e) { LOGGER.error("Error reading dimensions for " + textAttr.getFullName(), e); return new Dimension(0, 0); } }
@Override public Font getFont(Object element) { if (element instanceof ModelHandleTreeNode) { ModelHandleTreeNode handleNode = (ModelHandleTreeNode) element; if (handleNode.getRepository().isActiveModelRevision(handleNode.getValue())) { if (boldFont == null) { Font f = new Font(Display.getCurrent(), viewer.getControl().getFont().getFontData()); FontDescriptor boldDescriptor = FontDescriptor.createFrom(f).setStyle(SWT.BOLD); boldFont = getResourceManager().createFont(boldDescriptor); } return boldFont; } return null; } return null; }
/** * 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. * * @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(IFigure label) { Font scaledFont = label.getFont(); FontData data = scaledFont.getFontData()[0]; 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 { FontDescriptor fontDescriptor = FontDescriptor.createFrom(data); cachedFontDescriptors.add(fontDescriptor); return getResourceManager().createFont(fontDescriptor); } catch (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(); }
@Override protected void constrainShellSize() { super.constrainShellSize(); if (Util.isCocoa()) { final Tree tree = getTreeViewer().getTree(); final FontDescriptor treeFontDescriptor = FontDescriptor.createFrom(JFaceResources.getBannerFont()).setStyle(SWT.NORMAL); final Font treeFont = treeFontDescriptor.createFont(tree.getDisplay()); updateTreeFont(treeFont); tree.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { treeFontDescriptor.destroyFont(treeFont); } }); } }
@PostConstruct public void postConstruct(Composite parent) { ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); TreeViewer viewer = new TreeViewer(parent); viewer.setContentProvider(new TreeContentProvider()); viewer.getTree().setHeaderVisible(true); viewer.getTree().setLinesVisible(true); viewer.getTree().setFont(resourceManager.createFont(FontDescriptor.createFrom("Arial", 32, SWT.ITALIC))); TreeViewerColumn viewerColumn = new TreeViewerColumn(viewer, SWT.NONE); viewerColumn.getColumn().setWidth(300); viewerColumn.getColumn().setText("Names"); viewerColumn.setLabelProvider(new ColumnLabelProvider()); viewer.setInput(new String[] { "Simon Scholz", "Lars Vogel", "Dirk Fauth", "Wim Jongman", "Tom Schindl" }); GridLayoutFactory.fillDefaults().generateLayout(parent); }
@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; } }
@Override public Font getFont(Object element){ if (element instanceof Reminder) { Reminder reminder = (Reminder) element; if (boldFont == null) { Display disp = Display.getCurrent(); Font defaultFont = cv.getViewerWidget().getControl().getFont(); FontDescriptor boldDescriptor = FontDescriptor.createFrom(defaultFont).setStyle(SWT.BOLD); boldFont = boldDescriptor.createFont(disp); } Priority prio = reminder.getPriority(); if (Priority.HIGH == prio) { return boldFont; } } return null; }
private int drawTextPart(GC gc, int yStartPos, int xStartPos, TextPart text){ Point textExtent = new Point(0, 0); if (text.getStyle() == TextPart.PartStyle.NORMAL) { textExtent = gc.stringExtent(text.getText()); gc.drawText(text.getText(), xStartPos, yStartPos + spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER); } else if (text.getStyle() == TextPart.PartStyle.BOLD) { Font origFont = gc.getFont(); FontDescriptor boldDescriptor = FontDescriptor.createFrom(gc.getFont()).setStyle(SWT.BOLD); Font boldFont = boldDescriptor.createFont(Display.getDefault()); gc.setFont(boldFont); textExtent = gc.stringExtent(text.getText()); gc.drawText(text.getText(), xStartPos, yStartPos + spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER); gc.setFont(origFont); boldFont.dispose(); } return xStartPos + textExtent.x; }
public VaccinationCompositePaintListener(){ Display disp = Display.getCurrent(); defaultFont = UiDesk.getFont(Preferences.USR_DEFAULTFONT); FontDescriptor boldDescriptor = FontDescriptor.createFrom(defaultFont).setStyle(SWT.BOLD); boldFont = boldDescriptor.createFont(disp); headerFont = new Font(disp, "Helvetica", 16, SWT.BOLD); distanceBetweenDiseases = (int) (distanceBetweenDiseases * getScaleFactor()); fontHeightDefaultFont = (int) ((defaultFont.getFontData()[0].getHeight() + 5) * getScaleFactor()); fontHeightBoldFont = (int) ((boldFont.getFontData()[0].getHeight() + 5) * getScaleFactor()); entryHeight = (int) ((fontHeightBoldFont + 4) * getScaleFactor()); defaultEntryHeight = entryHeight; naviVacMap = new TreeMap<Integer, Vaccination>(); selectedVacc = null; showSide = CoreHub.userCfg.get(PreferencePage.VAC_SHOW_SIDE, false); }
private Font createColumnFont(final ColumnOptions<T> options, ViewerCell cell) { Font font = options.getFont(); if (font == null) { FontDescriptor fontDescriptor = FontDescriptor.createFrom(cell.getFont()).setStyle(options.getFontStyle()); font = fontDescriptor.createFont(cell.getControl().getDisplay()); options.setFont(font); } return font; }
/** * Changes a control's font * @param control * @param style * @throws DeviceResourceException */ public static void changeFont(Control control, int style) throws DeviceResourceException { FontDescriptor boldDescriptor = FontDescriptor.createFrom(control.getFont()); final Font boldFont = boldDescriptor.createFont(control.getDisplay()); control.setFont(boldFont); control.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent arg0) { if (boldFont != null && !boldFont.isDisposed()) { boldFont.dispose(); } } }); }
public static Font createFont(String name, int height, int style) { String id = name+"_"+height+"_"+style; Font f = fontCache.get(id); if (f == null) { // create new font and put it into cache f = resManager.createFont(FontDescriptor.createFrom(name, height, style)); fontCache.put(id, f); logger.debug("created font: "+id+" N="+fontCache.size()); } return f; }
/** * @see org.eclipse.gef.tools.DirectEditManager#bringDown() */ protected void bringDown() { if (proposalPopupForegroundColor != null) { proposalPopupForegroundColor.dispose(); proposalPopupForegroundColor = null; } if (proposalPopupBackgroundColor != null) { proposalPopupBackgroundColor.dispose(); proposalPopupBackgroundColor = null; } // myee - RATLC00523014: crashes when queued in asyncExec() eraseFeedback(); initialString = new StringBuffer(); Display.getCurrent().asyncExec(new Runnable() { public void run() { // Content Assist hack - allow proper cleanup on childen // controls XtextDirectEditManager.super.bringDown(); } }); for (Iterator<FontDescriptor> iter = cachedFontDescriptors.iterator(); iter.hasNext();) { getResourceManager().destroyFont((FontDescriptor) iter.next()); } cachedFontDescriptors.clear(); if (actionHandler != null) { actionHandler.dispose(); actionHandler = null; } if (actionBars != null) { restoreSavedActions(actionBars); actionBars.updateActionBars(); actionBars = null; } }
/** * This method obtains the fonts that are being used by the figure at its * zoom level. * * @param gep * the associated <code>GraphicalEditPart</code> of the figure * @param actualFont * font being used by the figure * @param display * @return <code>actualFont</code> if zoom level is 1.0 (or when there's an * error), new Font otherwise. */ private Font getZoomLevelFont(Font actualFont, Display display) { Object zoom = getEditPart().getViewer().getProperty(ZoomManager.class.toString()); if (zoom != null) { double zoomLevel = ((ZoomManager) zoom).getZoom(); if (zoomLevel == 1.0f) return actualFont; FontData[] fd = new FontData[actualFont.getFontData().length]; FontData tempFD = null; for (int i = 0; i < fd.length; i++) { tempFD = actualFont.getFontData()[i]; fd[i] = new FontData(tempFD.getName(), (int) (zoomLevel * tempFD.getHeight()), tempFD.getStyle()); } try { FontDescriptor fontDescriptor = FontDescriptor.createFrom(fd); cachedFontDescriptors.add(fontDescriptor); return getResourceManager().createFont(fontDescriptor); } catch (DeviceResourceException e) { Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "getZoomLevelFonts", e); //$NON-NLS-1$ Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "getZoomLevelFonts", e); //$NON-NLS-1$ return actualFont; } } else return actualFont; }
private void createPageLabel(Composite composite, GridData gridData) { Label label = new Label(composite, SWT.LEFT); label.setText(document.getTitle()); FontDescriptor boldDescriptor = FontDescriptor.createFrom(label.getFont()).setStyle(SWT.BOLD); Font boldFont = boldDescriptor.createFont(label.getDisplay()); label.setFont(boldFont); label.setLayoutData(gridData); }
public Font getFontData() { FontData fontData = Display.getCurrent().getSystemFont().getFontData()[0]; // new FontData() //FontDescriptor boldDescriptor = FontDescriptor.createFrom(fontData).setStyle(SWT.BOLD); FontDescriptor boldDescriptor = FontDescriptor.createFrom(fontData).setHeight(fontData.getHeight() + 2); Font boldFont = boldDescriptor.createFont(Display.getCurrent()); return boldFont; }
@Override public void applyStyles(final TextStyle textStyle) { FontData fontData = Display.getCurrent().getSystemFont().getFontData()[0]; // new FontData() FontDescriptor boldDescriptor = FontDescriptor.createFrom(fontData).setStyle(SWT.BOLD); Font boldFont = boldDescriptor.createFont(Display.getCurrent()); textStyle.font = boldFont; }
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)); }
@Override public Font getFont(Object element) { if (!engineList.getChecked(element)) return null; if (boldFont == null) { FontDescriptor fontDescriptor = JFaceResources.getDialogFontDescriptor(); fontDescriptor = fontDescriptor.setStyle(SWT.BOLD); boldFont = fontDescriptor.createFont(Display.getCurrent()); } return boldFont; }
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); }
/** * Used in the script pyedit_list_bindings.py */ public Font getFont(FontData descriptor) throws DeviceResourceException { Font font = getResourceManager().createFont(FontDescriptor.createFrom(descriptor)); // Old implementation (for Eclipse 3.3) // Font font = (Font) SWTResourceUtil.getFontTable().get(descriptor); // if (font == null) { // font = new Font(Display.getCurrent(), descriptor); // SWTResourceUtil.getFontTable().put(descriptor, font); // } return font; }
@Override public void applyStyles(TextStyle textStyle) { if(parentStyler != null) { parentStyler.applyStyles(textStyle); } Font font = textStyle.font; if(font == null) { font = JFaceResources.getDefaultFont(); } FontDescriptor fontDescriptor = FontDescriptor.createFrom(font); fontDescriptor = getModifiedFontDescriptor(fontDescriptor); textStyle.font = fontDescriptor.createFont(Display.getCurrent()); }
/** * Changes a control's font * @param control * @param style */ public static void changeFont(Control control, int style) { FontDescriptor boldDescriptor = FontDescriptor.createFrom(control.getFont()).setStyle(style); final Font boldFont = boldDescriptor.createFont(control.getDisplay()); control.setFont(boldFont); control.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent arg0) { if (boldFont != null && !boldFont.isDisposed()) { boldFont.dispose(); } } }); }
private Font getFont() { if (font != null) return font; FontDescriptor desc = FontDescriptor.createFrom( Display.getCurrent().getSystemFont()).setStyle(SWT.ITALIC); font = desc.createFont(Display.getCurrent()); return font; }
public static final Font bold(final Font font) { FontDescriptor fd = FontDescriptor.createFrom(font); return fd.setStyle(SWT.BOLD).createFont(Display.getDefault()); }
public static final Font size(Font font, int delta) { FontDescriptor fd = FontDescriptor.createFrom(font); int height = fd.getFontData()[0].getHeight() + delta; return fd.setHeight(height).createFont(Display.getDefault()); }
@Override public void applyStyles(final TextStyle textStyle) { FontDescriptor boldDescriptor = FontDescriptor.createFrom(new FontData()).setStyle(SWT.BOLD); Font boldFont = boldDescriptor.createFont(Display.getCurrent()); textStyle.font = boldFont; }
private Font getBoldFontFor(Label categoryTextLabel) { FontDescriptor boldDescriptor = FontDescriptor.createFrom(categoryTextLabel.getFont()).setStyle(SWT.BOLD); Font boldFont = boldDescriptor.createFont(categoryTextLabel.getDisplay()); return boldFont; }
public DefaultFontStyler(FontDescriptor fontDescriptor, String foregroundColorName, String backgroundColorName) { this.fontDescriptor = fontDescriptor; this.foregroundColorName = foregroundColorName; this.backgroundColorName = backgroundColorName; }
protected void setBoldFont(Font f) { if (boldFont != null) boldFont.dispose(); FontDescriptor boldDescriptor = FontDescriptor.createFrom(getFont()).setStyle(SWT.BOLD); boldFont = boldDescriptor.createFont(Display.getDefault()); }
private static FontDescriptor getFontDescriptor(final Control control) { return FontDescriptor.createFrom(control.getFont()); }
private static <C extends Control> C setFont(final C control, final FontDescriptor descriptor) { control.setFont(descriptor.createFont(Display.getCurrent())); return control; }
/** * Construct the GUI under the given parent. * * @param parent the parent Composite. * @return the top level widget. */ private Composite setupComposite(Composite parent) { // widgets Composite topLevel = new Composite(parent, SWT.NONE); Label labelId = new Label(topLevel, SWT.NONE); id = new Label(topLevel, SWT.NONE); Label labelName = new Label(topLevel, SWT.NONE); name = new Label(topLevel, SWT.NONE); Label labelDescription = new Label(topLevel, SWT.NONE); description = new Label(topLevel, SWT.NONE); Label labelQuarter = new Label(topLevel, SWT.NONE); quarter = new Label(topLevel, SWT.NONE); Label labelUpdatedBy = new Label(topLevel, SWT.NONE); updatedBy = new Label(topLevel, SWT.NONE); // content labelId.setText("ID"); labelName.setText("Name"); labelDescription.setText("Description"); labelQuarter.setText("Quarter"); labelUpdatedBy.setText("Updated by"); // layout GridLayout layout = new GridLayout(2, false); layout.horizontalSpacing = 22; layout.verticalSpacing = 9; topLevel.setLayout(layout); id.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); name.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); quarter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); updatedBy.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); Font font = name.getFont(); FontDescriptor bold = FontDescriptor.createFrom(font); bold = bold.setStyle(SWT.BOLD); FontDescriptor big = bold.setHeight(18); Font boldFont = bold.createFont(font.getDevice()); name.setFont(big.createFont(font.getDevice())); id.setFont(boldFont); description.setFont(boldFont); quarter.setFont(boldFont); updatedBy.setFont(boldFont); return topLevel; }
private Font getFont(Control control, int style) { FontDescriptor fontDescriptor = FontDescriptor.createFrom(control.getFont()); Font styledFont = fontDescriptor.setStyle(style).createFont(Display.getCurrent()); return styledFont; }
@PostConstruct public void createComposite(Composite parent) { addFonts(display); ResourceManager resManager = new LocalResourceManager(JFaceResources.getResources(), parent); FontDescriptor fontDescriptor = FontDescriptor.createFrom("Roboto-ThinItalic", 11, SWT.NORMAL); Font font = resManager.createFont(fontDescriptor); parent.setLayout(new GridLayout(1, false)); txtInput = new Text(parent, SWT.BORDER); txtInput.setFont(font); txtInput.setMessage("Enter text to mark part as dirty"); txtInput.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { dirty.setDirty(true); } }); FontData fd = txtInput.getFont().getFontData()[0]; txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Text txtInput2 = new Text(parent, SWT.BORDER); txtInput2.setMessage("Enter text to mark part as dirty"); txtInput2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button button = new Button(parent, SWT.PUSH); button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); button.setFont(font); button.setText("Press me"); Button button2 = new Button(parent, SWT.PUSH); button2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); button2.setText("Press me"); tableViewer = new TableViewer(parent); tableViewer.setContentProvider(ArrayContentProvider.getInstance());; tableViewer.setInput(createInitialDataModel()); tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); }