Java Code Examples for org.eclipse.jface.resource.FontDescriptor#createFont()
The following examples show how to use
org.eclipse.jface.resource.FontDescriptor#createFont() .
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: FontUtil.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * 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(); } }); }
Example 2
Source File: SyntaxColoringLabel.java From statecharts with Eclipse Public License 1.0 | 6 votes |
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: ReminderView.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
@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; }
Example 4
Source File: NatTableCustomCellPainter.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
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; }
Example 5
Source File: CodewindNavigatorLabelProvider.java From codewind-eclipse with Eclipse Public License 2.0 | 5 votes |
@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; }
Example 6
Source File: AddAnalysisDialog.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static void createSubtitleLabel(Composite parent, String text) { final Label label = new Label(parent, SWT.WRAP); label.setText(text + ':'); final FontDescriptor boldDescriptor = FontDescriptor.createFrom(parent.getFont()).setStyle(SWT.BOLD); final Font boldFont = boldDescriptor.createFont(parent.getDisplay()); label.setFont(boldFont); label.addDisposeListener(event -> boldDescriptor.destroyFont(boldFont)); }
Example 7
Source File: AddAnalysisDialog.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static Label createErrorLabel(Composite parent) { final Label label = new Label(parent, SWT.WRAP); Color color = new Color(parent.getDisplay(), 0xe7, 0x4c, 0x3c); label.setForeground(color); final FontDescriptor fd = FontDescriptor.createFrom(parent.getFont()); Font font = fd.createFont(parent.getDisplay()); label.setFont(font); label.addDisposeListener(e -> { color.dispose(); fd.destroyFont(font); }); return label; }
Example 8
Source File: BibtexEditor.java From slr-toolkit with Eclipse Public License 1.0 | 5 votes |
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); }
Example 9
Source File: AvailableCordovaEnginesSection.java From thym with Eclipse Public License 1.0 | 5 votes |
@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; }
Example 10
Source File: StylerHelpers.java From goclipse with Eclipse Public License 1.0 | 5 votes |
@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()); }
Example 11
Source File: SWTUtil.java From arx with Apache License 2.0 | 5 votes |
/** * 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(); } } }); }
Example 12
Source File: ColorStyler.java From olca-app with Mozilla Public License 2.0 | 5 votes |
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; }
Example 13
Source File: BuilderGeneratorPreferences.java From SparkBuilderGenerator with MIT License | 4 votes |
private Font getBoldFontFor(Label categoryTextLabel) { FontDescriptor boldDescriptor = FontDescriptor.createFrom(categoryTextLabel.getFont()).setStyle(SWT.BOLD); Font boldFont = boldDescriptor.createFont(categoryTextLabel.getDisplay()); return boldFont; }
Example 14
Source File: SyntaxColoringLabel.java From statecharts with Eclipse Public License 1.0 | 4 votes |
protected void setBoldFont(Font f) { if (boldFont != null) boldFont.dispose(); FontDescriptor boldDescriptor = FontDescriptor.createFrom(getFont()).setStyle(SWT.BOLD); boldFont = boldDescriptor.createFont(Display.getDefault()); }
Example 15
Source File: MigrationTaskView.java From depan with Apache License 2.0 | 4 votes |
/** * 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; }