optimization: replace all occurrence is dramatically faster
[fedora-idea.git] / platform-impl / src / com / intellij / openapi / editor / impl / RangeHighlighterImpl.java
blobfce7ed748481daebc6f96d9d06d3563ae166660f
1 package com.intellij.openapi.editor.impl;
3 import com.intellij.openapi.editor.Document;
4 import com.intellij.openapi.editor.ex.RangeHighlighterEx;
5 import com.intellij.openapi.editor.ex.RangeMarkerEx;
6 import com.intellij.openapi.editor.markup.*;
7 import com.intellij.openapi.util.Key;
8 import org.jetbrains.annotations.NotNull;
10 import java.awt.*;
12 /**
13 * Implementation of the markup element for the editor and document.
14 * @author max
16 public class RangeHighlighterImpl implements RangeHighlighterEx {
17 private final MarkupModel myModel;
18 private final int myLayer;
19 private final HighlighterTargetArea myTargetArea;
20 private TextAttributes myTextAttributes;
21 private LineMarkerRenderer myLineMarkerRenderer;
22 private Color myErrorStripeColor;
23 private Color myLineSeparatorColor;
24 private SeparatorPlacement mySeparatorPlacement;
25 private boolean isAfterEndOfLine;
26 private final RangeMarkerEx myRangeMarker;
27 private GutterIconRenderer myGutterIconRenderer;
28 private boolean myErrorStripeMarkIsThin;
29 private Object myErrorStripeTooltip;
30 private MarkupEditorFilter myFilter = MarkupEditorFilter.EMPTY;
32 RangeHighlighterImpl(@NotNull MarkupModel model,
33 int start,
34 int end,
35 int layer,
36 @NotNull HighlighterTargetArea target,
37 TextAttributes textAttributes,
38 boolean persistent) {
39 myRangeMarker = persistent
40 ? new PersistentLineMarker(model.getDocument(), start)
41 : (RangeMarkerEx)model.getDocument().createRangeMarker(start, end);
42 myTextAttributes = textAttributes;
43 myTargetArea = target;
44 myLayer = layer;
45 myModel = model;
46 if (textAttributes != null) {
47 myErrorStripeColor = textAttributes.getErrorStripeColor();
51 public TextAttributes getTextAttributes() {
52 return myTextAttributes;
55 public void setTextAttributes(final TextAttributes textAttributes) {
56 myTextAttributes = textAttributes;
59 public int getLayer() {
60 return myLayer;
63 public HighlighterTargetArea getTargetArea() {
64 return myTargetArea;
67 public int getAffectedAreaStartOffset() {
68 int startOffset = getStartOffset();
69 if (myTargetArea == HighlighterTargetArea.EXACT_RANGE) return startOffset;
70 if (startOffset == getDocument().getTextLength()) return startOffset;
71 return getDocument().getLineStartOffset(getDocument().getLineNumber(startOffset));
74 public int getAffectedAreaEndOffset() {
75 int endOffset = getEndOffset();
76 if (myTargetArea == HighlighterTargetArea.EXACT_RANGE) return endOffset;
77 int textLength = getDocument().getTextLength();
78 if (endOffset == textLength) return endOffset;
79 return Math.min(textLength, getDocument().getLineEndOffset(getDocument().getLineNumber(endOffset)) + 1);
82 public LineMarkerRenderer getLineMarkerRenderer() {
83 return myLineMarkerRenderer;
86 public void setLineMarkerRenderer(LineMarkerRenderer renderer) {
87 myLineMarkerRenderer = renderer;
88 fireChanged();
91 public GutterIconRenderer getGutterIconRenderer() {
92 return myGutterIconRenderer;
95 public void setGutterIconRenderer(GutterIconRenderer renderer) {
96 myGutterIconRenderer = renderer;
97 fireChanged();
100 public Color getErrorStripeMarkColor() {
101 return myErrorStripeColor;
104 public void setErrorStripeMarkColor(Color color) {
105 myErrorStripeColor = color;
106 fireChanged();
109 public Object getErrorStripeTooltip() {
110 return myErrorStripeTooltip;
113 public void setErrorStripeTooltip(Object tooltipObject) {
114 myErrorStripeTooltip = tooltipObject;
117 public boolean isThinErrorStripeMark() {
118 return myErrorStripeMarkIsThin;
121 public void setThinErrorStripeMark(boolean value) {
122 myErrorStripeMarkIsThin = value;
125 public Color getLineSeparatorColor() {
126 return myLineSeparatorColor;
129 public void setLineSeparatorColor(Color color) {
130 myLineSeparatorColor = color;
131 fireChanged();
134 public SeparatorPlacement getLineSeparatorPlacement() {
135 return mySeparatorPlacement;
138 public void setLineSeparatorPlacement(SeparatorPlacement placement) {
139 mySeparatorPlacement = placement;
140 fireChanged();
143 public void setEditorFilter(@NotNull MarkupEditorFilter filter) {
144 myFilter = filter;
147 @NotNull
148 public MarkupEditorFilter getEditorFilter() {
149 return myFilter;
152 public boolean isAfterEndOfLine() {
153 return isAfterEndOfLine;
156 public void setAfterEndOfLine(boolean afterEndOfLine) {
157 isAfterEndOfLine = afterEndOfLine;
160 private void fireChanged() {
161 if (myModel instanceof MarkupModelImpl) {
162 ((MarkupModelImpl)myModel).fireSegmentHighlighterChanged(this);
166 public int getStartOffset() {
167 return myRangeMarker.getStartOffset();
170 public long getId() {
171 return myRangeMarker.getId();
174 public int getEndOffset() {
175 return myRangeMarker.getEndOffset();
178 public boolean isValid() {
179 return myRangeMarker.isValid();
182 @NotNull
183 public Document getDocument() {
184 return myRangeMarker.getDocument();
187 public void setGreedyToLeft(boolean greedy) {
188 myRangeMarker.setGreedyToLeft(greedy);
191 public void setGreedyToRight(boolean greedy) {
192 myRangeMarker.setGreedyToRight(greedy);
195 public <T> T getUserData(Key<T> key) {
196 return myRangeMarker.getUserData(key);
199 public <T> void putUserData(Key<T> key, T value) {
200 myRangeMarker.putUserData(key, value);
203 public String toString() {
204 return myRangeMarker.toString();