mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
Use Java 9 TextUI.modelToView2D()
This commit is contained in:
parent
861a218c9b
commit
f39b490061
@ -1,13 +1,12 @@
|
|||||||
|
|
||||||
package net.filebot.ui.rename;
|
package net.filebot.ui.rename;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -16,22 +15,20 @@ import javax.swing.plaf.TextUI;
|
|||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.Highlighter;
|
import javax.swing.text.Highlighter;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
|
import javax.swing.text.Position.Bias;
|
||||||
|
|
||||||
import net.filebot.util.ui.GradientStyle;
|
import net.filebot.util.ui.GradientStyle;
|
||||||
|
|
||||||
|
|
||||||
class CharacterHighlightPainter implements Highlighter.HighlightPainter {
|
class CharacterHighlightPainter implements Highlighter.HighlightPainter {
|
||||||
|
|
||||||
private Color gradientBeginColor;
|
private Color gradientBeginColor;
|
||||||
private Color gradientEndColor;
|
private Color gradientEndColor;
|
||||||
|
|
||||||
|
|
||||||
public CharacterHighlightPainter(Color gradientBeginColor, Color gradientEndColor) {
|
public CharacterHighlightPainter(Color gradientBeginColor, Color gradientEndColor) {
|
||||||
this.gradientBeginColor = gradientBeginColor;
|
this.gradientBeginColor = gradientBeginColor;
|
||||||
this.gradientEndColor = gradientEndColor;
|
this.gradientEndColor = gradientEndColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g, int offset1, int offset2, Shape bounds, JTextComponent c) {
|
public void paint(Graphics g, int offset1, int offset2, Shape bounds, JTextComponent c) {
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
@ -39,20 +36,17 @@ class CharacterHighlightPainter implements Highlighter.HighlightPainter {
|
|||||||
try {
|
try {
|
||||||
// determine locations
|
// determine locations
|
||||||
TextUI mapper = c.getUI();
|
TextUI mapper = c.getUI();
|
||||||
Rectangle p1 = mapper.modelToView(c, offset1);
|
Rectangle2D p1 = mapper.modelToView2D(c, offset1, Bias.Backward);
|
||||||
Rectangle p2 = mapper.modelToView(c, offset2);
|
Rectangle2D p2 = mapper.modelToView2D(c, offset2, Bias.Backward);
|
||||||
|
|
||||||
Rectangle r = p1.union(p2);
|
Rectangle2D r = p1.createUnion(p2);
|
||||||
|
double w = r.getWidth() + 1;
|
||||||
|
double h = r.getHeight();
|
||||||
|
double x = r.getX() - 1;
|
||||||
|
double y = r.getY();
|
||||||
|
double arch = 5f;
|
||||||
|
|
||||||
float w = r.width + 1;
|
RoundRectangle2D shape = new RoundRectangle2D.Double(x, y, w, h, arch, arch);
|
||||||
float h = r.height;
|
|
||||||
|
|
||||||
float x = r.x - 1;
|
|
||||||
float y = r.y;
|
|
||||||
|
|
||||||
float arch = 5f;
|
|
||||||
|
|
||||||
RoundRectangle2D shape = new RoundRectangle2D.Float(x, y, w, h, arch, arch);
|
|
||||||
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g2d.setPaint(GradientStyle.TOP_TO_BOTTOM.getGradientPaint(shape, gradientBeginColor, gradientEndColor));
|
g2d.setPaint(GradientStyle.TOP_TO_BOTTOM.getGradientPaint(shape, gradientBeginColor, gradientEndColor));
|
||||||
|
Loading…
Reference in New Issue
Block a user