|
|
@ -188,13 +188,15 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
Shape dirtyShape; |
|
|
|
Shape dirtyShape; |
|
|
|
|
|
|
|
|
|
|
|
boolean ltr = isLeftTorRight(c); |
|
|
|
boolean ltr = isLeftTorRight(c); |
|
|
|
|
|
|
|
boolean rounded = ltr && isRounded(); |
|
|
|
|
|
|
|
boolean lineExtension = ltr && isLineExtendingEnabled(); |
|
|
|
|
|
|
|
|
|
|
|
if (ltr && (isLineExtendingEnabled() || isRounded())) { |
|
|
|
if (lineExtension || rounded) { |
|
|
|
dirtyShape = paintRoundedLayer(g2d, c, offs0, offs1, context, false); |
|
|
|
dirtyShape = paintRoundedLayer(g2d, c, offs0, offs1, context, rounded, lineExtension, false); |
|
|
|
|
|
|
|
|
|
|
|
// Swing may not recognise the painted extension. Just repaint if the selection changed to guarantee
|
|
|
|
// Swing may not recognise the painted extension. Just repaint if the selection changed to guarantee
|
|
|
|
// everything is visible.
|
|
|
|
// everything is visible.
|
|
|
|
if (isLineExtendingEnabled()) { |
|
|
|
if (lineExtension) { |
|
|
|
if ((lastSelEnd != c.getSelectionEnd() || lastSelStart != c.getSelectionStart())) { |
|
|
|
if ((lastSelEnd != c.getSelectionEnd() || lastSelStart != c.getSelectionStart())) { |
|
|
|
lastSelEnd = c.getSelectionEnd(); |
|
|
|
lastSelEnd = c.getSelectionEnd(); |
|
|
|
lastSelStart = c.getSelectionStart(); |
|
|
|
lastSelStart = c.getSelectionStart(); |
|
|
@ -228,7 +230,9 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Rectangle paintRoundedLayer(final Graphics2D g, final JTextComponent c, final int offs0, final int offs1, |
|
|
|
protected Rectangle paintRoundedLayer(final Graphics2D g, final JTextComponent c, final int offs0, final int offs1, |
|
|
|
final GraphicsContext context, final boolean isPaintingPreceding) { |
|
|
|
final GraphicsContext context, |
|
|
|
|
|
|
|
final boolean rounded, final boolean extendLines, |
|
|
|
|
|
|
|
final boolean isPaintingPreceding) { |
|
|
|
Insets ins = c.getInsets(); |
|
|
|
Insets ins = c.getInsets(); |
|
|
|
|
|
|
|
|
|
|
|
Rectangle posOffs0 = getPosRect(c, offs0); |
|
|
|
Rectangle posOffs0 = getPosRect(c, offs0); |
|
|
@ -249,6 +253,11 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
int nextLineEnd = getOffset(c, c.getWidth(), getPosRect(c, nextLineStart).y); |
|
|
|
int nextLineEnd = getOffset(c, c.getWidth(), getPosRect(c, nextLineStart).y); |
|
|
|
if (nextLineEnd < nextLineStart) nextLineEnd = nextLineStart; |
|
|
|
if (nextLineEnd < nextLineStart) nextLineEnd = nextLineStart; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isEndOfLine = offs1 >= c.getDocument().getLength() - 1 |
|
|
|
|
|
|
|
|| getPosRect(c, offs1 + 1).y > posOffs1.y; |
|
|
|
|
|
|
|
boolean isStartOfLine = offs0 == 0 |
|
|
|
|
|
|
|
|| getPosRect(c, offs0 - 1).y < posOffs0.y; |
|
|
|
|
|
|
|
|
|
|
|
Rectangle layerRect = getRect(posOffs0, posOffs1); |
|
|
|
Rectangle layerRect = getRect(posOffs0, posOffs1); |
|
|
|
Rectangle previousLineRect = getRect(prevStart, prevEnd); |
|
|
|
Rectangle previousLineRect = getRect(prevStart, prevEnd); |
|
|
|
Rectangle currentLineRect = getLineRect(c, currentLineStart, currentLineEnd); |
|
|
|
Rectangle currentLineRect = getLineRect(c, currentLineStart, currentLineEnd); |
|
|
@ -289,7 +298,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
|
|
|
|
|
|
|
|
boolean paintPreviousLine = false; |
|
|
|
boolean paintPreviousLine = false; |
|
|
|
|
|
|
|
|
|
|
|
if (isLineExtendingEnabled()) { |
|
|
|
if (extendLines) { |
|
|
|
// Adjust the line rects for the adjacent lines for correct rounded corner placement.
|
|
|
|
// Adjust the line rects for the adjacent lines for correct rounded corner placement.
|
|
|
|
extendLine(c, ins, previousLineRect, |
|
|
|
extendLine(c, ins, previousLineRect, |
|
|
|
hasLineAbove && previousLineStart >= c.getSelectionStart(), |
|
|
|
hasLineAbove && previousLineStart >= c.getSelectionStart(), |
|
|
@ -303,12 +312,15 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
hasLineBelow && nextLineStart >= c.getSelectionStart(), |
|
|
|
hasLineBelow && nextLineStart >= c.getSelectionStart(), |
|
|
|
extendNextRight); |
|
|
|
extendNextRight); |
|
|
|
|
|
|
|
|
|
|
|
paintPreviousLine = hasLineAbove && previousLineStart == previousLineEnd; |
|
|
|
paintPreviousLine = hasLineAbove |
|
|
|
|
|
|
|
&& (previousLineStart == previousLineEnd || previousLineEnd == c.getSelectionStart()); |
|
|
|
previousLineVisible = hasLineAbove; |
|
|
|
previousLineVisible = hasLineAbove; |
|
|
|
if (nextLineRect.y != posEnd.y) nextLineVisible = hasLineBelow; |
|
|
|
if (nextLineRect.y != posEnd.y) nextLineVisible = hasLineBelow; |
|
|
|
|
|
|
|
|
|
|
|
boolean extendRight = isPaintingPreceding || (hasLineBelow && (endX(layerRect) == endX(currentLineRect))); |
|
|
|
boolean extendRight = isPaintingPreceding || (hasLineBelow && (endX(layerRect) == endX(currentLineRect))); |
|
|
|
|
|
|
|
extendRight &= offs1 < c.getSelectionEnd(); |
|
|
|
boolean extendLeft = isPaintingPreceding || (hasLineAbove && startX(layerRect) == startX(currentLineRect)); |
|
|
|
boolean extendLeft = isPaintingPreceding || (hasLineAbove && startX(layerRect) == startX(currentLineRect)); |
|
|
|
|
|
|
|
extendLeft &= offs0 > c.getSelectionStart(); |
|
|
|
|
|
|
|
|
|
|
|
extendLine(c, ins, layerRect, extendLeft, extendRight); |
|
|
|
extendLine(c, ins, layerRect, extendLeft, extendRight); |
|
|
|
extendLine(c, ins, currentLineRect, extendLeft, extendRight); |
|
|
|
extendLine(c, ins, currentLineRect, extendLeft, extendRight); |
|
|
@ -316,9 +328,8 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
if (isPaintingPreceding) layerRect.height = currentLineRect.height; |
|
|
|
if (isPaintingPreceding) layerRect.height = currentLineRect.height; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean rounded = isRounded(); |
|
|
|
boolean canRoundLeft = rounded && (isStartOfLine || startX(currentLineRect) == startX(layerRect)); |
|
|
|
boolean canRoundLeft = rounded && startX(currentLineRect) == startX(layerRect); |
|
|
|
boolean canRoundRight = rounded && (isEndOfLine || endX(currentLineRect) == endX(layerRect)); |
|
|
|
boolean canRoundRight = rounded && endX(currentLineRect) == endX(layerRect); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean roundedTopLeft = !previousLineVisible || leftRoundedVisible(currentLineRect, previousLineRect); |
|
|
|
boolean roundedTopLeft = !previousLineVisible || leftRoundedVisible(currentLineRect, previousLineRect); |
|
|
|
boolean roundedTopRight = !previousLineVisible || rightRoundedVisible(currentLineRect, previousLineRect); |
|
|
|
boolean roundedTopRight = !previousLineVisible || rightRoundedVisible(currentLineRect, previousLineRect); |
|
|
@ -345,22 +356,26 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
canRoundRight && arcBottomRight); |
|
|
|
canRoundRight && arcBottomRight); |
|
|
|
|
|
|
|
|
|
|
|
if (paintPreviousLine && !isPaintingPreceding) { |
|
|
|
if (paintPreviousLine && !isPaintingPreceding) { |
|
|
|
Rectangle prev = paintRoundedLayer(g, c, previousLineStart, previousLineEnd, context, true); |
|
|
|
Rectangle prev = paintRoundedLayer(g, c, |
|
|
|
|
|
|
|
Math.max(previousLineStart, c.getSelectionStart()), |
|
|
|
|
|
|
|
Math.min(previousLineEnd, c.getSelectionEnd()), |
|
|
|
|
|
|
|
context, |
|
|
|
|
|
|
|
rounded, extendLines, true); |
|
|
|
convexHull(r, prev); |
|
|
|
convexHull(r, prev); |
|
|
|
} |
|
|
|
} |
|
|
|
return r; |
|
|
|
return r; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void extendLine(final JTextComponent c, final Insets ins, final Rectangle previousLineRect, |
|
|
|
private void extendLine(final JTextComponent c, final Insets ins, final Rectangle rect, |
|
|
|
final boolean extendLeft, final boolean extendRight) { |
|
|
|
final boolean extendLeft, final boolean extendRight) { |
|
|
|
if (extendRight || extendLeft) { |
|
|
|
if (extendRight || extendLeft) { |
|
|
|
int x = startX(previousLineRect); |
|
|
|
int x = startX(rect); |
|
|
|
if (extendRight) { |
|
|
|
if (extendRight) { |
|
|
|
previousLineRect.width = c.getWidth() - ins.left - x; |
|
|
|
rect.width = c.getWidth() - ins.left - x; |
|
|
|
} |
|
|
|
} |
|
|
|
if (extendLeft) { |
|
|
|
if (extendLeft) { |
|
|
|
previousLineRect.width = previousLineRect.x + previousLineRect.width - ins.left; |
|
|
|
rect.width = rect.x + rect.width - ins.left; |
|
|
|
previousLineRect.x = ins.left; |
|
|
|
rect.x = ins.left; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -499,19 +514,11 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
* First paint the whole rounded rectangle and remove any non visible arcs. |
|
|
|
* First paint the whole rounded rectangle and remove any non visible arcs. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
g.fillRoundRect(r.x, r.y, r.width, r.height, aw, ah); |
|
|
|
g.fillRoundRect(r.x, r.y, r.width, r.height, aw, ah); |
|
|
|
if (!topLeft && !topRight) { |
|
|
|
|
|
|
|
g.fillRect(r.x, r.y, r.width, ah); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (!topLeft) g.fillRect(r.x, r.y, aw, ah); |
|
|
|
if (!topLeft) g.fillRect(r.x, r.y, aw, ah); |
|
|
|
if (!topRight) g.fillRect(r.x + r.width - aw, r.y, aw, ah); |
|
|
|
if (!topRight) g.fillRect(r.x + r.width - aw, r.y, aw, ah); |
|
|
|
} |
|
|
|
|
|
|
|
if (!bottomLeft && !bottomRight) { |
|
|
|
|
|
|
|
g.fillRect(r.x, r.y + r.height - ah, r.width, ah); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (!bottomLeft) g.fillRect(r.x, r.y + r.height - ah, aw, ah); |
|
|
|
if (!bottomLeft) g.fillRect(r.x, r.y + r.height - ah, aw, ah); |
|
|
|
if (!bottomRight) g.fillRect(r.x + r.width - aw, r.y + r.height - ah, aw, ah); |
|
|
|
if (!bottomRight) g.fillRect(r.x + r.width - aw, r.y + r.height - ah, aw, ah); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
context.restoreClip(); |
|
|
|
context.restoreClip(); |
|
|
|
return shape; |
|
|
|
return shape; |
|
|
|
} |
|
|
|
} |
|
|
@ -519,6 +526,7 @@ public class DarkHighlightPainter extends DefaultHighlighter.DefaultHighlightPai |
|
|
|
private Rectangle paintArcs(final Graphics2D g, final GraphicsContext context, final Rectangle r, |
|
|
|
private Rectangle paintArcs(final Graphics2D g, final GraphicsContext context, final Rectangle r, |
|
|
|
final boolean topLeft, final boolean topRight, |
|
|
|
final boolean topLeft, final boolean topRight, |
|
|
|
final boolean bottomLeft, final boolean bottomRight) { |
|
|
|
final boolean bottomLeft, final boolean bottomRight) { |
|
|
|
|
|
|
|
if (r.isEmpty()) return r; |
|
|
|
Rectangle alloc = new Rectangle(r); |
|
|
|
Rectangle alloc = new Rectangle(r); |
|
|
|
if (topLeft || bottomLeft) { |
|
|
|
if (topLeft || bottomLeft) { |
|
|
|
alloc.x -= arcSize; |
|
|
|
alloc.x -= arcSize; |
|
|
|