|
|
@ -37,6 +37,8 @@ import javax.swing.text.*; |
|
|
|
import javax.swing.text.DefaultHighlighterDark.DarkHighlightPainter; |
|
|
|
import javax.swing.text.DefaultHighlighterDark.DarkHighlightPainter; |
|
|
|
|
|
|
|
|
|
|
|
import com.github.weisj.darklaf.graphics.PaintUtil; |
|
|
|
import com.github.weisj.darklaf.graphics.PaintUtil; |
|
|
|
|
|
|
|
import com.github.weisj.darklaf.ui.text.action.SelectLineAction; |
|
|
|
|
|
|
|
import com.github.weisj.darklaf.ui.text.action.SelectWordAction; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Jannis Weis |
|
|
|
* @author Jannis Weis |
|
|
@ -88,11 +90,6 @@ public class DarkCaret extends DefaultCaret implements UIResource { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void positionCaret(final MouseEvent e) { |
|
|
|
|
|
|
|
super.positionCaret(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isAlwaysVisible() { |
|
|
|
public boolean isAlwaysVisible() { |
|
|
|
return alwaysVisible; |
|
|
|
return alwaysVisible; |
|
|
|
} |
|
|
|
} |
|
|
@ -117,26 +114,32 @@ public class DarkCaret extends DefaultCaret implements UIResource { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public enum CaretStyle { |
|
|
|
public enum CaretStyle { |
|
|
|
VERTICAL_LINE_STYLE(1), |
|
|
|
VERTICAL_LINE_STYLE(1, false), |
|
|
|
UNDERLINE_STYLE(0), |
|
|
|
UNDERLINE_STYLE(1, true), |
|
|
|
BLOCK_STYLE(0), |
|
|
|
BLOCK_STYLE(1, true), |
|
|
|
BLOCK_BORDER_STYLE(0), |
|
|
|
BLOCK_BORDER_STYLE(1, true), |
|
|
|
THICK_VERTICAL_LINE_STYLE(1); |
|
|
|
THICK_VERTICAL_LINE_STYLE(2, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final int size; |
|
|
|
|
|
|
|
private final boolean charWidth; |
|
|
|
|
|
|
|
|
|
|
|
private final int width; |
|
|
|
CaretStyle(final int size, final boolean charWidth) { |
|
|
|
|
|
|
|
this.size = size; |
|
|
|
|
|
|
|
this.charWidth = charWidth; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CaretStyle(final int width) { |
|
|
|
public int getSize() { |
|
|
|
this.width = width; |
|
|
|
return size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getWidth() { |
|
|
|
public boolean isCharacterWidth() { |
|
|
|
return width; |
|
|
|
return charWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public double getWidth() { |
|
|
|
public double getWidth() { |
|
|
|
return style.getWidth(); |
|
|
|
return getStyle().getSize(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -264,15 +267,20 @@ public class DarkCaret extends DefaultCaret implements UIResource { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean isVisible() { |
|
|
|
|
|
|
|
return super.isVisible() || isAlwaysVisible(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void paint(final Graphics g) { |
|
|
|
public void paint(final Graphics g) { |
|
|
|
if (isVisible() || alwaysVisible) { |
|
|
|
if (isVisible()) { |
|
|
|
JTextComponent textArea = getComponent(); |
|
|
|
JTextComponent textArea = getComponent(); |
|
|
|
g.setColor(textArea.getCaretColor()); |
|
|
|
g.setColor(textArea.getCaretColor()); |
|
|
|
TextUI mapper = textArea.getUI(); |
|
|
|
TextUI mapper = textArea.getUI(); |
|
|
|
Rectangle r; |
|
|
|
Rectangle r; |
|
|
|
try { |
|
|
|
try { |
|
|
|
r = mapper.modelToView(textArea, getDot(), Position.Bias.Forward); |
|
|
|
r = mapper.modelToView(textArea, getDot(), getDotBias()); |
|
|
|
} catch (BadLocationException ex) { |
|
|
|
} catch (BadLocationException ex) { |
|
|
|
r = new Rectangle(0, 0, 0, 0); |
|
|
|
r = new Rectangle(0, 0, 0, 0); |
|
|
|
} |
|
|
|
} |
|
|
@ -294,28 +302,25 @@ public class DarkCaret extends DefaultCaret implements UIResource { |
|
|
|
r.y += 1; |
|
|
|
r.y += 1; |
|
|
|
|
|
|
|
|
|
|
|
Color textAreaBg = textArea.getBackground(); |
|
|
|
Color textAreaBg = textArea.getBackground(); |
|
|
|
switch (style) { |
|
|
|
|
|
|
|
case BLOCK_STYLE : |
|
|
|
|
|
|
|
if (textAreaBg == null) { |
|
|
|
if (textAreaBg == null) { |
|
|
|
textAreaBg = Color.white; |
|
|
|
textAreaBg = Color.white; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
switch (style) { |
|
|
|
|
|
|
|
case BLOCK_STYLE : |
|
|
|
g.setXORMode(textAreaBg); |
|
|
|
g.setXORMode(textAreaBg); |
|
|
|
g.fillRect(r.x, r.y, r.width, r.height); |
|
|
|
g.fillRect(r.x, r.y, r.width, r.height); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BLOCK_BORDER_STYLE : |
|
|
|
case BLOCK_BORDER_STYLE : |
|
|
|
PaintUtil.drawRect(g, r.x, r.y, r.width, r.height, 1); |
|
|
|
PaintUtil.drawRect(g, r.x, r.y, r.width, r.height, style.getSize()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case UNDERLINE_STYLE : |
|
|
|
case UNDERLINE_STYLE : |
|
|
|
if (textAreaBg == null) { |
|
|
|
|
|
|
|
textAreaBg = Color.white; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
g.setXORMode(textAreaBg); |
|
|
|
g.setXORMode(textAreaBg); |
|
|
|
int y = r.y + r.height; |
|
|
|
int y = r.y + r.height; |
|
|
|
g.fillRect(r.x, y - 1, r.width, 1); |
|
|
|
g.fillRect(r.x, y - style.getSize(), r.width, style.getSize()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case THICK_VERTICAL_LINE_STYLE : |
|
|
|
case THICK_VERTICAL_LINE_STYLE : |
|
|
|
case VERTICAL_LINE_STYLE : |
|
|
|
case VERTICAL_LINE_STYLE : |
|
|
|
g.fillRect(r.x, r.y, style.getWidth(), r.height); |
|
|
|
g.fillRect(r.x, r.y, style.getSize(), r.height); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -347,7 +352,7 @@ public class DarkCaret extends DefaultCaret implements UIResource { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void validateWidth(final Rectangle rect) { |
|
|
|
private void validateWidth(final Rectangle rect) { |
|
|
|
if (rect != null && rect.width <= 1) { |
|
|
|
if (rect != null && (rect.width <= 1 || getStyle().isCharacterWidth())) { |
|
|
|
JTextComponent textArea = getComponent(); |
|
|
|
JTextComponent textArea = getComponent(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
textArea.getDocument().getText(getDot(), 1, seg); |
|
|
|
textArea.getDocument().getText(getDot(), 1, seg); |
|
|
|