use of com.intellij.util.text.CharArrayCharSequence in project intellij-community by JetBrains.
the class XXXXX method paintBackgrounds.
private void paintBackgrounds(@NotNull Graphics g, @NotNull Rectangle clip, @NotNull LogicalPosition clipStartPosition, @NotNull VisualPosition clipStartVisualPos, int clipStartOffset, int clipEndOffset) {
Color defaultBackground = getBackgroundColor();
if (myEditorComponent.isOpaque()) {
g.setColor(defaultBackground);
g.fillRect(clip.x, clip.y, clip.width, clip.height);
}
Color prevBackColor = null;
int lineHeight = getLineHeight();
int visibleLine = yPositionToVisibleLine(clip.y);
Point position = new Point(0, visibleLine * lineHeight);
CharSequence prefixText = myPrefixText == null ? null : new CharArrayCharSequence(myPrefixText);
if (clipStartVisualPos.line == 0 && prefixText != null) {
Color backColor = myPrefixAttributes.getBackgroundColor();
position.x = drawBackground(g, backColor, prefixText, 0, prefixText.length(), position, myPrefixAttributes.getFontType(), defaultBackground, clip);
prevBackColor = backColor;
}
if (clipStartPosition.line >= myDocument.getLineCount() || clipStartPosition.line < 0) {
if (position.x > 0)
flushBackground(g, clip);
return;
}
myLastBackgroundPosition = null;
myLastBackgroundColor = null;
mySelectionStartPosition = null;
mySelectionEndPosition = null;
int start = clipStartOffset;
if (!myPurePaintingMode) {
getSoftWrapModel().registerSoftWrapsIfNecessary();
}
LineIterator lIterator = createLineIterator();
lIterator.start(start);
if (lIterator.atEnd()) {
return;
}
IterationState iterationState = new IterationState(this, start, clipEndOffset, isPaintSelection());
TextAttributes attributes = iterationState.getMergedAttributes();
Color backColor = getBackgroundColor(attributes);
int fontType = attributes.getFontType();
int lastLineIndex = Math.max(0, myDocument.getLineCount() - 1);
// There is a possible case that we need to draw background from the start of soft wrap-introduced visual line. Given position
// has valid 'y' coordinate then at it shouldn't be affected by soft wrap that corresponds to the visual line start offset.
// Hence, we store information about soft wrap to be skipped for further processing and adjust 'x' coordinate value if necessary.
TIntHashSet softWrapsToSkip = new TIntHashSet();
SoftWrap softWrap = getSoftWrapModel().getSoftWrap(start);
if (softWrap != null) {
softWrapsToSkip.add(softWrap.getStart());
Color color = null;
if (backColor != null && !backColor.equals(defaultBackground)) {
color = backColor;
}
// virtual space then.
if (color == null && position.y == getCaretModel().getVisualPosition().line * getLineHeight()) {
color = mySettings.isCaretRowShown() ? getColorsScheme().getColor(EditorColors.CARET_ROW_COLOR) : null;
}
if (color != null) {
drawBackground(g, color, softWrap.getIndentInPixels(), position, defaultBackground, clip);
prevBackColor = color;
}
position.x = softWrap.getIndentInPixels();
}
// There is a possible case that caret is located at soft-wrapped line. We don't need to paint caret row background
// on a last visual line of that soft-wrapped line then. Below is a holder for the flag that indicates if caret row
// background is already drawn.
boolean[] caretRowPainted = new boolean[1];
CharSequence text = myDocument.getImmutableCharSequence();
while (!iterationState.atEnd() && !lIterator.atEnd()) {
int hEnd = iterationState.getEndOffset();
int lEnd = lIterator.getEnd();
if (hEnd >= lEnd) {
FoldRegion collapsedFolderAt = myFoldingModel.getCollapsedRegionAtOffset(start);
if (collapsedFolderAt == null) {
position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, start, lEnd - lIterator.getSeparatorLength(), position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
prevBackColor = backColor;
paintAfterLineEndBackgroundSegments(g, iterationState, position, defaultBackground, lineHeight);
if (lIterator.getLineNumber() < lastLineIndex) {
if (backColor != null && !backColor.equals(defaultBackground)) {
g.setColor(backColor);
g.fillRect(position.x, position.y, clip.x + clip.width - position.x, lineHeight);
}
} else {
if (iterationState.hasPastFileEndBackgroundSegments()) {
paintAfterLineEndBackgroundSegments(g, iterationState, position, defaultBackground, lineHeight);
}
paintAfterFileEndBackground(iterationState, g, position, clip, lineHeight, defaultBackground, caretRowPainted);
break;
}
position.x = 0;
if (position.y > clip.y + clip.height)
break;
position.y += lineHeight;
start = lEnd;
} else if (collapsedFolderAt.getEndOffset() == clipEndOffset) {
softWrap = mySoftWrapModel.getSoftWrap(collapsedFolderAt.getStartOffset());
if (softWrap != null) {
position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, collapsedFolderAt.getStartOffset(), collapsedFolderAt.getStartOffset(), position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
}
CharSequence chars = collapsedFolderAt.getPlaceholderText();
position.x = drawBackground(g, backColor, chars, 0, chars.length(), position, fontType, defaultBackground, clip);
prevBackColor = backColor;
}
lIterator.advance();
} else {
FoldRegion collapsedFolderAt = iterationState.getCurrentFold();
if (collapsedFolderAt != null) {
softWrap = mySoftWrapModel.getSoftWrap(collapsedFolderAt.getStartOffset());
if (softWrap != null) {
position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, collapsedFolderAt.getStartOffset(), collapsedFolderAt.getStartOffset(), position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
}
CharSequence chars = collapsedFolderAt.getPlaceholderText();
position.x = drawBackground(g, backColor, chars, 0, chars.length(), position, fontType, defaultBackground, clip);
prevBackColor = backColor;
} else if (hEnd > lEnd - lIterator.getSeparatorLength()) {
position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, start, lEnd - lIterator.getSeparatorLength(), position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
prevBackColor = backColor;
} else {
position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, start, hEnd, position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
prevBackColor = backColor;
}
iterationState.advance();
attributes = iterationState.getMergedAttributes();
backColor = getBackgroundColor(attributes);
fontType = attributes.getFontType();
start = iterationState.getStartOffset();
}
}
flushBackground(g, clip);
if (lIterator.getLineNumber() >= lastLineIndex && position.y <= clip.y + clip.height) {
paintAfterFileEndBackground(iterationState, g, position, clip, lineHeight, defaultBackground, caretRowPainted);
}
// Perform additional activity if soft wrap is added or removed during repainting.
if (mySoftWrapsChanged) {
mySoftWrapsChanged = false;
clearTextWidthCache();
validateSize();
// Repaint editor to the bottom in order to ensure that its content is shown correctly after new soft wrap introduction.
repaintToScreenBottom(EditorUtil.yPositionToLogicalLine(this, position));
// Repaint gutter at all space that is located after active clip in order to ensure that line numbers are correctly redrawn
// in accordance with the newly introduced soft wrap(s).
myGutterComponent.repaint(0, clip.y, myGutterComponent.getWidth(), myGutterComponent.getHeight() - clip.y);
}
}
use of com.intellij.util.text.CharArrayCharSequence in project intellij-community by JetBrains.
the class XXXXX method paintText.
private void paintText(@NotNull Graphics g, @NotNull Rectangle clip, @NotNull LogicalPosition clipStartPosition, int clipStartOffset, int clipEndOffset) {
myCurrentFontType = null;
myLastCache = null;
int lineHeight = getLineHeight();
int visibleLine = clip.y / lineHeight;
int startLine = clipStartPosition.line;
int start = clipStartOffset;
Point position = new Point(0, visibleLine * lineHeight);
if (startLine == 0 && myPrefixText != null) {
position.x = drawStringWithSoftWraps(g, new CharArrayCharSequence(myPrefixText), 0, myPrefixText.length, position, clip, myPrefixAttributes.getEffectColor(), myPrefixAttributes.getEffectType(), myPrefixAttributes.getFontType(), myPrefixAttributes.getForegroundColor(), -1, PAINT_NO_WHITESPACE);
}
if (startLine >= myDocument.getLineCount() || startLine < 0) {
if (position.x > 0)
flushCachedChars(g);
return;
}
LineIterator lIterator = createLineIterator();
lIterator.start(start);
if (lIterator.atEnd()) {
return;
}
IterationState iterationState = new IterationState(this, start, clipEndOffset, isPaintSelection());
TextAttributes attributes = iterationState.getMergedAttributes();
Color currentColor = attributes.getForegroundColor();
if (currentColor == null) {
currentColor = getForegroundColor();
}
Color effectColor = attributes.getEffectColor();
EffectType effectType = attributes.getEffectType();
int fontType = attributes.getFontType();
g.setColor(currentColor);
CharSequence chars = myDocument.getImmutableCharSequence();
LineWhitespacePaintingStrategy context = new LineWhitespacePaintingStrategy();
context.update(chars, lIterator);
while (!iterationState.atEnd() && !lIterator.atEnd()) {
int hEnd = iterationState.getEndOffset();
int lEnd = lIterator.getEnd();
if (hEnd >= lEnd) {
FoldRegion collapsedFolderAt = myFoldingModel.getCollapsedRegionAtOffset(start);
if (collapsedFolderAt == null) {
drawStringWithSoftWraps(g, chars, start, lEnd - lIterator.getSeparatorLength(), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, context);
final VirtualFile file = getVirtualFile();
if (myProject != null && file != null && !isOneLineMode()) {
int offset = position.x;
String additionalText = "";
for (EditorLinePainter painter : EditorLinePainter.EP_NAME.getExtensions()) {
Collection<LineExtensionInfo> extensions = painter.getLineExtensions(myProject, file, lIterator.getLineNumber());
if (extensions != null && !extensions.isEmpty()) {
for (LineExtensionInfo info : extensions) {
final String text = info.getText();
additionalText += text;
position.x = drawString(g, text, 0, text.length(), position, clip, info.getEffectColor() == null ? effectColor : info.getEffectColor(), info.getEffectType() == null ? effectType : info.getEffectType(), info.getFontType(), info.getColor() == null ? currentColor : info.getColor(), context);
}
}
}
for (char ch : additionalText.toCharArray()) {
offset += EditorUtil.charWidth(ch, Font.ITALIC, this);
}
myLinePaintersWidth = Math.max(myLinePaintersWidth, offset);
}
position.x = 0;
if (position.y > clip.y + clip.height) {
break;
}
position.y += lineHeight;
start = lEnd;
}
// myBorderEffect.eolReached(g, this);
lIterator.advance();
if (!lIterator.atEnd()) {
context.update(chars, lIterator);
}
} else {
FoldRegion collapsedFolderAt = iterationState.getCurrentFold();
if (collapsedFolderAt != null) {
SoftWrap softWrap = mySoftWrapModel.getSoftWrap(collapsedFolderAt.getStartOffset());
if (softWrap != null) {
position.x = drawStringWithSoftWraps(g, chars, collapsedFolderAt.getStartOffset(), collapsedFolderAt.getStartOffset(), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, context);
}
int foldingXStart = position.x;
position.x = drawString(g, collapsedFolderAt.getPlaceholderText(), position, clip, effectColor, effectType, fontType, currentColor, PAINT_NO_WHITESPACE);
//drawStringWithSoftWraps(g, collapsedFolderAt.getPlaceholderText(), position, clip, effectColor, effectType,
// fontType, currentColor, logicalPosition);
BorderEffect.paintFoldedEffect(g, foldingXStart, position.y, position.x, getLineHeight(), effectColor, effectType);
} else {
position.x = drawStringWithSoftWraps(g, chars, start, Math.min(hEnd, lEnd - lIterator.getSeparatorLength()), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, context);
}
iterationState.advance();
attributes = iterationState.getMergedAttributes();
currentColor = attributes.getForegroundColor();
if (currentColor == null) {
currentColor = getForegroundColor();
}
effectColor = attributes.getEffectColor();
effectType = attributes.getEffectType();
fontType = attributes.getFontType();
start = iterationState.getStartOffset();
}
}
FoldRegion collapsedFolderAt = iterationState.getCurrentFold();
if (collapsedFolderAt != null) {
int foldingXStart = position.x;
int foldingXEnd = drawStringWithSoftWraps(g, collapsedFolderAt.getPlaceholderText(), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, PAINT_NO_WHITESPACE);
BorderEffect.paintFoldedEffect(g, foldingXStart, position.y, foldingXEnd, getLineHeight(), effectColor, effectType);
// myBorderEffect.collapsedFolderReached(g, this);
}
final SoftWrap softWrap = mySoftWrapModel.getSoftWrap(clipEndOffset);
if (softWrap != null) {
mySoftWrapModel.paint(g, SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED, position.x, position.y, getLineHeight());
}
flushCachedChars(g);
}
use of com.intellij.util.text.CharArrayCharSequence in project intellij-community by JetBrains.
the class FileBasedIndexTest method testLargeFile.
public void testLargeFile() throws Exception {
char[] text = new char[FileUtilRt.LARGE_FOR_CONTENT_LOADING + 42];
final String clazz = "class Foo { String bar; }";
for (int i = 0; i < text.length; i++) {
text[i] = i < clazz.length() ? clazz.charAt(i) : ' ';
}
final LightVirtualFile file = new LightVirtualFile("Foo.java", new CharArrayCharSequence(text));
assertFalse(((FileBasedIndexImpl) FileBasedIndex.getInstance()).isIndexingCandidate(file, StubUpdatingIndex.INDEX_ID));
}
use of com.intellij.util.text.CharArrayCharSequence in project intellij-community by JetBrains.
the class YYYYYYY method paintText.
private void paintText(@NotNull Graphics g, @NotNull Rectangle clip, @NotNull LogicalPosition clipStartPosition, int clipStartOffset, int clipEndOffset) {
myCurrentFontType = null;
myLastCache = null;
int lineHeight = getLineHeight();
int visibleLine = clip.y / lineHeight;
int startLine = clipStartPosition.line;
int start = clipStartOffset;
Point position = new Point(0, visibleLine * lineHeight);
if (startLine == 0 && myPrefixText != null) {
position.x = drawStringWithSoftWraps(g, new CharArrayCharSequence(myPrefixText), 0, myPrefixText.length, position, clip, myPrefixAttributes.getEffectColor(), myPrefixAttributes.getEffectType(), myPrefixAttributes.getFontType(), myPrefixAttributes.getForegroundColor(), -1, PAINT_NO_WHITESPACE);
}
if (startLine >= myDocument.getLineCount() || startLine < 0) {
if (position.x > 0)
flushCachedChars(g);
return;
}
LineIterator lIterator = createLineIterator();
lIterator.start(start);
if (lIterator.atEnd()) {
return;
}
IterationState iterationState = new IterationState(this, start, clipEndOffset, isPaintSelection());
TextAttributes attributes = iterationState.getMergedAttributes();
Color currentColor = attributes.getForegroundColor();
if (currentColor == null) {
currentColor = getForegroundColor();
}
Color effectColor = attributes.getEffectColor();
EffectType effectType = attributes.getEffectType();
int fontType = attributes.getFontType();
g.setColor(currentColor);
CharSequence chars = myDocument.getImmutableCharSequence();
LineWhitespacePaintingStrategy context = new LineWhitespacePaintingStrategy();
context.update(chars, lIterator);
while (!iterationState.atEnd() && !lIterator.atEnd()) {
int hEnd = iterationState.getEndOffset();
int lEnd = lIterator.getEnd();
if (hEnd >= lEnd) {
FoldRegion collapsedFolderAt = myFoldingModel.getCollapsedRegionAtOffset(start);
if (collapsedFolderAt == null) {
drawStringWithSoftWraps(g, chars, start, lEnd - lIterator.getSeparatorLength(), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, context);
final VirtualFile file = getVirtualFile();
if (myProject != null && file != null && !isOneLineMode()) {
int offset = position.x;
for (EditorLinePainter painter : EditorLinePainter.EP_NAME.getExtensions()) {
Collection<LineExtensionInfo> extensions = painter.getLineExtensions(myProject, file, lIterator.getLineNumber());
if (extensions != null && !extensions.isEmpty()) {
for (LineExtensionInfo info : extensions) {
final String text = info.getText();
for (int i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
offset += EditorUtil.charWidth(ch, Font.ITALIC, this);
}
position.x = drawString(g, text, 0, text.length(), position, clip, info.getEffectColor() == null ? effectColor : info.getEffectColor(), info.getEffectType() == null ? effectType : info.getEffectType(), info.getFontType(), info.getColor() == null ? currentColor : info.getColor(), context);
}
}
}
myLinePaintersWidth = Math.max(myLinePaintersWidth, offset);
}
position.x = 0;
if (position.y > clip.y + clip.height) {
break;
}
position.y += lineHeight;
start = lEnd;
}
// myBorderEffect.eolReached(g, this);
lIterator.advance();
if (!lIterator.atEnd()) {
context.update(chars, lIterator);
}
} else {
FoldRegion collapsedFolderAt = iterationState.getCurrentFold();
if (collapsedFolderAt != null) {
SoftWrap softWrap = mySoftWrapModel.getSoftWrap(collapsedFolderAt.getStartOffset());
if (softWrap != null) {
position.x = drawStringWithSoftWraps(g, chars, collapsedFolderAt.getStartOffset(), collapsedFolderAt.getStartOffset(), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, context);
}
int foldingXStart = position.x;
position.x = drawString(g, collapsedFolderAt.getPlaceholderText(), position, clip, effectColor, effectType, fontType, currentColor, PAINT_NO_WHITESPACE);
//drawStringWithSoftWraps(g, collapsedFolderAt.getPlaceholderText(), position, clip, effectColor, effectType,
// fontType, currentColor, logicalPosition);
BorderEffect.paintFoldedEffect(g, foldingXStart, position.y, position.x, getLineHeight(), effectColor, effectType);
} else {
position.x = drawStringWithSoftWraps(g, chars, start, Math.min(hEnd, lEnd - lIterator.getSeparatorLength()), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, context);
}
iterationState.advance();
attributes = iterationState.getMergedAttributes();
currentColor = attributes.getForegroundColor();
if (currentColor == null) {
currentColor = getForegroundColor();
}
effectColor = attributes.getEffectColor();
effectType = attributes.getEffectType();
fontType = attributes.getFontType();
start = iterationState.getStartOffset();
}
}
FoldRegion collapsedFolderAt = iterationState.getCurrentFold();
if (collapsedFolderAt != null) {
int foldingXStart = position.x;
int foldingXEnd = drawStringWithSoftWraps(g, collapsedFolderAt.getPlaceholderText(), position, clip, effectColor, effectType, fontType, currentColor, clipStartOffset, PAINT_NO_WHITESPACE);
BorderEffect.paintFoldedEffect(g, foldingXStart, position.y, foldingXEnd, getLineHeight(), effectColor, effectType);
// myBorderEffect.collapsedFolderReached(g, this);
}
final SoftWrap softWrap = mySoftWrapModel.getSoftWrap(clipEndOffset);
if (softWrap != null) {
mySoftWrapModel.paint(g, SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED, position.x, position.y, getLineHeight());
}
flushCachedChars(g);
}
Aggregations