下面列出了怎么用org.eclipse.jface.text.MarginPainter的API类实例代码及写法,或者点击链接到github查看源代码。
public XtendFormatterPreview forEmbeddedEditor(EmbeddedEditor editorHandle) {
if (this.editorHandle != null) {
throw new IllegalStateException("This formatter preview is already binded to an embedet editor");
}
this.editorHandle = editorHandle;
this.modelAccess = editorHandle.createPartialEditor();
this.marginPainter = new MarginPainter(editorHandle.getViewer());
final RGB rgb = PreferenceConverter.getColor(preferenceStoreAccess.getPreferenceStore(),
AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR);
marginPainter.setMarginRulerColor(EditorUtils.colorFromRGB(rgb));
editorHandle.getViewer().addPainter(marginPainter);
return this;
}
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);
}
private void createMarginPainter(TextViewer commitMessageTextViewer) {
MarginPainter marginPainter = new MarginPainter(commitMessageTextViewer);
marginPainter.setMarginRulerColumn(MAX_COMMIT_MESSAGE_LINE_LENGTH); //maximum recommended commit message line length is 72
marginPainter.setMarginRulerColor(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_GRAY));
commitMessageTextViewer.addPainter(marginPainter);
}
public void turnOnMarginPainter() {
fMarginPainter= new MarginPainter(this);
fMarginPainter.setMarginRulerStyle(SWT.LINE_DOT);
fMarginPainter.setMarginRulerColor(new Color(Display.getDefault(), 0,0,0));
this.addPainter(fMarginPainter);
}