author | martin |
Wed, 02 Sep 2015 14:11:50 -0700 | |
changeset 32427 | c22b7e41adf3 |
parent 27764 | 4e79ff3e0602 |
child 40128 | e635645d2a8a |
permissions | -rw-r--r-- |
27267 | 1 |
/* |
2 |
* Copyright (c) 2014, 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 |
/* @test |
|
25 |
* @bug 8058120 |
|
26 |
* @summary Rendering / caret errors with HTMLDocument |
|
27 |
* @author Dmitry Markov |
|
28 |
* @run main bug8058120 |
|
29 |
*/ |
|
30 |
||
31 |
import javax.swing.*; |
|
32 |
import javax.swing.text.Element; |
|
33 |
import javax.swing.text.html.HTML; |
|
34 |
import javax.swing.text.html.HTMLDocument; |
|
35 |
import javax.swing.text.html.HTMLEditorKit; |
|
36 |
import java.awt.*; |
|
37 |
||
38 |
public class bug8058120 { |
|
39 |
private static HTMLDocument document = null; |
|
40 |
private static final String text = "<p id = 'ab'>ab</p>"; |
|
41 |
private static final String textToInsert = "c"; |
|
42 |
||
43 |
public static void main(String[] args) { |
|
27764
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
44 |
Robot robot; |
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
45 |
try { |
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
46 |
robot = new Robot(); |
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
47 |
}catch(Exception ex) { |
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
48 |
ex.printStackTrace(); |
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
49 |
throw new RuntimeException("Unexpected failure"); |
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
50 |
} |
27267 | 51 |
SwingUtilities.invokeLater(new Runnable() { |
52 |
@Override |
|
53 |
public void run() { |
|
54 |
createAndShowGUI(); |
|
55 |
} |
|
56 |
}); |
|
57 |
||
27764
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
58 |
robot.waitForIdle(); |
27267 | 59 |
|
60 |
SwingUtilities.invokeLater(new Runnable() { |
|
61 |
@Override |
|
62 |
public void run() { |
|
63 |
try { |
|
64 |
document.insertAfterEnd(document.getElement("ab"), textToInsert); |
|
65 |
} catch (Exception ex) { |
|
66 |
throw new RuntimeException(ex); |
|
67 |
} |
|
68 |
} |
|
69 |
}); |
|
70 |
||
27764
4e79ff3e0602
8063106: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 1
yan
parents:
27267
diff
changeset
|
71 |
robot.waitForIdle(); |
27267 | 72 |
|
73 |
SwingUtilities.invokeLater(new Runnable() { |
|
74 |
@Override |
|
75 |
public void run() { |
|
76 |
Element parent = document.getElement("ab").getParentElement(); |
|
77 |
int count = parent.getElementCount(); |
|
78 |
if (count != 2) { |
|
79 |
throw new RuntimeException("Test Failed! Unexpected Element count = "+count); |
|
80 |
} |
|
81 |
Element insertedElement = parent.getElement(count - 1); |
|
82 |
if (!HTML.Tag.IMPLIED.toString().equals(insertedElement.getName())) { |
|
83 |
throw new RuntimeException("Test Failed! Inserted text is not wrapped by " + HTML.Tag.IMPLIED + " tag"); |
|
84 |
} |
|
85 |
} |
|
86 |
}); |
|
87 |
} |
|
88 |
||
89 |
private static void createAndShowGUI() { |
|
90 |
try { |
|
91 |
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); |
|
92 |
} catch (Exception ex) { |
|
93 |
throw new RuntimeException(ex); |
|
94 |
} |
|
95 |
||
96 |
JFrame frame = new JFrame("bug8058120"); |
|
97 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
98 |
||
99 |
JEditorPane editorPane = new JEditorPane(); |
|
100 |
editorPane.setContentType("text/html"); |
|
101 |
editorPane.setEditorKit(new HTMLEditorKit()); |
|
102 |
||
103 |
document = (HTMLDocument) editorPane.getDocument(); |
|
104 |
||
105 |
editorPane.setText(text); |
|
106 |
||
107 |
frame.add(editorPane); |
|
108 |
frame.setSize(200, 200); |
|
109 |
frame.setVisible(true); |
|
110 |
} |
|
111 |
} |