cleanup
[fedora-idea.git] / platform / platform-api / src / com / intellij / ui / HighlightedText.java
blob8e5c46b3dd5da2ab4b46eafbf4379d7c0d657686
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.
17 package com.intellij.ui;
19 import com.intellij.openapi.editor.markup.TextAttributes;
21 import java.util.ArrayList;
23 public class HighlightedText {
24 private final StringBuffer myBuffer;
25 private final ArrayList myHighlightedRegions;
27 public HighlightedText() {
28 myBuffer = new StringBuffer();
29 myHighlightedRegions = new ArrayList(3);
32 public void appendText(String text, TextAttributes attributes) {
33 int startOffset = myBuffer.length();
34 myBuffer.append(text);
35 if (attributes != null) {
36 myHighlightedRegions.add(new HighlightedRegion(startOffset, myBuffer.length(), attributes));
40 public void insertTextAtStart(String text, TextAttributes attributes) {
41 int textLength = text.length();
42 for (int i=0; i < myHighlightedRegions.size(); i++) {
43 HighlightedRegion info = (HighlightedRegion)myHighlightedRegions.get(i);
44 info.startOffset += textLength;
45 info.endOffset += textLength;
47 myBuffer.insert(0, text);
48 if (attributes != null) {
49 myHighlightedRegions.add(new HighlightedRegion(0, textLength, attributes));
53 public boolean equals(Object o) {
54 if (!(o instanceof HighlightedText)) return false;
56 HighlightedText highlightedText = (HighlightedText)o;
58 if (!myBuffer.equals(highlightedText.myBuffer)) return false;
59 if (!myHighlightedRegions.equals(highlightedText.myHighlightedRegions)) return false;
61 return true;
64 public String getText() {
65 return myBuffer.toString();
68 public void applyToComponent(HighlightableComponent renderer) {
69 renderer.setText(myBuffer.toString());
70 for (int i=0; i < myHighlightedRegions.size(); i++) {
71 HighlightedRegion info = (HighlightedRegion)myHighlightedRegions.get(i);
72 renderer.addHighlighter(info.startOffset, info.endOffset, info.textAttributes);