private Map<Annotation, Position> createAnnotations(
     final Match[] matches, final boolean selected) {
   final Map<Annotation, Position> map = new HashMap<Annotation, Position>();
   for (final Match match : matches) {
     final Annotation annotation =
         new Annotation(selected ? SELECTED_ANNOTATION_TYPE : ANNOTATION_TYPE, false, null);
     final Position position = new Position(match.getOffset(), match.getLength());
     map.put(annotation, position);
   }
   return map;
 }
Пример #2
0
 private StyleRange createRange(Match match, boolean selection) {
   Display display = composite.getDisplay();
   Color fgColor, bgColor;
   if (selection) {
     // Lighten to avoid search selection on system selection
     fgColor = ColorManager.lighten(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT), 50);
     bgColor = ColorManager.getInstance().getSelectedBackgroundColor();
   } else {
     // To avoid white text on light-green background
     fgColor = display.getSystemColor(SWT.COLOR_BLACK);
     bgColor = ColorManager.getInstance().getBackgroundColor();
   }
   return new StyleRange(match.getOffset(), match.getLength(), fgColor, bgColor);
 }
Пример #3
0
 private static Match[] getRangeMatches(final int start, final int length, final Match[] matches) {
   int from = getPosition(start, matches);
   if (from >= matches.length) return Match.EMPTY;
   if (from > 0) {
     final Match border = matches[from - 1];
     if (border.getLength() + border.getOffset() > start) from--;
   }
   final int to = getPosition(start + length, matches) - 1;
   if (from <= to) {
     final Match[] result = new Match[to - from + 1];
     System.arraycopy(matches, from, result, 0, result.length);
     return result;
   }
   return Match.EMPTY;
 }