/** * Create margin painter and add to source viewer */ protected void createMarginPainter() { MarginPainter marginPainter = new MarginPainter(sourceViewer); marginPainter.setMarginRulerColumn(MAX_LINE_WIDTH); marginPainter.setMarginRulerColor(Display.getDefault().getSystemColor( SWT.COLOR_GRAY)); sourceViewer.addPainter(marginPainter); }
public JavaPreview(Map<String, String> workingValues, Composite parent) { JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools(); fPreviewDocument= new Document(); fWorkingValues= workingValues; tools.setupJavaDocumentPartitioner( fPreviewDocument, IJavaPartitions.JAVA_PARTITIONING); PreferenceStore prioritizedSettings= new PreferenceStore(); HashMap<String, String> complianceOptions= new HashMap<String, String>(); JavaModelUtil.setComplianceOptions(complianceOptions, JavaModelUtil.VERSION_LATEST); for (Entry<String, String> complianceOption : complianceOptions.entrySet()) { prioritizedSettings.setValue(complianceOption.getKey(), complianceOption.getValue()); } IPreferenceStore[] chain= { prioritizedSettings, JavaPlugin.getDefault().getCombinedPreferenceStore() }; fPreferenceStore= new ChainedPreferenceStore(chain); fSourceViewer= new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore); fSourceViewer.setEditable(false); Cursor arrowCursor= fSourceViewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW); fSourceViewer.getTextWidget().setCursor(arrowCursor); // Don't set caret to 'null' as this causes https://bugs.eclipse.org/293263 // fSourceViewer.getTextWidget().setCaret(null); fViewerConfiguration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, IJavaPartitions.JAVA_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 JavaSourcePreviewerUpdater(); fSourceViewer.setDocument(fPreviewDocument); }