Search in sources :

Example 1 with AnnotationPreference

use of org.eclipse.ui.texteditor.AnnotationPreference in project eclipse.platform.text by eclipse.

the class TextSourceViewerConfiguration method isShowInOverviewRuler.

/*
	 * @see DefaultAnnotationHover#isIncluded(Annotation)
	 * @since 3.2
	 */
protected boolean isShowInOverviewRuler(Annotation annotation) {
    AnnotationPreference preference = getAnnotationPreference(annotation);
    if (preference == null)
        return true;
    String key = preference.getOverviewRulerPreferenceKey();
    if (key == null || !fPreferenceStore.getBoolean(key))
        return false;
    return true;
}
Also used : AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference)

Example 2 with AnnotationPreference

use of org.eclipse.ui.texteditor.AnnotationPreference in project eclipse.platform.text by eclipse.

the class TextSourceViewerConfiguration method isShownInText.

/*
	 * @see DefaultTextHover#isIncluded(Annotation)
	 * @since 3.2
	 */
protected boolean isShownInText(Annotation annotation) {
    AnnotationPreference preference = getAnnotationPreference(annotation);
    if (preference == null)
        return false;
    String key = preference.getTextPreferenceKey();
    if (key != null) {
        if (!fPreferenceStore.getBoolean(key))
            return false;
    } else {
        key = preference.getHighlightPreferenceKey();
        if (key == null || !fPreferenceStore.getBoolean(key))
            return false;
    }
    return true;
}
Also used : AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference)

Example 3 with AnnotationPreference

use of org.eclipse.ui.texteditor.AnnotationPreference in project eclipse.platform.text by eclipse.

the class AnnotationsConfigurationBlock method createAnnotationTypeListModel.

private ListItem[] createAnnotationTypeListModel(MarkerAnnotationPreferences preferences) {
    ArrayList<ListItem> listModelItems = new ArrayList<>();
    Iterator<AnnotationPreference> e = preferences.getAnnotationPreferences().iterator();
    while (e.hasNext()) {
        AnnotationPreference info = e.next();
        if (info.isIncludeOnPreferencePage()) {
            String label = info.getPreferenceLabel();
            if (containsMoreThanOne(preferences.getAnnotationPreferences().iterator(), label))
                // $NON-NLS-1$//$NON-NLS-2$
                label += " (" + info.getAnnotationType() + ")";
            Image image = getImage(info);
            listModelItems.add(new ListItem(label, image, info.getColorPreferenceKey(), info.getTextPreferenceKey(), info.getOverviewRulerPreferenceKey(), info.getHighlightPreferenceKey(), info.getVerticalRulerPreferenceKey(), info.getTextStylePreferenceKey(), info.getIsGoToNextNavigationTargetKey()));
        }
    }
    Comparator<ListItem> comparator = new Comparator<ListItem>() {

        @Override
        public int compare(ListItem o1, ListItem o2) {
            String label1 = o1.label;
            String label2 = o2.label;
            return Collator.getInstance().compare(label1, label2);
        }
    };
    Collections.sort(listModelItems, comparator);
    ListItem[] items = new ListItem[listModelItems.size()];
    listModelItems.toArray(items);
    return items;
}
Also used : ArrayList(java.util.ArrayList) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference) Image(org.eclipse.swt.graphics.Image) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Comparator(java.util.Comparator)

Example 4 with AnnotationPreference

use of org.eclipse.ui.texteditor.AnnotationPreference in project eclipse.platform.text by eclipse.

the class AnnotationsConfigurationBlock method getImage.

/**
 * Returns the image for the given annotation and the given annotation preferences or
 * <code>null</code> if there is no such image.
 *
 * @param preference the annotation preference
 * @return the image or <code>null</code>
 * @since 3.1
 */
