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); 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(); }
/** * Create a highlighted range on the previewers document with the given line, column, length and * key. * * @param line the line * @param column the column * @param length the length * @param key the key * @return the highlighted range */ private HighlightedRange createHighlightedRange(int line, int column, int length, String key) { try { IDocument document = fPreviewViewer.getDocument(); int offset = document.getLineOffset(line) + column; return new HighlightedRange(offset, length, key); } catch (BadLocationException x) { CUIPlugin.log(x); } return null; }
@Override public void performDefaults() { super.performDefaults(); fListViewer.refresh(); handleSyntaxColorListSelection(); uninstallSemanticHighlighting(); installSemanticHighlighting(); fPreviewViewer.invalidateTextPresentation(); }