<Swing Dev> [9] Review request for 8163124 Add floating point API support to javax.swing.text.Caret
Semyon Sadetsky
semyon.sadetsky at oracle.com
Thu Sep 15 10:49:20 UTC 2016
Hi Alexander,
Could you run the next test (with x8 scale, for example):
public class New2dApiTest {
public static void main(String[] args) {
JTextArea jTextArea2d = new JTextArea("jksxbqhbxniiiaiiaawww") {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(new Color(255, 0, 0, 50));
for (int i = 0; i < getText().length(); i++) {
try {
g2d.fill(modelToView2D(i));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
};
JTextArea jTextArea = new JTextArea("jksxbqhbxniiiaiiaawww") {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(new Color(0, 0, 255, 50));
for (int i = 0; i < getText().length(); i++) {
try {
g2d.fill(modelToView(i));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
};
JFrame jFrame = new JFrame();
jFrame.getContentPane().setLayout(new GridLayout(2, 1));
jFrame.getContentPane().add(jTextArea2d);
jFrame.getContentPane().add(jTextArea);
jFrame.pack();
jFrame.setVisible(true);
}
}
For some reason I cannot see the difference with the new and old API result.
--Semyon
On 04.08.2016 15:44, Alexandr Scherbatiy wrote:
>
> Hello,
>
> Could you review the fix:
> bug: https://bugs.openjdk.java.net/browse/JDK-8163124
> webrev: http://cr.openjdk.java.net/~alexsch/8163124/webrev.00
>
> The text position can have floating point value on HiDPI display.
> The Caret interface should be updated to allow use floating point
> positions.
>
> The fix adds the following public API with floating point positions:
> javax.swing.text.Caret.getMagicCaretPosition2D()
> javax.swing.text.Caret.setMagicCaretPosition2D(Point2D p)
> javax.swing.text.JTextComponent.modelToView2D(int pos)
> javax.swing.text.JTextComponent.viewToModel2D(Point2D pt)
> javax.swing.text.ParagraphView.getClosestPositionTo(int pos,
> Position.Bias b, Shape a, int direction, Position.Bias[], int
> rowIndex, float x)
>
>
> The fix replaces
> Caret.getMagicCaretPosition()/setMagicCaretPosition(Point p) to
> Caret.getMagicCaretPosition2D()/setMagicCaretPosition2D(Point2D p) in
> all places
> except DefaultCaret because DefaultCaret extends Rectangle so its
> coordinates always have int values.
> I have filled a separated enhancement for this JDK-8163174 Add
> DefaultCaret2D which supports floating point API
>
> To make a custom caret use floating point API it is also necessary
> that PlainView.modelToView() returns a rectangle with floating point
> values. It can be done after the fix
> JDK-8156217 Selected text is shifted on HiDPI display
> which implements Utilities.getTabbedTextWidth(Segment s, FontMetrics
> metrics, float x, TabExpander e, int startOffset) method.
> I have filled a separated issue on it:
> JDK-8163175 PlainView.modelToView() method should return Rectangle2D
>
> Thanks,
> Alexandr.
More information about the swing-dev
mailing list