1 /* |
|
2 * Copyright (c) 2009, 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 * @bug 6539700 |
|
27 * @summary test that the long space-less lines are correctly soft-wrapped |
|
28 * @author Sergey Groznyh |
|
29 * @run main bug6539700 |
|
30 */ |
|
31 |
|
32 import javax.swing.JEditorPane; |
|
33 import javax.swing.JFrame; |
|
34 import javax.swing.SwingUtilities; |
|
35 import javax.swing.text.ParagraphView; |
|
36 import javax.swing.text.View; |
|
37 |
|
38 public class bug6539700 { |
|
39 static JFrame f; |
|
40 static JEditorPane ep; |
|
41 static String text = "AAAAAAAA<b>AAAAAA</b>AAAAAAAA<b>AAAAAAAAA</b>" + |
|
42 "AA<b>AAA</b>AAAAAAAAA"; |
|
43 static int size = 100; |
|
44 static Class rowClass = null; |
|
45 |
|
46 static void createContentPane() { |
|
47 ep = new JEditorPane(); |
|
48 ep.setContentType("text/html"); |
|
49 ep.setEditable(false); |
|
50 ep.setText(text); |
|
51 f = new JFrame(); |
|
52 f.setSize(size, 2 * size); |
|
53 f.add(ep); |
|
54 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
55 f.setVisible(true); |
|
56 } |
|
57 |
|
58 static void checkRows(View v, boolean last) { |
|
59 int width = (int) v.getPreferredSpan(View.X_AXIS); |
|
60 |
|
61 if (v.getClass() == rowClass) { |
|
62 // Row width shouldn't exceed the container width |
|
63 if (width > size) { |
|
64 throw new RuntimeException("too long row: " + width); |
|
65 } |
|
66 |
|
67 // Row shouldn't be too short (except for the last one) |
|
68 if (!last) { |
|
69 if (width < size * 2 / 3) { |
|
70 throw new RuntimeException("too short row: " + width); |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 int n = v.getViewCount(); |
|
76 if (n > 0) { |
|
77 for (int i = 0; i < n; i++) { |
|
78 View c = v.getView(i); |
|
79 checkRows(c, i == n - 1); |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 public static void main(String[] argv) { |
|
85 try { |
|
86 SwingUtilities.invokeAndWait(new Runnable() { |
|
87 public void run() { |
|
88 createContentPane(); |
|
89 } |
|
90 }); |
|
91 } catch (Exception ex) { |
|
92 throw new RuntimeException(ex); |
|
93 } |
|
94 |
|
95 Class[] pvchildren = ParagraphView.class.getDeclaredClasses(); |
|
96 for (Class c : pvchildren) { |
|
97 if (c.getName().equals("javax.swing.text.ParagraphView$Row")) { |
|
98 rowClass = c; |
|
99 break; |
|
100 } |
|
101 } |
|
102 if (rowClass == null) { |
|
103 throw new RuntimeException("can't find ParagraphView.Row class"); |
|
104 } |
|
105 |
|
106 SwingUtilities.invokeLater(new Runnable() { |
|
107 public void run() { |
|
108 checkRows(ep.getUI().getRootView(ep), true); |
|
109 } |
|
110 }); |
|
111 |
|
112 System.out.println("OK"); |
|
113 } |
|
114 } |
|