List of usage examples for org.eclipse.jface.resource JFaceResources getFont
public static Font getFont(String symbolicName)
From source file:ccw.editors.clojure.hovers.CCWBrowserInformationControl.java
License:Open Source License
private void createTestWidget() { fTestWidget = new TextLayout(getShell().getDisplay()); // Initialize fonts Font font = JFaceResources .getFont(fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName); fTestWidget.setFont(font);/*from w w w.j a v a2 s .c o m*/ fTestWidget.setWidth(-1); // Compute and set tab width fTestWidget.setText(" "); //$NON-NLS-1$ int tabWidth = fTestWidget.getBounds().width; fTestWidget.setTabs(new int[] { tabWidth }); fTestWidget.setText(""); //$NON-NLS-1$ }
From source file:ccw.editors.clojure.hovers.CCWBrowserInformationControl.java
License:Open Source License
@Override public Point computeSizeHint() { // AR - this hack is necessary because BrowserInformationControl does not take into consideration // <pre> tags during its computation of the displayed widget Point newSizeHint = super.computeSizeHint(); BrowserInformationControlInput input = getInput(); if (input != null) { Document doc = Jsoup.parse(input.getHtml()); Element styleElement = doc.select("style").first(); int preCssPoints = -1; Matcher preCssPointsMatcher = Pattern.compile("pre.*[{].*font-size:[ ]+(\\d+)p") .matcher(styleElement.html()); if (preCssPointsMatcher.find()) { try { preCssPoints = Integer.valueOf(preCssPointsMatcher.group(1)); CCWPlugin.getTracer().trace(TraceOptions.HOVER_SUPPORT, "CSS <pre> tag points found: " + preCssPoints); } catch (NumberFormatException ex) { CCWPlugin.getTracer().trace(TraceOptions.HOVER_SUPPORT, "CSS <pre> NumberFormatException, cannot read from it."); }/*w w w . ja v a 2s . c o m*/ } // AR - Given that we are in *hack-mode*, for the height we will first subtract // the estimate calculated with the used font and then sum the one obtained using // the Monospace font. Font originalFont = JFaceResources.getFont(fSymbolicFontName); FontData[] monoFd = SWTFontUtils.getMonospacedFont().getFontData(); assertNotNull(monoFd); Font monospaceFont; if (preCssPoints != -1) { monospaceFont = new Font(getShell().getDisplay(), SWTFontUtils.newHeightFontData(monoFd, preCssPoints)); } else { monospaceFont = new Font(getShell().getDisplay(), monoFd); } Elements preElements = doc.getElementsByTag("pre"); for (Element el : preElements) { String txt = el.text(); // AR - Estimate with original font Point originalSize = estimateSizeHint(originalFont, txt); // AR - Jsoup flattens all the tag's texts. Point monospaceSize = estimateSizeHint(monospaceFont, txt); // AR - Canonical "+ something" as in BrowserInformationControl.computeSizeHint newSizeHint = new Point(Math.max(newSizeHint.x, monospaceSize.x), Math.max(newSizeHint.y, newSizeHint.y - originalSize.y + monospaceSize.y)); } monospaceFont.dispose(); // AR - Considering <p> as occuping more than nothing in height Elements pElements = doc.getElementsByTag("p"); // AR - Trim for taking into consideration the scrollbars Rectangle trim = computeTrim(); // AR - final sum newSizeHint = new Point(newSizeHint.x + trim.width, newSizeHint.y + trim.height + pElements.size() * 6); } return newSizeHint; }
From source file:ccw.preferences.SyntaxColoringPreferencePage.java
License:Open Source License
private Control createPreviewer(Composite parent) { IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore(); IPreferenceStore store = new ChainedPreferenceStore( new IPreferenceStore[] { fOverlayStore, generalTextStore }); fPreviewViewer = new ClojureSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store, null) { public void setStatusLineErrorMessage(String you_need_a_running_repl) { // Do nothing }/*from w w w . j a v a 2s.co m*/ }; ClojureSourceViewerConfiguration configuration = new ClojureSourceViewerConfiguration(store, fPreviewViewer); fPreviewViewer.configure(configuration); fPreviewViewer.initializeViewerColors(); Font font = JFaceResources.getFont(org.eclipse.jdt.ui.PreferenceConstants.EDITOR_TEXT_FONT); fPreviewViewer.getTextWidget().setFont(font); IDocument document = new Document(PREVIEW_SOURCE); IDocumentPartitioner partitioner = new ClojurePartitioner(new ClojurePartitionScanner(), ClojurePartitionScanner.CLOJURE_CONTENT_TYPES); Map<String, IDocumentPartitioner> m = new HashMap<String, IDocumentPartitioner>(); m.put(ClojurePartitionScanner.CLOJURE_PARTITIONING, partitioner); TextUtilities.addDocumentPartitioners(document, m); fPreviewViewer.setDocument(document); return fPreviewViewer.getControl(); }
From source file:ch.netcetera.eclipse.workspaceconfig.ui.dialog.WorkspacePrefercensRecorderResultDialog.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . j a va 2 s . co m protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 10; layout.marginWidth = 15; layout.numColumns = 2; composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setFont(parent.getFont()); Text resultText = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); GridData nameTextGridData = new GridData(GridData.FILL_BOTH); nameTextGridData.minimumWidth = 300; nameTextGridData.minimumHeight = 200; nameTextGridData.heightHint = 300; resultText.setLayoutData(nameTextGridData); resultText.setText(result); resultText.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); resultText.setText(this.result); return composite; }
From source file:com.amalto.workbench.widgets.xmlviewer.XMLSourceViewer.java
License:Open Source License
/** * DOC hbhong Comment method "updateFont". */ private void updateFont() { getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); }
From source file:com.amazonaws.eclipse.lambda.project.wizard.page.NewLambdaJavaFunctionProjectWizardPageOne.java
License:Open Source License
private void createHandlerSourcePreview(Composite composite) { newFillingLabel(composite, "Preview:", 1); IPreferenceStore javaPluginPrefStore = JavaPlugin.getDefault().getCombinedPreferenceStore(); sourcePreview = new JavaSourceViewer(composite, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, javaPluginPrefStore);/*from ww w.j a v a2 s .c o m*/ sourcePreview.setEditable(false); sourcePreview.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); // TODO: investigate why Java source coloring is not working // org.eclipse.jdt.internal.ui.preferences.formatter.JavaPreview JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools(); SimpleJavaSourceViewerConfiguration sourceConfig = new SimpleJavaSourceViewerConfiguration( tools.getColorManager(), javaPluginPrefStore, null, IJavaPartitions.JAVA_PARTITIONING, true); sourcePreview.configure(sourceConfig); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); gridData.horizontalSpan = 1; gridData.heightHint = 50; sourcePreview.getTextWidget().setLayoutData(gridData); sourcePreviewDocument = new Document(""); sourcePreview.setDocument(sourcePreviewDocument); }
From source file:com.amazonaws.eclipse.lambda.project.wizard.util.LambdaFunctionGroup.java
License:Open Source License
public void createHandlerSourcePreview() { newFillingLabel(group, "Preview:", 1); sourcePreviewDocument = new Document(""); IPreferenceStore javaPluginPrefStore = JavaPlugin.getDefault().getCombinedPreferenceStore(); sourcePreview = new JavaSourceViewer(group, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, javaPluginPrefStore);/*from ww w . ja v a 2 s .c om*/ sourcePreview.setEditable(false); sourcePreview.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); // Setting up Java Syntax Highlight JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools(); tools.setupJavaDocumentPartitioner(sourcePreviewDocument, IJavaPartitions.JAVA_PARTITIONING); SimpleJavaSourceViewerConfiguration sourceConfig = new SimpleJavaSourceViewerConfiguration( tools.getColorManager(), javaPluginPrefStore, null, IJavaPartitions.JAVA_PARTITIONING, true); sourcePreview.configure(sourceConfig); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); gridData.horizontalSpan = 1; gridData.heightHint = 50; sourcePreview.getTextWidget().setLayoutData(gridData); sourcePreview.setDocument(sourcePreviewDocument); linkPreviewWithHandlerConfigInput(); }
From source file:com.apicloud.navigator.composite.ThemeUIComposite.java
License:Open Source License
private void setFont(String fontId, FontData[] data) { String fdString = PreferenceConverter.getStoredRepresentation(data); Font existing = JFaceResources.getFont(fontId); String existingString = ""; if (!(existing.isDisposed())) { existingString = PreferenceConverter.getStoredRepresentation(existing.getFontData()); }/* w ww . j a v a 2s. c o m*/ if (existingString.equals(fdString)) { return; } JFaceResources.getFontRegistry().put(fontId, data); ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(); String key = ThemeElementHelper.createPreferenceKey(currentTheme, fontId); IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); store.setValue(key, fdString); }
From source file:com.aptana.formatter.ui.preferences.ScriptSourcePreviewerUpdater.java
License:Open Source License
/** * Creates a script source preview updater for the given viewer, configuration and preference store. * /*from w ww . java2 s . c o m*/ * @param viewer * the viewer * @param configuration * the configuration * @param preferenceStore * the preference store */ public ScriptSourcePreviewerUpdater(final SourceViewer viewer, final SourceViewerConfiguration configuration, final IPreferenceStore preferenceStore) { Assert.isNotNull(viewer); Assert.isNotNull(configuration); Assert.isNotNull(preferenceStore); final IPropertyChangeListener fontChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { final String fontKey = JFaceResources.TEXT_FONT; if (fontKey.equals(event.getProperty())) { final Font font = JFaceResources.getFont(fontKey); viewer.getTextWidget().setFont(font); } } }; final IPreferenceChangeListener themeListener = new IPreferenceChangeListener() { public void preferenceChange(PreferenceChangeEvent event) { if (event.getKey().equals(IThemeManager.THEME_CHANGED)) { ColorManager colorManager = ThemePlugin.getDefault().getColorManager(); IThemeManager themeManager = ThemePlugin.getDefault().getThemeManager(); Color color = colorManager.getColor(themeManager.getCurrentTheme().getBackground()); StyledText styledText = viewer.getTextWidget(); styledText.setBackground(color); } } }; // Listen to theme changes final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { // if (configuration.affectsTextPresentation(event)) { // configuration.handlePropertyChangeEvent(event); viewer.invalidateTextPresentation(); // } } }; viewer.getTextWidget().addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { preferenceStore.removePropertyChangeListener(propertyChangeListener); JFaceResources.getFontRegistry().removeListener(fontChangeListener); if (themeListener != null) { EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID) .removePreferenceChangeListener(themeListener); } } }); JFaceResources.getFontRegistry().addListener(fontChangeListener); preferenceStore.addPropertyChangeListener(propertyChangeListener); EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID).addPreferenceChangeListener(themeListener); }
From source file:com.aptana.ide.ui.editors.preferences.formatter.Preview.java
License:Open Source License
/** * Create a new Java preview//from ww w . ja v a2s . c o m * * @param workingValues * @param parent * @param language * @param pstore */ public Preview(Map workingValues, Composite parent, String language, IPreferenceStore pstore) { parser = LanguageRegistry.createParser(language); formatter = LanguageRegistry.getCodeFormatter(language); parseState = parser.createParseState(null); fPreviewDocument = new Document(); fWorkingValues = workingValues; languageColorizer = LanguageRegistry.getLanguageColorizer(language); IPreferenceStore prioritizedSettings = UnifiedEditorsPlugin.getDefault().getPreferenceStore(); fPreferenceStore = prioritizedSettings; fSourceViewer = new TextViewer(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); fSourceViewer.setDocument(fPreviewDocument); fSourceViewer.getTextWidget().setBackground(languageColorizer.getBackground()); fSourceViewer.getTextWidget().addLineStyleListener(new LineStyleListener() { public void lineGetStyle(LineStyleEvent e) { { if (parseState == null) { return; } LexemeList lexemeList = parseState.getLexemeList(); if (lexemeList == null) { IdeLog.logError(UnifiedEditorsPlugin.getDefault(), Messages.UnifiedEditor_LexemeListIsNull); return; } int orgOffset = e.lineOffset; int offset = orgOffset; int extra = 0; int lineLength = e.lineText.length(); int maxLineLength = lineLength; Lexeme[] lexemes = null; synchronized (lexemeList) { int startingIndex = lexemeList.getLexemeCeilingIndex(offset); int endingIndex = lexemeList.getLexemeFloorIndex(offset + maxLineLength); if (startingIndex == -1 && endingIndex != -1) { startingIndex = endingIndex; } if (endingIndex == -1 && startingIndex != -1) { endingIndex = startingIndex; } if (startingIndex != -1 && endingIndex != -1) { lexemes = lexemeList.cloneRange(startingIndex, endingIndex); } } if (lexemes != null) { Vector styles = new Vector(); colorizer.createStyles(parseState, styles, lexemes, true); StyleRange[] styleResults = (StyleRange[]) styles.toArray(new StyleRange[] {}); // move styles back to actual widget offsets in case of // folding if (extra > 0) { for (int i = 0; i < styleResults.length; i++) { StyleRange range = styleResults[i]; range.start -= extra; } } e.styles = styleResults; } } }; }); // fSourceViewer.configure(fViewerConfiguration); fSourceViewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.jface.textfont")); //$NON-NLS-1$ new JavaSourcePreviewerUpdater(); updateWidget(); }