<Swing Dev> [9] Review request for 8163124 Add floating point API support to javax.swing.text.Caret
Alexandr Scherbatiy
alexandr.scherbatiy at oracle.com
Tue Sep 20 12:22:39 UTC 2016
On 9/20/2016 2:02 PM, Semyon Sadetsky wrote:
> Thanks, that helped.
>
> Did you think about changing the DefaultCaret class to use the new 2D
> API in case it is allowed for the component ?
DefaultCaret class extends Rectangle so it always uses int coordinates.
I filled an enhancement to support new floating point version of the
caret.
JDK-8163174 Add DefaultCaret2D which supports floating point API
https://bugs.openjdk.java.net/browse/JDK-8163174
Thanks,
Alexandr.
>
> --Semyon
>
>
> On 19.09.2016 22:43, Alexandr Scherbatiy wrote:
>>
>> This is the known issue: JDK-8163175 PlainView.modelToView() method
>> should return Rectangle2D
>> It is included into the fix JDK-8156217 Selected text is shifted on
>> HiDPI display.
>>
>> You can apply the fix [1] JDK-8156217 to the JDK and try the proposed
>> sample.
>> I get the results [2] for scale 2x and [3] for scale 8x.
>>
>> [1] http://cr.openjdk.java.net/~alexsch/8156217/webrev.07/all
>> [2]
>> http://cr.openjdk.java.net/~alexsch/8156217/screenshots/model-to-view-2x.png
>> [3]
>> http://cr.openjdk.java.net/~alexsch/8156217/screenshots/model-to-view-8x.png
>>
>> Thanks,
>> Alexandr.
>>
>> On 9/15/2016 1:49 PM, Semyon Sadetsky wrote:
>>> 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