下面列出了怎么用org.eclipse.ui.texteditor.MarkerAnnotationPreferences的API类实例代码及写法,或者点击链接到github查看源代码。
public BookmarkColumn() {
super();
fDelegate = new BookmarkRulerColumn();
// some initialization (is it required? hz..) :
new MarkerAnnotationPreferences().getAnnotationPreferences();
}
/**
* Creates decoration support for the sourceViewer. code is entirely copied from
* {@link XtextEditor} and its super class {@link AbstractDecoratedTextEditor}.
*
*/
protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
MarkerAnnotationPreferences annotationPreferences = new MarkerAnnotationPreferences();
List<AnnotationPreference> prefs = annotationPreferences.getAnnotationPreferences();
for (AnnotationPreference annotationPreference : prefs) {
support.setAnnotationPreference(annotationPreference);
}
support.setCharacterPairMatcher(getCharacterPairMatcher());
support.setMatchingCharacterPainterPreferenceKeys(BracketMatchingPreferencesInitializer.IS_ACTIVE_KEY,
BracketMatchingPreferencesInitializer.COLOR_KEY);
support.install(getPreferenceStoreAccess().getPreferenceStore());
}
private void setAnnotationColorsToMatchTheme(Theme theme)
{
IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode("org.eclipse.ui.editors"); //$NON-NLS-1$
if (!theme.hasEntry("override.searchResultIndication")) //$NON-NLS-1$
{
prefs.put("searchResultIndicationColor", toString(theme.getSearchResultColor())); //$NON-NLS-1$
}
// TODO Use markup.changed bg color for "decoration color" in Prefs>General>Appearance>Colors and Fonts
// TODO Move this stuff over to theme change listeners in the XML/HTML/Ruby editor plugins?
if (!theme.hasEntry("override.xmlTagPairOccurrenceIndication")) //$NON-NLS-1$
{
prefs.putBoolean("xmlTagPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
prefs.putBoolean("xmlTagPairOccurrenceIndication", true); //$NON-NLS-1$
prefs.put("xmlTagPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
prefs.put("xmlTagPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
}
if (!theme.hasEntry("override.htmlTagPairOccurrenceIndication")) //$NON-NLS-1$
{
prefs.putBoolean("htmlTagPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
prefs.putBoolean("htmlTagPairOccurrenceIndication", true); //$NON-NLS-1$
prefs.put("htmlTagPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
prefs.put("htmlTagPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
}
if (!theme.hasEntry("override.rubyBlockPairOccurrenceIndication")) //$NON-NLS-1$
{
prefs.putBoolean("rubyBlockPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
prefs.putBoolean("rubyBlockPairOccurrenceIndication", true); //$NON-NLS-1$
prefs.put("rubyBlockPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
prefs.put("rubyBlockPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
}
// PyDev Occurrences (com.python.pydev.occurrences)
// Override them if pydev is set to use our themes
if (Platform.getPreferencesService().getBoolean("org.python.pydev.red_core", "PYDEV_USE_APTANA_THEMES", true, //$NON-NLS-1$ //$NON-NLS-2$
null))
{
if (!theme.hasEntry("override.pydevOccurrenceIndication")) //$NON-NLS-1$
{
MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
AnnotationPreference pydevOccurPref = null;
for (Object obj : preferences.getAnnotationPreferences())
{
AnnotationPreference pref = (AnnotationPreference) obj;
Object type = pref.getAnnotationType();
if ("com.python.pydev.occurrences".equals(type)) //$NON-NLS-1$
{
pydevOccurPref = pref;
}
}
if (pydevOccurPref != null)
{
if (pydevOccurPref.getTextStylePreferenceKey() != null)
{
// Now that pydev supports text style, use the box style and don't highlight.
prefs.putBoolean("pydevOccurrenceHighlighting", false); //$NON-NLS-1$
prefs.putBoolean("pydevOccurrenceIndication", true); //$NON-NLS-1$
prefs.put("pydevOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
prefs.put("pydevOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
}
else
{
// Must use highlighting, since we're against older pydev that had no text style
prefs.putBoolean("pydevOccurrenceHighlighting", true); //$NON-NLS-1$
prefs.putBoolean("pydevOccurrenceIndication", true); //$NON-NLS-1$
prefs.put("pydevOccurrenceIndicationColor", toString(theme.getSearchResultColor())); //$NON-NLS-1$
}
}
}
}
try
{
prefs.flush();
}
catch (BackingStoreException e)
{
IdeLog.logError(ThemePlugin.getDefault(), e);
}
}