List of usage examples for org.eclipse.jface.resource JFaceResources getFont
public static Font getFont(String symbolicName)
From source file:org.springsource.ide.eclipse.commons.quicksearch.ui.QuickSearchDialog.java
License:Open Source License
private void createDetailsArea(Composite parent) { details = new StyledText(parent, SWT.MULTI + SWT.READ_ONLY + SWT.BORDER + SWT.H_SCROLL); details.setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); // GridDataFactory.fillDefaults().grab(true, false).applyTo(details); // details = new SourceViewer(parent, null, SWT.READ_ONLY+SWT.MULTI+SWT.BORDER); // details.getTextWidget().setText("Line 1\nLine 2\nLine 3\nLine 4\nLine 5"); // details.setEditable(false); ///*from w w w . ja v a 2s . c o m*/ // IPreferenceStore prefs = EditorsPlugin.getDefault().getPreferenceStore(); // TextSourceViewerConfiguration sourceViewerConf = new TextSourceViewerConfiguration(prefs); // details.configure(sourceViewerConf); // // GridDataFactory.fillDefaults().grab(true, false).applyTo(details); // Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); // details.getTextWidget().setFont(font); list.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { refreshDetails(); } }); details.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { refreshDetails(); } }); }
From source file:org.springsource.ide.eclipse.commons.ui.HtmlTooltip.java
License:Open Source License
private Point computeSizeHint(Browser browser, String html) { TextLayout fTextLayout = new TextLayout(browser.getDisplay()); // Initialize fonts Font defaultFont = JFaceResources.getFont(JFaceResources.DIALOG_FONT); FontData fd = defaultFont.getFontData()[0]; // Try getting font from the HTML style tag String family = fd.getName(); int size = fd.getHeight(); int style = SWT.NONE; Matcher matcher = FONT_FAMILY_PATTERN.matcher(html); if (matcher.find()) { family = matcher.group(1);//from w ww. j a v a 2 s . c om } matcher = FONT_SIZE_PATTERN.matcher(html); if (matcher.find()) { try { size = Integer.valueOf(matcher.group(1)); } catch (NumberFormatException e) { // ignore } } matcher = FONT_STYLE_PATTERN.matcher(html); if (matcher.find()) { if ("italic".equalsIgnoreCase(matcher.group(1))) { style |= SWT.ITALIC; } } matcher = FONT_WEIGHT_PATTERN.matcher(html); if (matcher.find()) { if ("bold".equalsIgnoreCase(matcher.group(1))) { style |= SWT.BOLD; } } Font font = null; Font boldFont = null; try { font = new Font(defaultFont.getDevice(), new FontData(family, size, style)); fTextLayout.setFont(font); fTextLayout.setWidth(-1); boldFont = new Font(font.getDevice(), new FontData(family, size, style | SWT.BOLD)); TextStyle fBoldStyle = new TextStyle(boldFont, null, null); // Compute and set tab width fTextLayout.setText(" "); //$NON-NLS-1$ int tabWidth = fTextLayout.getBounds().width; fTextLayout.setTabs(new int[] { tabWidth }); fTextLayout.setText(""); //$NON-NLS-1$ Rectangle trim = /*browser.getParent().computeTrim(0, 0, 0, 0)*/new Rectangle(0, 0, 35, 20); int height = trim.height; //FIXME: The HTML2TextReader does not render <p> like a browser. // Instead of inserting an empty line, it just adds a single line break. // Furthermore, the indentation of <dl><dd> elements is too small (e.g with a long @see line) TextPresentation presentation = new TextPresentation(); String text; try (HTML2TextReader reader = new HTML2TextReader(new StringReader(html), presentation)) { text = reader.getString(); } catch (IOException e) { text = ""; //$NON-NLS-1$ } fTextLayout.setText(text); fTextLayout.setWidth(maxSizeConstraints == null || maxSizeConstraints.x < trim.width ? SWT.DEFAULT : maxSizeConstraints.x - trim.width); Iterator<StyleRange> iter = presentation.getAllStyleRangeIterator(); while (iter.hasNext()) { StyleRange sr = iter.next(); if (sr.fontStyle == SWT.BOLD) { fTextLayout.setStyle(fBoldStyle, sr.start, sr.start + sr.length - 1); } } Rectangle bounds = fTextLayout.getBounds(); // does not return minimum width, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=217446 int lineCount = fTextLayout.getLineCount(); int textWidth = 0; for (int i = 0; i < lineCount; i++) { Rectangle rect = fTextLayout.getLineBounds(i); int lineWidth = rect.x + rect.width; // if (i == 0) // lineWidth+= fInput.getLeadingImageWidth(); textWidth = Math.max(textWidth, lineWidth); } bounds.width = textWidth; fTextLayout.setText(""); //$NON-NLS-1$ int minWidth = bounds.width; height = height + bounds.height; // Add some air to accommodate for different browser renderings // minWidth+= 15; // height+= 20; // Apply max size constraints if (maxSizeConstraints != null) { if (maxSizeConstraints.x != SWT.DEFAULT) { minWidth = Math.min(maxSizeConstraints.x, minWidth + trim.width); } if (maxSizeConstraints.y != SWT.DEFAULT) { height = Math.min(maxSizeConstraints.y, height); } } // Ensure minimal size int width = Math.max(MIN_WIDTH, minWidth); height = Math.max(MIN_HEIGHT, height); fTextLayout.dispose(); font.dispose(); boldFont.dispose(); return new Point(width, height); } finally { if (font != null) { font.dispose(); } if (boldFont != null) { boldFont.dispose(); } } }
From source file:org.summer.sdt.internal.ui.preferences.JavaEditorColoringConfigurationBlock.java
License:Open Source License
private Control createPreviewer(Composite parent) { IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore(); IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { getPreferenceStore(), new PreferencesAdapter(createTemporaryCorePreferenceStore()), generalTextStore }); fPreviewViewer = new JavaSourceViewer(parent, null, null, false, SWT.H_SCROLL | SWT.BORDER, store); SimpleJavaSourceViewerConfiguration configuration = new SimpleJavaSourceViewerConfiguration(fColorManager, store, null, IJavaPartitions.JAVA_PARTITIONING, false); fPreviewViewer.configure(configuration); // fake 1.5 source to get 1.5 features right. configuration.handlePropertyChangeEvent(new PropertyChangeEvent(this, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4, JavaCore.VERSION_1_5)); Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); fPreviewViewer.getTextWidget().setFont(font); new JavaSourcePreviewerUpdater(fPreviewViewer, configuration, store); fPreviewViewer.setEditable(false);//from w w w .ja va 2 s .c om Cursor arrowCursor = fPreviewViewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW); fPreviewViewer.getTextWidget().setCursor(arrowCursor); // Don't set caret to 'null' as this causes https://bugs.eclipse.org/293263 // fPreviewViewer.getTextWidget().setCaret(null); String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$ IDocument document = new Document(content); JavaPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING); fPreviewViewer.setDocument(document); installSemanticHighlighting(); return fPreviewViewer.getControl(); }
From source file:org.talend.core.ui.properties.tab.TalendTabbedPropertyTitle.java
License:Open Source License
/** * Constructor for TabbedPropertyTitle./*from w w w. j a va 2 s . c om*/ * * @param parent the parent composite. * @param factory the widget factory for the tabbed property sheet */ public TalendTabbedPropertyTitle(Composite parent, TabbedPropertySheetWidgetFactory factory) { super(parent, SWT.NO_FOCUS); this.factory = factory; colorHelper = new TalendTabbedPropertyColorHelper(factory); // CSS CoreUIPlugin.setCSSClass(this, this.getClass().getSimpleName()); this.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { if (image == null && (text == null || text.equals(BLANK))) { label.setVisible(false); } else { label.setVisible(true); drawTitleBackground(e); } } }); factory.getColors().initializeSectionToolBarColors(); setBackground(factory.getColors().getBackground()); setForeground(factory.getColors().getForeground()); FormLayout layout = new FormLayout(); layout.marginWidth = 1; layout.marginHeight = 2; setLayout(layout); Font font; if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) { FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT) .getFontData(); /* title font is 2pt larger than that used in the tabs. */ fontData[0].setHeight(fontData[0].getHeight() + 2); JFaceResources.getFontRegistry().put(TITLE_FONT, fontData); } font = JFaceResources.getFont(TITLE_FONT); label = factory.createCLabel(this, BLANK); if (colorHelper.getTitleBackground() == null) { label.setBackground(new Color[] { factory.getColors().getColor(IFormColors.H_GRADIENT_END), factory.getColors().getColor(IFormColors.H_GRADIENT_START) }, new int[] { 100 }, true); } else { label.setBackground(colorHelper.getTitleBackground()); } label.setFont(font); label.setForeground(colorHelper.getTitleForeground()); FormData data = new FormData(); data.left = new FormAttachment(0, 0); data.top = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); label.setLayoutData(data); /* * setImage(PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_ELEMENT)); */ }
From source file:org.talend.designer.core.ui.views.CodeView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { this.parent = parent; parent.setLayout(new FillLayout()); ECodeLanguage language = LanguageManager.getCurrentLanguage(); ISourceViewer viewer = null;/* w ww.ja va2s .c om*/ final StyledText text; int styles = SWT.H_SCROLL | SWT.V_SCROLL; document = new Document(); switch (language) { case JAVA: IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore(); viewer = new JavaSourceViewer(parent, null, null, false, styles, store); viewer.setDocument(document); JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools(); tools.setupJavaDocumentPartitioner(viewer.getDocument(), IJavaPartitions.JAVA_PARTITIONING); SimpleJavaSourceViewerConfiguration config = new SimpleJavaSourceViewerConfiguration( tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, true); viewer.configure(config); viewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); document = viewer.getDocument(); break; default: // empty since only have java } viewer.setEditable(false); text = viewer.getTextWidget(); // getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this); IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager(); IAction wrapAction = new Action() { @Override public void run() { text.setWordWrap(isChecked()); } }; wrapAction.setToolTipText("wrap"); //$NON-NLS-1$ wrapAction.setChecked(false); wrapAction.setImageDescriptor(ImageDescriptor.createFromFile(DesignerPlugin.class, "/icons/wrap.gif")); //$NON-NLS-1$ tbm.add(wrapAction); createMenu(); }
From source file:org.talend.repository.ui.login.AbstractLoginActionPage.java
License:Open Source License
public AbstractLoginActionPage(Composite parent, LoginDialogV2 dialog, int style) { super(parent, style); stackLayout = (StackLayout) parent.getLayout(); this.loginDialog = dialog; this.setFont(JFaceResources.getFont(LoginDialogV2.FONT_TALEND_FOR_LOGIN_UI)); this.backgroundColor = JFaceResources.getColorRegistry().get(LoginDialogV2.COLOR_LOGON_DIALOG_BACKGROUND); }
From source file:org.thanlwinsoft.doccharconvert.eclipse.editors.MappingTableLabelProvider.java
License:Open Source License
@Override public Font getFont(Object element, int columnIndex) { if (columnIndex < COL_OFFSET) { return JFaceResources.getFont(JFaceResources.TEXT_FONT); }/*from w ww .j a v a 2s. c o m*/ String ref = mappingTable.getColumns().getComponentArray(columnIndex - COL_OFFSET).getR(); SyllableConverter sc = mParentEditor.getDocument().getSyllableConverter(); int side = SyllableConverterUtils.getSide(sc, ref); return mParentEditor.getFont(side); }
From source file:org.thanlwinsoft.doccharconvert.eclipse.editors.SyllableConverterEditor.java
License:Open Source License
protected Font getFont(int side) { if (mFonts[side] != null) return mFonts[side]; Script s = converterDoc.getSyllableConverter().getScriptArray(side); String faceName = s.getFont(); Font font = JFaceResources.getFont(JFaceResources.TEXT_FONT); if (faceName == null) { InputStream is = null;/*from ww w .j a va 2 s . c om*/ try { URL fileUrl = mFileInput.getURI().toURL(); String filename = fileUrl.getPath(); int dot = filename.lastIndexOf("."); if (dot > -1) { filename = filename.substring(0, dot + 1) + "dccx"; fileUrl.getHost(); fileUrl = new URL(fileUrl, filename); is = fileUrl.openStream(); } } catch (MalformedURLException e) { DocCharConvertEclipsePlugin.log(IStatus.WARNING, e.getLocalizedMessage(), e); } catch (IOException e) { DocCharConvertEclipsePlugin.log(IStatus.WARNING, e.getLocalizedMessage(), e); } // if (inputFile != null) // { // IPath dccxPath = inputFile.getFullPath(); // // if (dccxPath != null) // { // dccxPath = // dccxPath.removeFileExtension().addFileExtension("dccx"); // IResource dccxRes = // ResourcesPlugin.getWorkspace().getRoot().findMember(dccxPath); // if (dccxRes instanceof IFile) // { // IFile dccxFile = (IFile)dccxRes; // try // { // is = dccxFile.getContents(true); // } // catch (CoreException e) // { // DocCharConvertEclipsePlugin.log(IStatus.WARNING, // e.getLocalizedMessage(), e); // } // } // } // else // { // dccxPath = // inputFile.getLocation().removeFileExtension().addFileExtension // ("dccx"); // File file = dccxPath.toFile(); // try // { // is = new FileInputStream(file); // } // catch (FileNotFoundException e) // { // DocCharConvertEclipsePlugin.log(IStatus.WARNING, // e.getLocalizedMessage(), e); // } // } if (is != null) { try { DocCharConverterDocument doc = DocCharConverterDocument.Factory.parse(is); Styles styles = doc.getDocCharConverter().getStyles(); if (styles.sizeOfStyleArray() > 0) { Style style = styles.getStyleArray(0); faceName = style.getFontArray(side).getName(); } } catch (XmlException e) { DocCharConvertEclipsePlugin.log(IStatus.WARNING, e.getLocalizedMessage(), e); } catch (IOException e) { DocCharConvertEclipsePlugin.log(IStatus.WARNING, e.getLocalizedMessage(), e); } } } if (faceName != null) { FontData fd = new FontData(faceName, font.getFontData()[0].getHeight(), SWT.NORMAL); font = new Font(parent.getDisplay(), fd); mFonts[side] = font; } return font; }
From source file:org.tigris.subversion.subclipse.ui.operations.SourceViewerInformationControl.java
License:Open Source License
/** * Creates a source viewer information control with the given shell as * parent. The given shell styles are applied to the created shell. The * given styles are applied to the created styled text widget. The text * widget will be initialized with the given font. The status field will * contain the given text or be hidden.//from www .j a va 2s .c om * * @param parent the parent shell * @param shellStyle the additional styles for the shell * @param style the additional styles for the styled text widget * @param symbolicFontName the symbolic font name * @param statusFieldText the text to be used in the optional status field * or <code>null</code> if the status field should be hidden */ public SourceViewerInformationControl(Shell parent, int shellStyle, int style, String symbolicFontName, String statusFieldText) { GridLayout layout; GridData gd; fShell = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle); Display display = fShell.getDisplay(); fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); Composite composite = fShell; layout = new GridLayout(1, false); int border = ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER; layout.marginHeight = border; layout.marginWidth = border; composite.setLayout(layout); gd = new GridData(GridData.FILL_HORIZONTAL); composite.setLayoutData(gd); if (statusFieldText != null) { composite = new Composite(composite, SWT.NONE); layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); composite.setLayoutData(gd); composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); } // Source viewer fViewer = new SourceViewer(composite, null, style); fViewer.setEditable(false); // configure hyperlink detectors // fViewer.configure(new SourceViewerConfiguration()); fViewer.configure(new TextSourceViewerConfiguration(EditorsUI.getPreferenceStore()) { protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) { return Collections.singletonMap("org.eclipse.ui.DefaultTextEditor.Subclipse", //$NON-NLS-1$ null); // new IAdaptable() { // public Object getAdapter(Class adapter) { // // return Platform.getAdapterManager().getAdapter(CVSHistoryPage.this, adapter); // return null; // } // }); } }); fText = fViewer.getTextWidget(); gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH); fText.setLayoutData(gd); fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); fText.setFont(JFaceResources.getFont(symbolicFontName)); fText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.character == 0x1B) // ESC fShell.dispose(); } public void keyReleased(KeyEvent e) { } }); // Status field if (statusFieldText != null) { // Horizontal separator line fSeparator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT); fSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Status field label fStatusField = new Label(composite, SWT.RIGHT); fStatusField.setText(statusFieldText); Font font = fStatusField.getFont(); FontData[] fontDatas = font.getFontData(); for (int i = 0; i < fontDatas.length; i++) fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10); fStatusTextFont = new Font(fStatusField.getDisplay(), fontDatas); fStatusField.setFont(fStatusTextFont); GridData gd2 = new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); fStatusField.setLayoutData(gd2); // Regarding the color see bug 41128 fStatusField.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); fStatusField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); } addDisposeListener(this); }
From source file:org.xrepl.ui.console.XreplConsolePage.java
License:Open Source License
private void createOutputViewer() { outputViewer = new TextViewer(page, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); outputViewer.getTextWidget().setLayoutData(new GridData(GridData.FILL_BOTH)); outputViewer.getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); outputViewer.setEditable(false);/*from ww w.j a v a 2 s. c om*/ outputViewer.setDocument(new Document()); }