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; }
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); }
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; }
protected void updateCell(ItemCell cell) { List<StyleRange> list = new ArrayList<StyleRange>(); boolean selectionFound = false; if (cellToMatches != null) { List<Match> matches = cellToMatches.get(cell); if (matches != null) { for (Match match : matches) { boolean sel = match.equals(selection); selectionFound = selectionFound | sel; StyleRange range = createRange(match, sel); list.add(range); } } } if (!selectionFound && selection != null) { ItemCell selCell = (ItemCell) selection.getBlock(); if (selCell.equals(cell)) { list.add(createRange(selection, true)); } } StyleRange[] ranges = list.toArray(new StyleRange[list.size()]); decorator.setStyles(cell, ranges); }
protected ItemCell getCell(Match match) { return (ItemCell) match.getBlock(); }