List of usage examples for org.eclipse.jface.resource JFaceResources getFontRegistry
public static FontRegistry getFontRegistry()
From source file:org.eclipse.e4.tools.emf.ui.common.ImageTooltip.java
License:Open Source License
@Override protected Composite createToolTipContentArea(Event event, Composite parent) { clearResources();// w w w .j a va 2s .c o m parent = new Composite(parent, SWT.NONE); parent.setBackground(event.widget.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); parent.setBackgroundMode(SWT.INHERIT_DEFAULT); parent.setLayout(new GridLayout(2, false)); URI uri = getImageURI(); if (uri != null) { int fileSize = -1; ByteArrayOutputStream out = null; InputStream stream = null; InputStream bStream = null; String errorMessage = "<" + Messages.ImageTooltip_UnknownError + ">"; //$NON-NLS-1$ //$NON-NLS-2$ try { URL url; try { url = new URL(uri.toString()); stream = url.openStream(); } catch (Exception e) { // FIXME Temporary fix to show icon // If not found in runtime search in workspace if (stream == null) { String[] segments = uri.segments(); URI tmpUri = URI.createPlatformResourceURI(segments[1], true); for (int i = 2; i < segments.length; i++) { tmpUri = tmpUri.appendSegment(segments[i]); } url = new URL(tmpUri.toString()); stream = url.openStream(); } } if (stream != null) { out = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int length; while ((length = stream.read(buf)) != -1) { out.write(buf, 0, length); } fileSize = out.size(); bStream = new ByteArrayInputStream(out.toByteArray()); image = new Image(parent.getDisplay(), bStream); } } catch (MalformedURLException e) { errorMessage = e.getMessage(); } catch (FileNotFoundException e) { if (uri.isPlatform()) { errorMessage = MessageFormat.format(Messages.ImageTooltip_FileNotFound, e.getMessage(), uri.segment(1)); } else { errorMessage = e.getMessage(); } } catch (IOException e) { errorMessage = e.getMessage(); } catch (Exception e) { errorMessage = e.getMessage(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (bStream != null) { try { bStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (stream != null) { try { stream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // --------------------------------- Label l = new Label(parent, SWT.NONE); l.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); l.setText(Messages.ImageTooltip_Icon + ":"); //$NON-NLS-1$ l = new Label(parent, SWT.NONE); if (image == null) { System.err.println(errorMessage); l.setText(errorMessage); } else { l.setImage(image); } // --------------------------------- l = new Label(parent, SWT.NONE); l.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); l.setText(Messages.ImageTooltip_Name + ":"); //$NON-NLS-1$ l = new Label(parent, SWT.NONE); l.setText(uri.lastSegment()); // --------------------------------- l = new Label(parent, SWT.NONE); l.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); l.setText(Messages.ImageTooltip_Dimension + ":"); //$NON-NLS-1$ l = new Label(parent, SWT.NONE); if (image != null) { l.setText(image.getBounds().width + "x" + image.getBounds().height + " px"); //$NON-NLS-1$ //$NON-NLS-2$ } else { l.setText("0x0 px"); //$NON-NLS-1$ } // --------------------------------- l = new Label(parent, SWT.NONE); l.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); l.setText(Messages.ImageTooltip_FileSize + ":"); //$NON-NLS-1$ l = new Label(parent, SWT.NONE); l.setText(new DecimalFormat("#,##0.00").format((fileSize / 1024.0)) + "KB"); //$NON-NLS-1$ //$NON-NLS-2$ } return parent; }
From source file:org.eclipse.e4.tools.emf.ui.script.js.text.JavaScriptEditor.java
License:Open Source License
@Inject public JavaScriptEditor(Composite parent, IResourcePool pool) { this.document = new Document(); VerticalRuler verticalRuler = new VerticalRuler(VERTICAL_RULER_WIDTH); int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION; viewer = new SourceViewer(parent, verticalRuler, styles); Font f = null;/*from w ww .java 2 s . c o m*/ if (!JFaceResources.getFontRegistry().hasValueFor("JavaEditorFont")) { if (SWT.getPlatform().equals("carbon") || SWT.getPlatform().equals("cocoa")) { JFaceResources.getFontRegistry().put("JavaEditorFont", new FontData[] { new FontData("Monaco", 11, SWT.NONE) }); } } f = JFaceResources.getFontRegistry().get("JavaEditorFont"); viewer.getTextWidget().setFont(f); JavaScriptTextTools textTools = new JavaScriptTextTools(pool, store); viewer.configure(new JavaScriptSourceViewerConfiguration(textTools)); textTools.setupJavaDocumentPartitioner(document, IJavaScriptPartitions.JAVA_PARTITIONING); viewer.setDocument(document); }
From source file:org.eclipse.e4.xwt.tools.ui.designer.properties.tabbed.sections.ColorSection.java
License:Open Source License
private Point computeImageSize(Control window) { GC gc = new GC(window); Font f = JFaceResources.getFontRegistry().get(JFaceResources.DIALOG_FONT); gc.setFont(f);//w w w . j a v a 2 s .c o m int height = gc.getFontMetrics().getHeight(); gc.dispose(); Point p = new Point(height * 3 - 6, height); return p; }
From source file:org.eclipse.e4mf.common.ui.viewer.ColumnViewerInformationControlToolTipSupport.java
License:Open Source License
protected String getSymbolicFont() { if (font == null) { return DEFAULT_FONT; } else {// w ww.j a va 2s .c om FontData[] fontData = font.getFontData(); FontRegistry fontRegistry = JFaceResources.getFontRegistry(); for (Object name : fontRegistry.getKeySet()) { FontData[] registerFontData = fontRegistry.getFontData((String) name); if (Arrays.equals(fontData, registerFontData)) { return (String) name; } } return DEFAULT_FONT; } }
From source file:org.eclipse.ecf.internal.example.collab.ui.LineChatClientView.java
License:Open Source License
public LineChatClientView(EclipseCollabSharedObject lch, LineChatView view, String name, String initText, String downloaddir) {//www .j ava2s . c o m super(); this.lch = lch; this.view = view; this.name = name; this.teamChat = new TeamChat(this, view.tabFolder, SWT.NULL, initText); this.userdata = lch.getUser(); this.downloaddir = downloaddir; users = new ArrayList(); teamChat.getTableViewer().setInput(users); if (userdata != null) addUser(userdata); ClientPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(ClientPlugin.PREF_DISPLAY_TIMESTAMP)) { showTimestamp = ((Boolean) event.getNewValue()).booleanValue(); } } }); JFaceResources.getColorRegistry().put(ViewerToolTip.HEADER_BG_COLOR, new RGB(255, 255, 255)); JFaceResources.getFontRegistry().put(ViewerToolTip.HEADER_FONT, JFaceResources.getFontRegistry() .getBold(JFaceResources.getDefaultFont().getFontData()[0].getName()).getFontData()); final ToolTip toolTip = new ViewerToolTip(teamChat.getTableViewer().getControl()); toolTip.setHideOnMouseDown(false); toolTip.setPopupDelay(200); }
From source file:org.eclipse.edt.ide.eunit.ui.testresult.TestResultPkgNodeDetailsPage.java
License:Open Source License
protected Text createColorBoldReadOnlyNoBoraderText(FormToolkit toolkit, Composite parent, int span, String labelText, Color color) { Text textControl = createReadOnlyNoBorderText(toolkit, parent, span, labelText); textControl.setForeground(color);/*w ww. j a v a2 s .co m*/ textControl.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); return textControl; }
From source file:org.eclipse.edt.ide.rui.visualeditor.internal.util.ColorSelectionDialog.java
License:Open Source License
/** * Creates an image for each named color. *//* ww w . java2 s. c o m*/ protected void initializeColorImages() { GC gc = new GC(getShell()); Font f = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT); gc.setFont(f); int iImageHeight = gc.getFontMetrics().getHeight(); gc.dispose(); Color colorBlack = getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK); String[] straColors = ColorUtil.getColorNames(); String[] straHex = ColorUtil.getColorHexValues(); _colors = new Color[straColors.length]; _images = new Image[straColors.length]; for (int i = 0; i < straHex.length; i++) { // Convert to decimal //------------------- String strR = straHex[i].substring(0, 2); String strG = straHex[i].substring(2, 4); String strB = straHex[i].substring(4); int iR = Integer.parseInt(strR, 16); int iG = Integer.parseInt(strG, 16); int iB = Integer.parseInt(strB, 16); RGB rgb = new RGB(iR, iG, iB); _colors[i] = new Color(getShell().getDisplay(), rgb); _images[i] = new Image(getShell().getDisplay(), IMAGE_WIDTH, iImageHeight); // Fill the background with the button color //------------------------------------------ gc = new GC(_images[i]); gc.setBackground(_colors[i]); gc.fillRectangle(0, 0, IMAGE_WIDTH, iImageHeight); gc.setBackground(colorBlack); gc.drawRectangle(0, 0, IMAGE_WIDTH - 1, iImageHeight - 1); gc.dispose(); } }
From source file:org.eclipse.emf.diffmerge.ui.util.UIUtil.java
License:Open Source License
/** * Return the bold variant of the given font * @param font_p a non-null font/*from ww w .java2s .c o m*/ * @return a non-null font */ public static Font getBold(Font font_p) { FontData data = font_p.getFontData()[0]; Font result = JFaceResources.getFontRegistry().getBold(data.getName()); return result; }
From source file:org.eclipse.emf.diffmerge.ui.util.UIUtil.java
License:Open Source License
/** * Return the italic variant of the given font * @param font_p a non-null font/* w w w.ja v a 2 s. com*/ * @return a non-null font */ public static Font getItalic(Font font_p) { FontData data = font_p.getFontData()[0]; Font result = JFaceResources.getFontRegistry().getItalic(data.getName()); return result; }
From source file:org.eclipse.emf.ecoretools.design.properties.BindingViewHelper.java
License:Open Source License
/** * {@inheritDoc}//w ww. jav a2 s . co m * @see org.eclipse.emf.eef.runtime.ui.parts.ViewHelper#createLabel(org.eclipse.swt.widgets.Composite, java.lang.Object, java.lang.String) */ public Label createLabel(Composite parent, Object editor, String alternate) { IPropertiesEditionComponent propertiesEditingComponent = context.getPropertiesEditingComponent(); String text = getDescription(editor, alternate); if (!text.endsWith(": ") && !text.endsWith(":")) { text += ": "; } Label label; if (toolkit != null) { label = toolkit.createLabel(parent, text); } else { label = new Label(parent, SWT.NONE); label.setText(text); } // Asserting that toolkit is setted => kind == Form if (propertiesEditingComponent != null && propertiesEditingComponent.isRequired(editor, toolkit == null ? 0 : 1)) { label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); } return label; }