private Image getImage(AnnotationPreference preference) {
    ImageRegistry registry = EditorsPlugin.getDefault().getImageRegistry();
    String annotationType = (String) preference.getAnnotationType();
    if (annotationType == null)
        return null;
    // $NON-NLS-1$
    String customImage = annotationType + "__AnnotationsConfigurationBlock_Image";
    Image image;
    image = registry.get(customImage);
    if (image != null)
        return image;
    image = registry.get(annotationType);
    if (image == null) {
        AnnotationPreference delegatingPreference = EditorsPlugin.getDefault().getAnnotationPreferenceLookup().getAnnotationPreference(annotationType);
        ImageDescriptor descriptor = delegatingPreference.getImageDescriptor();
        if (descriptor != null) {
            registry.put(annotationType, descriptor);
            image = registry.get(annotationType);
        } else {
            String symbolicImageName = preference.getSymbolicImageName();
            if (symbolicImageName != null) {
                String key = DefaultMarkerAnnotationAccess.getSharedImageName(symbolicImageName);
                if (key != null) {
                    ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
                    image = sharedImages.getImage(key);
                }
            }
        }
    }
    if (image == null)
        return null;
    // create custom image
    // square images
    final int SIZE = 16;
    ImageData data = image.getImageData();
    Image copy;
    if (data.height > SIZE || data.width > SIZE) {
        // scale down to icon size
        copy = new Image(Display.getCurrent(), data.scaledTo(SIZE, SIZE));
    } else if (data.height == SIZE && data.width == SIZE) {
        // nothing to scale, return the image
        return image;
    } else {
        // don't scale up, but rather copy into the middle and mark everything else transparent
        ImageData mask = data.getTransparencyMask();
        ImageData resized = new ImageData(SIZE, SIZE, data.depth, data.palette);
        ImageData resizedMask = new ImageData(SIZE, SIZE, mask.depth, mask.palette);
        int xo = Math.max(0, (SIZE - data.width) / 2);
        int yo = Math.max(0, (SIZE - data.height) / 2);
        for (int y = 0; y < SIZE; y++) {
            for (int x = 0; x < SIZE; x++) {
                if (y >= yo && x >= xo && y < yo + data.height && x < xo + data.width) {
                    resized.setPixel(x, y, data.getPixel(x - xo, y - yo));
                    resizedMask.setPixel(x, y, mask.getPixel(x - xo, y - yo));
                }
            }
        }
        copy = new Image(Display.getCurrent(), resized, resizedMask);
    }
    fImageKeys.add(customImage);
    registry.put(customImage, copy);
    return copy;
}
Also used : ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ISharedImages(org.eclipse.ui.ISharedImages) ImageData(org.eclipse.swt.graphics.ImageData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference)

Example 5 with AnnotationPreference

use of org.eclipse.ui.texteditor.AnnotationPreference in project eclipse.platform.text by eclipse.

the class QuickDiffConfigurationBlock method createOverlayStoreKeys.

private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys(MarkerAnnotationPreferences preferences) {
    ArrayList<OverlayKey> overlayKeys = new ArrayList<>();
    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON));
    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER));
    Iterator<AnnotationPreference> e = preferences.getAnnotationPreferences().iterator();
    while (e.hasNext()) {
        AnnotationPreference info = e.next();
        if (// $NON-NLS-1$
        info.getAnnotationType().equals("org.eclipse.ui.workbench.texteditor.quickdiffChange") || // $NON-NLS-1$
        (info.getAnnotationType().equals("org.eclipse.ui.workbench.texteditor.quickdiffAddition")) || // $NON-NLS-1$
        (info.getAnnotationType().equals("org.eclipse.ui.workbench.texteditor.quickdiffDeletion"))) {
            overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, info.getColorPreferenceKey()));
            overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getOverviewRulerPreferenceKey()));
        }
    }
    OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
    overlayKeys.toArray(keys);
    return keys;
}
Also used : OverlayKey(org.eclipse.ui.internal.editors.text.OverlayPreferenceStore.OverlayKey) OverlayKey(org.eclipse.ui.internal.editors.text.OverlayPreferenceStore.OverlayKey) ArrayList(java.util.ArrayList) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference)

Aggregations

AnnotationPreference (org.eclipse.ui.texteditor.AnnotationPreference)32 ArrayList (java.util.ArrayList)6 SourceViewerDecorationSupport (org.eclipse.ui.texteditor.SourceViewerDecorationSupport)5 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 IOverviewRuler (org.eclipse.jface.text.source.IOverviewRuler)4 OverviewRuler (org.eclipse.jface.text.source.OverviewRuler)4 DefaultMarkerAnnotationAccess (org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess)4 MarkerAnnotationPreferences (org.eclipse.ui.texteditor.MarkerAnnotationPreferences)4 Iterator (java.util.Iterator)3 Annotation (org.eclipse.jface.text.source.Annotation)2 AnnotationRulerColumn (org.eclipse.jface.text.source.AnnotationRulerColumn)2 CompositeRuler (org.eclipse.jface.text.source.CompositeRuler)2 IAnnotationAccess (org.eclipse.jface.text.source.IAnnotationAccess)2 ISharedTextColors (org.eclipse.jface.text.source.ISharedTextColors)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)2 Image (org.eclipse.swt.graphics.Image)2 OverlayKey (org.eclipse.ui.internal.editors.text.OverlayPreferenceStore.OverlayKey)2 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)2