List of usage examples for org.eclipse.jface.resource JFaceResources getFont
public static Font getFont(String symbolicName)
From source file:org.eclipse.cdt.internal.ui.preferences.CEditorColoringConfigurationBlock.java
License:Open Source License
private Control createPreviewer(Composite parent) { IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore(); IPreferenceStore store = new ChainedPreferenceStore( new IPreferenceStore[] { getPreferenceStore(), generalTextStore }); fPreviewViewer = new CSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store);//from w w w . j a v a 2s . c om SimpleCSourceViewerConfiguration configuration = new SimpleCSourceViewerConfiguration(fColorManager, store, null, ICPartitions.C_PARTITIONING, false); fPreviewViewer.configure(configuration); Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); fPreviewViewer.getTextWidget().setFont(font); CSourcePreviewerUpdater.registerPreviewer(fPreviewViewer, configuration, store); fPreviewViewer.setEditable(false); String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$ IDocument document = new Document(content); CUIPlugin.getDefault().getTextTools().setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null); fPreviewViewer.setDocument(document); installSemanticHighlighting(); return fPreviewViewer.getControl(); }
From source file:org.eclipse.cdt.internal.ui.preferences.CodeTemplateBlock.java
License:Open Source License
private SourceViewer createViewer(Composite parent, int nColumns) { Label label = new Label(parent, SWT.NONE); label.setText(PreferencesMessages.CodeTemplateBlock_preview); GridData data = new GridData(); data.horizontalSpan = nColumns;/*from w w w.j a va 2s .com*/ label.setLayoutData(data); IDocument document = new Document(); CTextTools tools = CUIPlugin.getDefault().getTextTools(); tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null); IPreferenceStore store = CUIPlugin.getDefault().getCombinedPreferenceStore(); SourceViewer viewer = new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store); CodeTemplateSourceViewerConfiguration configuration = new CodeTemplateSourceViewerConfiguration( tools.getColorManager(), store, null, fTemplateProcessor); viewer.configure(configuration); viewer.setEditable(false); viewer.setDocument(document); Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); viewer.getTextWidget().setFont(font); new CSourcePreviewerUpdater(viewer, configuration, store); Control control = viewer.getControl(); data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); data.horizontalSpan = nColumns; data.heightHint = fPixelConverter.convertHeightInCharsToPixels(5); control.setLayoutData(data); return viewer; }
From source file:org.eclipse.cdt.internal.ui.preferences.CSourcePreviewerUpdater.java
License:Open Source License
/** * Registers a source preview updater for the given viewer, configuration and preference store. * * @param viewer the viewer/* w w w. j a v a2s.com*/ * @param configuration the configuration * @param preferenceStore the preference store */ static public void registerPreviewer(final SourceViewer viewer, final CSourceViewerConfiguration configuration, final IPreferenceStore preferenceStore) { Assert.isNotNull(viewer); Assert.isNotNull(configuration); Assert.isNotNull(preferenceStore); final IPropertyChangeListener fontChangeListener = new IPropertyChangeListener() { /* * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) */ @Override public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(PreferenceConstants.EDITOR_TEXT_FONT)) { Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); viewer.getTextWidget().setFont(font); } } }; final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { /* * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) */ @Override public void propertyChange(PropertyChangeEvent event) { if (configuration.affectsTextPresentation(event)) { configuration.handlePropertyChangeEvent(event); viewer.invalidateTextPresentation(); } } }; viewer.getTextWidget().addDisposeListener(new DisposeListener() { /* * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) */ @Override public void widgetDisposed(DisposeEvent e) { preferenceStore.removePropertyChangeListener(propertyChangeListener); JFaceResources.getFontRegistry().removeListener(fontChangeListener); } }); JFaceResources.getFontRegistry().addListener(fontChangeListener); preferenceStore.addPropertyChangeListener(propertyChangeListener); }
From source file:org.eclipse.cdt.internal.ui.preferences.EditTemplateDialog.java
License:Open Source License
private SourceViewer createEditor(Composite parent) { String prefix = getPrefix();/* ww w.jav a2 s . c o m*/ IDocument document = new Document(prefix + fTemplate.getPattern()); CTextTools tools = CUIPlugin.getDefault().getTextTools(); tools.setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null); IPreferenceStore store = CUIPlugin.getDefault().getCombinedPreferenceStore(); SourceViewer viewer = new CSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store); CodeTemplateSourceViewerConfiguration configuration = new CodeTemplateSourceViewerConfiguration( tools.getColorManager(), store, null, fTemplateProcessor); viewer.configure(configuration); viewer.setEditable(true); viewer.setDocument(document, prefix.length(), document.getLength() - prefix.length()); Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); viewer.getTextWidget().setFont(font); new CSourcePreviewerUpdater(viewer, configuration, store); int nLines = document.getNumberOfLines(); if (nLines < 5) { nLines = 5; } else if (nLines > 12) { nLines = 12; } Control control = viewer.getControl(); GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = convertWidthInCharsToPixels(80); data.heightHint = convertHeightInCharsToPixels(nLines); control.setLayoutData(data); viewer.addTextListener(new ITextListener() { @Override public void textChanged(TextEvent event) { if (event.getDocumentEvent() != null) doSourceChanged(event.getDocumentEvent().getDocument()); } }); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { updateSelectionDependentActions(); } }); return viewer; }
From source file:org.eclipse.cdt.internal.ui.preferences.formatter.CPreview.java
License:Open Source License
/** * Create a new C preview/*from w w w. j a va2s . c o m*/ * @param workingValues * @param parent */ public CPreview(Map<String, String> workingValues, Composite parent) { CTextTools tools = CUIPlugin.getDefault().getTextTools(); fPreviewDocument = new Document(); fWorkingValues = workingValues; tools.setupCDocumentPartitioner(fPreviewDocument, ICPartitions.C_PARTITIONING, null); PreferenceStore prioritizedSettings = new PreferenceStore(); IPreferenceStore[] chain = { prioritizedSettings, CUIPlugin.getDefault().getCombinedPreferenceStore() }; fPreferenceStore = new ChainedPreferenceStore(chain); fSourceViewer = new CSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore); fViewerConfiguration = new SimpleCSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, ICPartitions.C_PARTITIONING, true); fSourceViewer.configure(fViewerConfiguration); fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); fMarginPainter = new MarginPainter(fSourceViewer); final RGB rgb = PreferenceConverter.getColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR); fMarginPainter.setMarginRulerColor(tools.getColorManager().getColor(rgb)); fSourceViewer.addPainter(fMarginPainter); new CSourcePreviewerUpdater(); fSourceViewer.setDocument(fPreviewDocument); }
From source file:org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionInputPage.java
License:Open Source License
private void createSignaturePreview(Composite composite, RowLayouter layouter) { Label previewLabel = new Label(composite, SWT.NONE); previewLabel.setText(Messages.ExtractFunctionInputPage_signature_preview); layouter.perform(previewLabel);/*from w w w.ja v a 2s . com*/ IPreferenceStore store = CUIPlugin.getDefault().getCombinedPreferenceStore(); signaturePreview = new CSourceViewer(composite, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP /*| SWT.BORDER*/, store); signaturePreview.configure(new CSourceViewerConfiguration( CUIPlugin.getDefault().getTextTools().getColorManager(), store, null, null)); signaturePreview.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); signaturePreview.adaptBackgroundColor(composite); signaturePreview.setDocument(signaturePreviewDocument); signaturePreview.setEditable(false); // Layouting problems with wrapped text: see http://bugs.eclipse.org/bugs/show_bug.cgi?id=9866 Control signaturePreviewControl = signaturePreview.getControl(); PixelConverter pixelConverter = new PixelConverter(signaturePreviewControl); GridData gdata = new GridData(GridData.FILL_BOTH); gdata.widthHint = pixelConverter.convertWidthInCharsToPixels(50); gdata.heightHint = pixelConverter.convertHeightInCharsToPixels(3); signaturePreviewControl.setLayoutData(gdata); layouter.perform(signaturePreviewControl); }
From source file:org.eclipse.cdt.internal.ui.text.AbstractCompareViewerInformationControl.java
License:Open Source License
@Override public Point computeSizeConstraints(int widthInChars, int heightInChars) { Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); GC gc = new GC(fCompareViewerControl); gc.setFont(font);/*from w w w. jav a2 s .c o m*/ int width = gc.getFontMetrics().getAverageCharWidth(); int height = gc.getFontMetrics().getHeight(); gc.dispose(); return new Point(widthInChars * width, heightInChars * height); }
From source file:org.eclipse.cdt.internal.ui.text.AbstractSourceViewerInformationControl.java
License:Open Source License
protected final ISourceViewer createSourceViewer(Composite parent, int style) { IPreferenceStore store = CUIPlugin.getDefault().getCombinedPreferenceStore(); SourceViewer sourceViewer = new CSourceViewer(parent, null, null, false, style, store); CTextTools tools = CUIPlugin.getDefault().getTextTools(); sourceViewer.configure(new SimpleCSourceViewerConfiguration(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING, false)); sourceViewer.setEditable(false);/*w w w . j a va 2s. com*/ fText = sourceViewer.getTextWidget(); GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH); fText.setLayoutData(gd); initializeColors(); fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); fText.setBackground(fBackgroundColor); fTextFont = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); fText.setFont(fTextFont); return sourceViewer; }
From source file:org.eclipse.cdt.internal.ui.text.c.hover.CMacroCompareViewer.java
License:Open Source License
@Override protected void configureTextViewer(TextViewer textViewer) { super.configureTextViewer(textViewer); // hack: gain access to text viewers switch (fViewerIndex++) { case 0://from w w w . jav a 2 s . c o m fTopViewer = textViewer; fTopViewer.getTextWidget().setFont(JFaceResources.getFont(CMergeViewer.class.getName())); break; case 1: fLeftViewer = textViewer; fLeftViewer.getTextWidget().setFont(JFaceResources.getFont(CMergeViewer.class.getName())); fLeftViewer.addTextPresentationListener(fLeftHighlighter); break; case 2: fRightViewer = textViewer; fRightViewer.getTextWidget().setFont(JFaceResources.getFont(CMergeViewer.class.getName())); fRightViewer.addTextPresentationListener(fRightHighlighter); } }
From source file:org.eclipse.cdt.internal.ui.text.c.hover.CMacroExpansionExplorationControl.java
License:Open Source License
protected ISourceViewer createSourceViewer(Composite parent, int style) { IPreferenceStore store = CUIPlugin.getDefault().getCombinedPreferenceStore(); SourceViewer sourceViewer = new CSourceViewer(parent, null, null, false, style, store); CTextTools tools = CUIPlugin.getDefault().getTextTools(); sourceViewer.configure(new SimpleCSourceViewerConfiguration(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING, false)); sourceViewer.setEditable(false);//from ww w. ja va2 s . com fMacroText = sourceViewer.getTextWidget(); Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); fMacroText.setFont(font); GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH); gd.heightHint = fMacroText.getLineHeight() * 2; fMacroText.setLayoutData(gd); final Document doc = new Document(); CUIPlugin.getDefault().getTextTools().setupCDocument(doc); sourceViewer.setDocument(doc); return sourceViewer; }