IDEA-51739
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / editor / impl / RangeHighlighterImpl.java
blob1e7951db0055214d727324cae2bea36d7b4c7cb0
1 /*
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.Key;
24 import org.jetbrains.annotations.NotNull;
26 import java.awt.*;
28 /**
29 * Implementation of the markup element for the editor and document.
30 * @author max
32 public class RangeHighlighterImpl implements RangeHighlighterEx {
33 private final MarkupModel myModel;
34 private final int myLayer;
35 private final HighlighterTargetArea myTargetArea;
36 private TextAttributes myTextAttributes;
37 private LineMarkerRenderer myLineMarkerRenderer;
38 private Color myErrorStripeColor;
39 private Color myLineSeparatorColor;
40 private SeparatorPlacement mySeparatorPlacement;
41 private boolean isAfterEndOfLine;
42 private final RangeMarkerEx myRangeMarker;
43 private GutterIconRenderer myGutterIconRenderer;
44 private boolean myErrorStripeMarkIsThin;
45 private Object myErrorStripeTooltip;
46 private MarkupEditorFilter myFilter = MarkupEditorFilter.EMPTY;
48 RangeHighlighterImpl(@NotNull MarkupModel model,
49 int start,
50 int end,
51 int layer,
52 @NotNull HighlighterTargetArea target,
53 TextAttributes textAttributes,
54 boolean persistent) {
55 myRangeMarker = persistent
56 ? new PersistentLineMarker((DocumentEx)model.getDocument(), start)
57 : (RangeMarkerEx)model.getDocument().createRangeMarker(start, end);
58 myTextAttributes = textAttributes;
59 myTargetArea = target;
60 myLayer = layer;
61 myModel = model;
62 if (textAttributes != null) {
63 myErrorStripeColor = textAttributes.getErrorStripeColor();
67 public TextAttributes getTextAttributes() {
68 return myTextAttributes;
71 public void setTextAttributes(final TextAttributes textAttributes) {
72 myTextAttributes = textAttributes;
73 fireChanged();
76 public int getLayer() {
77 return myLayer;
80 public HighlighterTargetArea getTargetArea() {
81 return myTargetArea;
84 public int getAffectedAreaStartOffset() {
85 int startOffset = getStartOffset();
86 if (myTargetArea == HighlighterTargetArea.EXACT_RANGE) return startOffset;
87 if (startOffset == getDocument().getTextLength()) return startOffset;
88 return getDocument().getLineStartOffset(getDocument().getLineNumber(startOffset));
91 public int getAffectedAreaEndOffset() {
92 int endOffset = getEndOffset();
93 if (myTargetArea == HighlighterTargetArea.EXACT_RANGE) return endOffset;
94 int textLength = getDocument().getTextLength();
95 if (endOffset == textLength) return endOffset;
96 return Math.min(textLength, getDocument().getLineEndOffset(getDocument().getLineNumber(endOffset)) + 1);
99 public LineMarkerRenderer getLineMarkerRenderer() {
100 return myLineMarkerRenderer;
103 public void setLineMarkerRenderer(LineMarkerRenderer renderer) {
104 myLineMarkerRenderer = renderer;
105 fireChanged();
108 public GutterIconRenderer getGutterIconRenderer() {
109 return myGutterIconRenderer;
112 public void setGutterIconRenderer(GutterIconRenderer renderer) {
113 myGutterIconRenderer = renderer;
114 fireChanged();
117 public Color getErrorStripeMarkColor() {
118 return myErrorStripeColor;
121 public void setErrorStripeMarkColor(Color color) {
122 myErrorStripeColor = color;
123 fireChanged();
126 public Object getErrorStripeTooltip() {
127 return myErrorStripeTooltip;
130 public void setErrorStripeTooltip(Object tooltipObject) {
131 myErrorStripeTooltip = tooltipObject;
132 fireChanged();
135 public boolean isThinErrorStripeMark() {
136 return myErrorStripeMarkIsThin;
139 public void setThinErrorStripeMark(boolean value) {
140 myErrorStripeMarkIsThin = value;
141 fireChanged();
144 public Color getLineSeparatorColor() {
145 return myLineSeparatorColor;
148 public void setLineSeparatorColor(Color color) {
149 myLineSeparatorColor = color;
150 fireChanged();
153 public SeparatorPlacement getLineSeparatorPlacement() {
154 return mySeparatorPlacement;
157 public void setLineSeparatorPlacement(SeparatorPlacement placement) {
158 mySeparatorPlacement = placement;
159 fireChanged();
162 public void setEditorFilter(@NotNull MarkupEditorFilter filter) {
163 myFilter = filter;
164 fireChanged();
167 @NotNull
168 public MarkupEditorFilter getEditorFilter() {
169 return myFilter;
172 public boolean isAfterEndOfLine() {
173 return isAfterEndOfLine;
176 public void setAfterEndOfLine(boolean afterEndOfLine) {
177 isAfterEndOfLine = afterEndOfLine;
178 fireChanged();
181 private void fireChanged() {
182 if (myModel instanceof MarkupModelImpl) {
183 ((MarkupModelImpl)myModel).fireSegmentHighlighterChanged(this);
187 public int getStartOffset() {
188 return myRangeMarker.getStartOffset();
191 public long getId() {
192 return myRangeMarker.getId();
195 public int getEndOffset() {
196 return myRangeMarker.getEndOffset();
199 public boolean isValid() {
200 return myRangeMarker.isValid();
203 @NotNull
204 public Document getDocument() {
205 return myRangeMarker.getDocument();
208 public void setGreedyToLeft(boolean greedy) {
209 myRangeMarker.setGreedyToLeft(greedy);
212 public void setGreedyToRight(boolean greedy) {
213 myRangeMarker.setGreedyToRight(greedy);
216 public boolean isGreedyToRight() {
217 return myRangeMarker.isGreedyToRight();
220 public boolean isGreedyToLeft() {
221 return myRangeMarker.isGreedyToLeft();
224 public <T> T getUserData(@NotNull Key<T> key) {
225 return myRangeMarker.getUserData(key);
228 public <T> void putUserData(@NotNull Key<T> key, T value) {
229 myRangeMarker.putUserData(key, value);
232 public String toString() {
233 return myRangeMarker.toString();