mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
find/replace: current occurrence highlighting. added new EffectType: ROUNDED_BOX.
This commit is contained in:
@@ -137,10 +137,9 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
Editor editor = mySearchResults.getEditor();
|
||||
if (cursor != null) {
|
||||
ArrayList<RangeHighlighter> dummy = new ArrayList<RangeHighlighter>();
|
||||
highlightRange(cursor.getPrimaryRange(), new TextAttributes(null, null, null, null, 0), dummy);
|
||||
highlightRange(cursor.getPrimaryRange(), new TextAttributes(null, null, Color.BLACK, EffectType.ROUNDED_BOX, 0), dummy);
|
||||
if (!dummy.isEmpty()) {
|
||||
myCursorHighlighter = dummy.get(0);
|
||||
myCursorHighlighter.setCustomRenderer(new CursorRenderer());
|
||||
}
|
||||
|
||||
if (!SearchResults.insideVisibleArea(editor, cursor.getPrimaryRange()) && scroll) {
|
||||
@@ -263,37 +262,6 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class CursorRenderer implements CustomHighlighterRenderer {
|
||||
@Override
|
||||
public void paint(Editor editor, RangeHighlighter highlighter, Graphics g) {
|
||||
Document document = editor.getDocument();
|
||||
int offset = highlighter.getStartOffset();
|
||||
while (offset < highlighter.getEndOffset()) {
|
||||
int line = document.getLineNumber(offset);
|
||||
int newOffset = document.getLineEndOffset(line);
|
||||
newOffset = Math.min(highlighter.getEndOffset(), newOffset);
|
||||
drawSegment(editor, new TextRange(offset, newOffset), g);
|
||||
offset = newOffset+1;
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawSegment(Editor editor, Segment highlighter, Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
VisualPosition startVp = editor.offsetToVisualPosition(highlighter.getStartOffset());
|
||||
VisualPosition endVp = editor.offsetToVisualPosition(highlighter.getEndOffset());
|
||||
Point start = editor.visualPositionToXY(startVp);
|
||||
Point end = editor.visualPositionToXY(endVp);
|
||||
g2d.setColor(new Color(50, 50, 50));
|
||||
g2d.translate(0, start.y - 4);
|
||||
Color c1 = new Color(220, 200, 130);
|
||||
Color c2 = new Color(220, 170, 30);
|
||||
int endX = start.x != end.x ? end.x : end.x + 2;
|
||||
UIUtil.drawSearchMatch(g2d, start.x - 1, endX + 1, editor.getLineHeight() + 2 * 4, c1, c2);
|
||||
g2d.translate(0, -start.y + 4);
|
||||
}
|
||||
}
|
||||
|
||||
private class ReplacementBalloonPositionTracker extends PositionTracker<Balloon> {
|
||||
private final Editor myEditor;
|
||||
private final int myStartOffset;
|
||||
|
||||
+3
@@ -133,6 +133,9 @@ public class LivePreviewControllerBase implements LivePreview.Delegate, FindUtil
|
||||
|
||||
@Override
|
||||
public String getStringToReplace(Editor editor, LiveOccurrence liveOccurrence) {
|
||||
if (liveOccurrence == null) {
|
||||
return null;
|
||||
}
|
||||
String foundString = editor.getDocument().getText(liveOccurrence.getPrimaryRange());
|
||||
String documentText = editor.getDocument().getText();
|
||||
FindModel currentModel = mySearchResults.getFindModel();
|
||||
|
||||
@@ -22,5 +22,6 @@ public enum EffectType {
|
||||
STRIKEOUT,
|
||||
BOLD_LINE_UNDERSCORE,
|
||||
BOLD_DOTTED_LINE,
|
||||
SEARCH_MATCH
|
||||
SEARCH_MATCH,
|
||||
ROUNDED_BOX
|
||||
}
|
||||
|
||||
@@ -40,13 +40,13 @@ public class BorderEffect {
|
||||
EffectType effectType = attributes1.getEffectType();
|
||||
return effectColor != null
|
||||
&& effectColor.equals(attributes2.getEffectColor())
|
||||
&& EffectType.BOXED == effectType &&
|
||||
&& (EffectType.BOXED == effectType || EffectType.ROUNDED_BOX == effectType) &&
|
||||
effectType == attributes2.getEffectType();
|
||||
}
|
||||
};
|
||||
private static final Condition<TextAttributes> BOX_FILTER = new Condition<TextAttributes>() {
|
||||
public boolean value(TextAttributes attributes) {
|
||||
return attributes.getEffectColor() != null && attributes.getEffectType() == EffectType.BOXED;
|
||||
return isBorder(attributes);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,17 +78,18 @@ public class BorderEffect {
|
||||
private static boolean isBorder(TextAttributes textAttributes) {
|
||||
return textAttributes != null &&
|
||||
textAttributes.getEffectColor() != null &&
|
||||
EffectType.BOXED == textAttributes.getEffectType();
|
||||
(EffectType.BOXED == textAttributes.getEffectType() || EffectType.ROUNDED_BOX == textAttributes.getEffectType());
|
||||
}
|
||||
|
||||
private void paintBorder(RangeHighlighterEx rangeHighlighter) {
|
||||
paintBorder(rangeHighlighter.getTextAttributes().getEffectColor(),
|
||||
rangeHighlighter.getAffectedAreaStartOffset(),
|
||||
rangeHighlighter.getAffectedAreaEndOffset());
|
||||
rangeHighlighter.getAffectedAreaEndOffset(),
|
||||
rangeHighlighter.getTextAttributes().getEffectType());
|
||||
}
|
||||
|
||||
private void paintBorder(Color color, int startOffset, int endOffset) {
|
||||
paintBorder(myGraphics, myEditor, startOffset, endOffset, color);
|
||||
private void paintBorder(Color color, int startOffset, int endOffset, EffectType effectType) {
|
||||
paintBorder(myGraphics, myEditor, startOffset, endOffset, color, effectType);
|
||||
}
|
||||
|
||||
private boolean intersectsRange(RangeHighlighterEx rangeHighlighter) {
|
||||
@@ -106,7 +107,7 @@ public class BorderEffect {
|
||||
while (!iterator.atEnd()) {
|
||||
iterator.advance();
|
||||
paintBorder(myGraphics, myEditor, iterator.getStart(), iterator.getEnd(),
|
||||
iterator.getTextAttributes().getEffectColor());
|
||||
iterator.getTextAttributes().getEffectColor(), iterator.getTextAttributes().getEffectType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,14 +117,14 @@ public class BorderEffect {
|
||||
return myEditor.getDocument().getLineStartOffset(line);
|
||||
}
|
||||
|
||||
private static void paintBorder(Graphics g, EditorImpl editor, int startOffset, int endOffset, Color color) {
|
||||
private static void paintBorder(Graphics g, EditorImpl editor, int startOffset, int endOffset, Color color, EffectType effectType) {
|
||||
Color savedColor = g.getColor();
|
||||
g.setColor(color);
|
||||
paintBorder(g, editor, startOffset, endOffset);
|
||||
paintBorder(g, editor, startOffset, endOffset, effectType);
|
||||
g.setColor(savedColor);
|
||||
}
|
||||
|
||||
private static void paintBorder(Graphics g, EditorImpl editor, int startOffset, int endOffset) {
|
||||
private static void paintBorder(Graphics g, EditorImpl editor, int startOffset, int endOffset, EffectType effectType) {
|
||||
Point startPoint = offsetToXY(editor, startOffset);
|
||||
Point endPoint = offsetToXY(editor, endOffset);
|
||||
int height = endPoint.y - startPoint.y;
|
||||
@@ -132,10 +133,14 @@ public class BorderEffect {
|
||||
int endX = endPoint.x;
|
||||
if (height == 0) {
|
||||
int width = endX == startX ? 1 : endX - startX - 1;
|
||||
g.drawRect(startX, startY, width, editor.getLineHeight() - 1);
|
||||
if (effectType == EffectType.ROUNDED_BOX) {
|
||||
UIUtil.drawRectPickedOut((Graphics2D)g, startX, startY, width, editor.getLineHeight() - 1);
|
||||
} else {
|
||||
g.drawRect(startX, startY, width, editor.getLineHeight() - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
BorderGraphics border = new BorderGraphics(g, startX, startY);
|
||||
BorderGraphics border = new BorderGraphics(g, startX, startY, effectType);
|
||||
border.horizontalTo(editor.getMaxWidthInRange(startOffset, endOffset) - 1);
|
||||
border.verticalRel(height - 1);
|
||||
border.horizontalTo(endX);
|
||||
@@ -181,12 +186,14 @@ public class BorderEffect {
|
||||
|
||||
private int myX;
|
||||
private int myY;
|
||||
private EffectType myEffectType;
|
||||
|
||||
public BorderGraphics(Graphics graphics, int startX, int stIntY) {
|
||||
public BorderGraphics(Graphics graphics, int startX, int stIntY, EffectType effectType) {
|
||||
myGraphics = graphics;
|
||||
|
||||
myX = startX;
|
||||
myY = stIntY;
|
||||
myEffectType = effectType;
|
||||
}
|
||||
|
||||
public void horizontalTo(int x) {
|
||||
@@ -198,7 +205,11 @@ public class BorderEffect {
|
||||
}
|
||||
|
||||
private void lineTo(int x, int y) {
|
||||
UIUtil.drawLine(myGraphics, myX, myY, x, y);
|
||||
if (myEffectType == EffectType.ROUNDED_BOX) {
|
||||
UIUtil.drawLinePickedOut(myGraphics, myX, myY, x, y);
|
||||
} else {
|
||||
UIUtil.drawLine(myGraphics, myX, myY, x, y);
|
||||
}
|
||||
myX = x;
|
||||
myY = y;
|
||||
}
|
||||
|
||||
@@ -26,13 +26,11 @@ import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import com.intellij.util.WeakListener;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
@@ -51,7 +49,6 @@ import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@@ -92,6 +89,20 @@ public class UIUtil {
|
||||
private UIUtil() {
|
||||
}
|
||||
|
||||
public static void drawLinePickedOut(Graphics graphics, int x, int y, int x1, int y1) {
|
||||
if (x == x1) {
|
||||
int minY = Math.min(y, y1);
|
||||
int maxY = Math.max(y, y1);
|
||||
graphics.drawLine(x, minY+1, x1, maxY-1);
|
||||
} else if (y == y1) {
|
||||
int minX = Math.min(x, x1);
|
||||
int maxX = Math.max(x, x1);
|
||||
graphics.drawLine(minX+1, y, maxX-1, y1);
|
||||
} else {
|
||||
drawLine(graphics, x, y, x1, y1);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isReallyTypedEvent(KeyEvent e) {
|
||||
char c = e.getKeyChar();
|
||||
if (!(c >= 0x20 && c != 0x7F)) return false;
|
||||
@@ -785,6 +796,13 @@ public class UIUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawRectPickedOut(Graphics2D g, int x, int y, int w, int h) {
|
||||
g.drawLine(x+1, y, x+w-1, y);
|
||||
g.drawLine(x+w, y+1, x+w, y+h-1);
|
||||
g.drawLine(x+w-1, y+h, x+1, y+h);
|
||||
g.drawLine(x, y+1, x, y+h-1);
|
||||
}
|
||||
|
||||
private static void drawBoringDottedLine(final Graphics2D g,
|
||||
final int startX,
|
||||
final int endX,
|
||||
|
||||
Reference in New Issue
Block a user