1 /*
2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @key headful
27 * @bug 4506788 7147408
28 * @summary Tests if cursor gets stuck after insertion a character
29 * @author Denis Sharypov
30 * @run applet bug4506788.html
31 */
32
33 import java.awt.*;
34 import java.awt.event.*;
35 import java.lang.reflect.InvocationTargetException;
36 import javax.swing.*;
37 import javax.swing.event.*;
38 import javax.swing.text.*;
39
40 public class bug4506788 extends JApplet {
41
42 private volatile boolean passed = false;
43 private JEditorPane jep;
44
45 @Override
46 public void init() {
47 try {
48 SwingUtilities.invokeAndWait(new Runnable() {
49 @Override
50 public void run() {
51 createAndShowGUI();
52 }
53 });
54 } catch (InterruptedException | InvocationTargetException ex) {
55 ex.printStackTrace();
56 throw new RuntimeException("FAILED: SwingUtilities.invokeAndWait method failed then creating and showing GUI");
57 }
58 }
59
60 @Override
61 public void start() {
62 Robot robot;
63 try {
64 robot = new Robot();
65 } catch (AWTException e) {
66 throw new RuntimeException("Robot could not be created");
67 }
68
69 robot.waitForIdle();
70
71 Point p;
72 try {
73 p = getJEPLocOnScreen();
74 } catch (Exception e) {
75 throw new RuntimeException("Could not get JEditorPane location on screen");
76 }
77
78 robot.setAutoDelay(50);
79 robot.mouseMove(p.x, p.y);
80 robot.mousePress(InputEvent.BUTTON1_MASK);
112 private void createAndShowGUI() {
113 jep = new JEditorPane();
114 String text = "abc";
115 JFrame f = new JFrame();
116 jep.setEditorKit(new StyledEditorKit());
117 jep.setText(text);
118 jep.addCaretListener(new CaretListener() {
119 @Override
120 public void caretUpdate(CaretEvent e) {
121 passed = (e.getDot() == 3);
122 }
123 });
124
125 DefaultStyledDocument doc = (DefaultStyledDocument) jep.getDocument();
126 MutableAttributeSet atr = new SimpleAttributeSet();
127 StyleConstants.setBold(atr, true);
128 doc.setCharacterAttributes(1, 1, atr, false);
129
130 f.getContentPane().add(jep);
131 f.setSize(100, 100);
132 f.setVisible(true);
133 }
134 }
|
1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @key headful
27 * @bug 4506788 7147408
28 * @summary Tests if cursor gets stuck after insertion a character
29 * @run main bug4506788
30 */
31
32 import java.awt.*;
33 import java.awt.event.*;
34 import java.lang.reflect.InvocationTargetException;
35 import javax.swing.*;
36 import javax.swing.event.*;
37 import javax.swing.text.*;
38
39 public class bug4506788 {
40
41 private volatile boolean passed = false;
42 private JEditorPane jep;
43
44 public static void main(final String[] args) {
45 bug4506788 app = new bug4506788();
46 app.init();
47 app.start();
48 }
49
50 public void init() {
51 try {
52 SwingUtilities.invokeAndWait(new Runnable() {
53 @Override
54 public void run() {
55 createAndShowGUI();
56 }
57 });
58 } catch (InterruptedException | InvocationTargetException ex) {
59 ex.printStackTrace();
60 throw new RuntimeException("FAILED: SwingUtilities.invokeAndWait method failed then creating and showing GUI");
61 }
62 }
63
64 public void start() {
65 Robot robot;
66 try {
67 robot = new Robot();
68 } catch (AWTException e) {
69 throw new RuntimeException("Robot could not be created");
70 }
71
72 robot.waitForIdle();
73
74 Point p;
75 try {
76 p = getJEPLocOnScreen();
77 } catch (Exception e) {
78 throw new RuntimeException("Could not get JEditorPane location on screen");
79 }
80
81 robot.setAutoDelay(50);
82 robot.mouseMove(p.x, p.y);
83 robot.mousePress(InputEvent.BUTTON1_MASK);
115 private void createAndShowGUI() {
116 jep = new JEditorPane();
117 String text = "abc";
118 JFrame f = new JFrame();
119 jep.setEditorKit(new StyledEditorKit());
120 jep.setText(text);
121 jep.addCaretListener(new CaretListener() {
122 @Override
123 public void caretUpdate(CaretEvent e) {
124 passed = (e.getDot() == 3);
125 }
126 });
127
128 DefaultStyledDocument doc = (DefaultStyledDocument) jep.getDocument();
129 MutableAttributeSet atr = new SimpleAttributeSet();
130 StyleConstants.setBold(atr, true);
131 doc.setCharacterAttributes(1, 1, atr, false);
132
133 f.getContentPane().add(jep);
134 f.setSize(100, 100);
135 f.setLocationRelativeTo(null);
136 f.setVisible(true);
137 }
138 }
|