2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.editor
.impl
;
18 import com
.intellij
.openapi
.editor
.Document
;
19 import com
.intellij
.openapi
.editor
.ex
.DocumentEx
;
20 import com
.intellij
.openapi
.editor
.ex
.RangeHighlighterEx
;
21 import com
.intellij
.openapi
.editor
.ex
.RangeMarkerEx
;
22 import com
.intellij
.openapi
.editor
.markup
.*;
23 import com
.intellij
.openapi
.util
.Comparing
;
24 import com
.intellij
.openapi
.util
.Key
;
25 import org
.jetbrains
.annotations
.NotNull
;
26 import org
.jetbrains
.annotations
.Nullable
;
31 * Implementation of the markup element for the editor and document.
34 public class RangeHighlighterImpl
implements RangeHighlighterEx
{
35 private final MarkupModel myModel
;
36 private final int myLayer
;
37 private final HighlighterTargetArea myTargetArea
;
38 private TextAttributes myTextAttributes
;
39 private LineMarkerRenderer myLineMarkerRenderer
;
40 private Color myErrorStripeColor
;
41 private Color myLineSeparatorColor
;
42 private SeparatorPlacement mySeparatorPlacement
;
43 private boolean isAfterEndOfLine
;
44 private final RangeMarkerEx myRangeMarker
;
45 private GutterIconRenderer myGutterIconRenderer
;
46 private boolean myErrorStripeMarkIsThin
;
47 private Object myErrorStripeTooltip
;
48 private MarkupEditorFilter myFilter
= MarkupEditorFilter
.EMPTY
;
50 RangeHighlighterImpl(@NotNull MarkupModel model
,
54 @NotNull HighlighterTargetArea target
,
55 TextAttributes textAttributes
,
57 myRangeMarker
= persistent
58 ?
new PersistentLineMarker((DocumentEx
)model
.getDocument(), start
)
59 : (RangeMarkerEx
)model
.getDocument().createRangeMarker(start
, end
);
60 myTextAttributes
= textAttributes
;
61 myTargetArea
= target
;
64 if (textAttributes
!= null) {
65 myErrorStripeColor
= textAttributes
.getErrorStripeColor();
69 public TextAttributes
getTextAttributes() {
70 return myTextAttributes
;
73 public void setTextAttributes(TextAttributes textAttributes
) {
74 TextAttributes old
= myTextAttributes
;
75 myTextAttributes
= textAttributes
;
76 if (!Comparing
.equal(old
, textAttributes
)) {
81 public int getLayer() {
85 public HighlighterTargetArea
getTargetArea() {
89 public int getAffectedAreaStartOffset() {
90 int startOffset
= getStartOffset();
91 if (myTargetArea
== HighlighterTargetArea
.EXACT_RANGE
) return startOffset
;
92 if (startOffset
== getDocument().getTextLength()) return startOffset
;
93 return getDocument().getLineStartOffset(getDocument().getLineNumber(startOffset
));
96 public int getAffectedAreaEndOffset() {
97 int endOffset
= getEndOffset();
98 if (myTargetArea
== HighlighterTargetArea
.EXACT_RANGE
) return endOffset
;
99 int textLength
= getDocument().getTextLength();
100 if (endOffset
== textLength
) return endOffset
;
101 return Math
.min(textLength
, getDocument().getLineEndOffset(getDocument().getLineNumber(endOffset
)) + 1);
104 public LineMarkerRenderer
getLineMarkerRenderer() {
105 return myLineMarkerRenderer
;
108 public void setLineMarkerRenderer(LineMarkerRenderer renderer
) {
109 myLineMarkerRenderer
= renderer
;
113 public GutterIconRenderer
getGutterIconRenderer() {
114 return myGutterIconRenderer
;
117 public void setGutterIconRenderer(GutterIconRenderer renderer
) {
118 GutterIconRenderer old
= myGutterIconRenderer
;
119 myGutterIconRenderer
= renderer
;
120 if (!Comparing
.equal(old
, renderer
)) {
125 public Color
getErrorStripeMarkColor() {
126 return myErrorStripeColor
;
129 public void setErrorStripeMarkColor(Color color
) {
130 Color old
= myErrorStripeColor
;
131 myErrorStripeColor
= color
;
132 if (!Comparing
.equal(old
, color
)) {
137 public Object
getErrorStripeTooltip() {
138 return myErrorStripeTooltip
;
141 public void setErrorStripeTooltip(Object tooltipObject
) {
142 Object old
= myErrorStripeTooltip
;
143 myErrorStripeTooltip
= tooltipObject
;
144 if (!Comparing
.equal(old
, tooltipObject
)) {
149 public boolean isThinErrorStripeMark() {
150 return myErrorStripeMarkIsThin
;
153 public void setThinErrorStripeMark(boolean value
) {
154 boolean old
= myErrorStripeMarkIsThin
;
155 myErrorStripeMarkIsThin
= value
;
161 public Color
getLineSeparatorColor() {
162 return myLineSeparatorColor
;
165 public void setLineSeparatorColor(Color color
) {
166 Color old
= myLineSeparatorColor
;
167 myLineSeparatorColor
= color
;
168 if (!Comparing
.equal(old
, color
)) {
173 public SeparatorPlacement
getLineSeparatorPlacement() {
174 return mySeparatorPlacement
;
177 public void setLineSeparatorPlacement(@Nullable SeparatorPlacement placement
) {
178 SeparatorPlacement old
= mySeparatorPlacement
;
179 mySeparatorPlacement
= placement
;
180 if (!Comparing
.equal(old
, placement
)) {
185 public void setEditorFilter(@NotNull MarkupEditorFilter filter
) {
191 public MarkupEditorFilter
getEditorFilter() {
195 public boolean isAfterEndOfLine() {
196 return isAfterEndOfLine
;
199 public void setAfterEndOfLine(boolean afterEndOfLine
) {
200 boolean old
= isAfterEndOfLine
;
201 isAfterEndOfLine
= afterEndOfLine
;
202 if (old
!= afterEndOfLine
) {
207 private void fireChanged() {
208 if (myModel
instanceof MarkupModelImpl
) {
209 ((MarkupModelImpl
)myModel
).fireSegmentHighlighterChanged(this);
213 public int getStartOffset() {
214 return myRangeMarker
.getStartOffset();
217 public long getId() {
218 return myRangeMarker
.getId();
221 public int getEndOffset() {
222 return myRangeMarker
.getEndOffset();
225 public boolean isValid() {
226 return myRangeMarker
.isValid();
230 public Document
getDocument() {
231 return myRangeMarker
.getDocument();
234 public void setGreedyToLeft(boolean greedy
) {
235 myRangeMarker
.setGreedyToLeft(greedy
);
238 public void setGreedyToRight(boolean greedy
) {
239 myRangeMarker
.setGreedyToRight(greedy
);
242 public boolean isGreedyToRight() {
243 return myRangeMarker
.isGreedyToRight();
246 public boolean isGreedyToLeft() {
247 return myRangeMarker
.isGreedyToLeft();
250 public <T
> T
getUserData(@NotNull Key
<T
> key
) {
251 return myRangeMarker
.getUserData(key
);
254 public <T
> void putUserData(@NotNull Key
<T
> key
, T value
) {
255 myRangeMarker
.putUserData(key
, value
);
258 public String
toString() {
259 return myRangeMarker
.toString();