From f39b490061768efb693a1f6f5c2319db960673f5 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 16 Oct 2017 21:18:40 +0200 Subject: [PATCH] Use Java 9 TextUI.modelToView2D() --- .../ui/rename/CharacterHighlightPainter.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/source/net/filebot/ui/rename/CharacterHighlightPainter.java b/source/net/filebot/ui/rename/CharacterHighlightPainter.java index 3480a1b5..ffae21d8 100644 --- a/source/net/filebot/ui/rename/CharacterHighlightPainter.java +++ b/source/net/filebot/ui/rename/CharacterHighlightPainter.java @@ -1,13 +1,12 @@ package net.filebot.ui.rename; - import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.Shape; +import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; import java.util.logging.Level; import java.util.logging.Logger; @@ -16,22 +15,20 @@ import javax.swing.plaf.TextUI; import javax.swing.text.BadLocationException; import javax.swing.text.Highlighter; import javax.swing.text.JTextComponent; +import javax.swing.text.Position.Bias; import net.filebot.util.ui.GradientStyle; - class CharacterHighlightPainter implements Highlighter.HighlightPainter { private Color gradientBeginColor; private Color gradientEndColor; - public CharacterHighlightPainter(Color gradientBeginColor, Color gradientEndColor) { this.gradientBeginColor = gradientBeginColor; this.gradientEndColor = gradientEndColor; } - @Override public void paint(Graphics g, int offset1, int offset2, Shape bounds, JTextComponent c) { Graphics2D g2d = (Graphics2D) g; @@ -39,27 +36,24 @@ class CharacterHighlightPainter implements Highlighter.HighlightPainter { try { // determine locations TextUI mapper = c.getUI(); - Rectangle p1 = mapper.modelToView(c, offset1); - Rectangle p2 = mapper.modelToView(c, offset2); + Rectangle2D p1 = mapper.modelToView2D(c, offset1, Bias.Backward); + 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; - 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); + RoundRectangle2D shape = new RoundRectangle2D.Double(x, y, w, h, arch, arch); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(GradientStyle.TOP_TO_BOTTOM.getGradientPaint(shape, gradientBeginColor, gradientEndColor)); g2d.fill(shape); } catch (BadLocationException e) { - //should not happen + // should not happen Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); } }