author | alexsch |
Thu, 03 Nov 2016 18:43:55 +0300 | |
changeset 42193 | f7550ec880cf |
permissions | -rw-r--r-- |
42193
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
1 |
/* |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
4 |
* |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
8 |
* |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
13 |
* accompanied this code). |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
14 |
* |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
18 |
* |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
21 |
* questions. |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
22 |
*/ |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
23 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
24 |
import java.awt.Color; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
25 |
import java.awt.GridBagConstraints; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
26 |
import java.awt.GridBagLayout; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
27 |
import java.awt.Insets; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
28 |
import java.awt.event.ActionEvent; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
29 |
import java.awt.event.ActionListener; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
30 |
import java.awt.event.WindowAdapter; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
31 |
import java.awt.event.WindowEvent; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
32 |
import java.util.HashMap; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
33 |
import java.util.concurrent.CountDownLatch; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
34 |
import java.util.concurrent.TimeUnit; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
35 |
import javax.swing.JButton; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
36 |
import javax.swing.JComponent; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
37 |
import javax.swing.JFrame; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
38 |
import javax.swing.JPanel; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
39 |
import javax.swing.JScrollPane; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
40 |
import javax.swing.JTextArea; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
41 |
import javax.swing.JTextPane; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
42 |
import javax.swing.JViewport; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
43 |
import javax.swing.SwingUtilities; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
44 |
import javax.swing.UIManager; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
45 |
import javax.swing.text.BadLocationException; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
46 |
import javax.swing.text.DefaultStyledDocument; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
47 |
import javax.swing.text.Style; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
48 |
import javax.swing.text.StyleConstants; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
49 |
import javax.swing.text.StyleContext; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
50 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
51 |
/* |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
52 |
* @test |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
53 |
* @bug 8164032 8156217 |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
54 |
* @summary JViewport backing store image is not scaled on HiDPI display |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
55 |
* @run main/manual JViewPortBackingStoreImageTest |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
56 |
*/ |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
57 |
public class JViewPortBackingStoreImageTest { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
58 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
59 |
private static volatile boolean testResult = false; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
60 |
private static volatile CountDownLatch countDownLatch; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
61 |
private static final String INSTRUCTIONS = "INSTRUCTIONS:\n\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
62 |
+ "Verify text is drawn with high resolution and text selection " |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
63 |
+ "is not shifted when JViewPort is used on HiDPI display.\n\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
64 |
+ "If the display does not support HiDPI mode press PASS.\n\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
65 |
+ "1. Check that the text does not have low resolution.\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
66 |
+ "If no, press FAIL.\n\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
67 |
+ "2. Select the current text from the end to the beginning.\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
68 |
+ "\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
69 |
+ "If the text is slightly shiftted from one side to another\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
70 |
+ "and back during selection press Fail.\n" |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
71 |
+ "Otherwise, press Pass."; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
72 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
73 |
private static DefaultStyledDocument doc; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
74 |
private static StyleContext styles; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
75 |
private static HashMap<String, Style> contentAttributes; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
76 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
77 |
public static void main(String args[]) throws Exception { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
78 |
countDownLatch = new CountDownLatch(1); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
79 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
80 |
SwingUtilities.invokeLater(JViewPortBackingStoreImageTest::createUI); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
81 |
countDownLatch.await(15, TimeUnit.MINUTES); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
82 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
83 |
if (!testResult) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
84 |
throw new RuntimeException("Test fails!"); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
85 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
86 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
87 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
88 |
private static void createUI() { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
89 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
90 |
try { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
91 |
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
92 |
} catch (Exception e) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
93 |
throw new RuntimeException(e); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
94 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
95 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
96 |
final JFrame mainFrame = new JFrame(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
97 |
GridBagLayout layout = new GridBagLayout(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
98 |
JPanel mainControlPanel = new JPanel(layout); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
99 |
JPanel resultButtonPanel = new JPanel(layout); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
100 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
101 |
GridBagConstraints gbc = new GridBagConstraints(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
102 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
103 |
gbc.gridx = 0; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
104 |
gbc.gridy = 0; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
105 |
gbc.insets = new Insets(5, 15, 5, 15); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
106 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
107 |
mainControlPanel.add(createComponent(), gbc); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
108 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
109 |
JTextArea instructionTextArea = new JTextArea(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
110 |
instructionTextArea.setText(INSTRUCTIONS); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
111 |
instructionTextArea.setEditable(false); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
112 |
instructionTextArea.setBackground(Color.white); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
113 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
114 |
gbc.gridx = 0; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
115 |
gbc.gridy = 1; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
116 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
117 |
mainControlPanel.add(instructionTextArea, gbc); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
118 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
119 |
JButton passButton = new JButton("Pass"); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
120 |
passButton.setActionCommand("Pass"); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
121 |
passButton.addActionListener((ActionEvent e) -> { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
122 |
testResult = true; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
123 |
mainFrame.dispose(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
124 |
countDownLatch.countDown(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
125 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
126 |
}); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
127 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
128 |
JButton failButton = new JButton("Fail"); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
129 |
failButton.setActionCommand("Fail"); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
130 |
failButton.addActionListener(new ActionListener() { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
131 |
@Override |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
132 |
public void actionPerformed(ActionEvent e) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
133 |
mainFrame.dispose(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
134 |
countDownLatch.countDown(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
135 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
136 |
}); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
137 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
138 |
gbc.gridx = 0; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
139 |
gbc.gridy = 0; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
140 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
141 |
resultButtonPanel.add(passButton, gbc); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
142 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
143 |
gbc.gridx = 1; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
144 |
gbc.gridy = 0; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
145 |
resultButtonPanel.add(failButton, gbc); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
146 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
147 |
gbc.gridx = 0; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
148 |
gbc.gridy = 2; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
149 |
mainControlPanel.add(resultButtonPanel, gbc); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
150 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
151 |
mainFrame.add(mainControlPanel); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
152 |
mainFrame.pack(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
153 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
154 |
mainFrame.addWindowListener(new WindowAdapter() { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
155 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
156 |
@Override |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
157 |
public void windowClosing(WindowEvent e) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
158 |
mainFrame.dispose(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
159 |
countDownLatch.countDown(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
160 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
161 |
}); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
162 |
mainFrame.setVisible(true); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
163 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
164 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
165 |
private static JComponent createComponent() { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
166 |
createStyles(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
167 |
for (int i = 0; i < data.length; i++) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
168 |
Paragraph p = data[i]; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
169 |
addParagraph(p); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
170 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
171 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
172 |
JTextPane textPane = new JTextPane(doc); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
173 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
174 |
JScrollPane scroller = new JScrollPane(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
175 |
JViewport port = scroller.getViewport(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
176 |
port.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
177 |
port.add(textPane); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
178 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
179 |
return scroller; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
180 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
181 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
182 |
static void createStyles() { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
183 |
styles = new StyleContext(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
184 |
doc = new DefaultStyledDocument(styles); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
185 |
contentAttributes = new HashMap<>(); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
186 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
187 |
// no attributes defined |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
188 |
Style s = styles.addStyle(null, null); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
189 |
contentAttributes.put("none", s); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
190 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
191 |
Style def = styles.getStyle(StyleContext.DEFAULT_STYLE); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
192 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
193 |
Style heading = styles.addStyle("heading", def); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
194 |
StyleConstants.setFontFamily(heading, "SansSerif"); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
195 |
StyleConstants.setBold(heading, true); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
196 |
StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
197 |
StyleConstants.setSpaceAbove(heading, 10); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
198 |
StyleConstants.setSpaceBelow(heading, 10); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
199 |
StyleConstants.setFontSize(heading, 18); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
200 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
201 |
// Title |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
202 |
Style sty = styles.addStyle("title", heading); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
203 |
StyleConstants.setFontSize(sty, 32); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
204 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
205 |
// author |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
206 |
sty = styles.addStyle("author", heading); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
207 |
StyleConstants.setItalic(sty, true); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
208 |
StyleConstants.setSpaceBelow(sty, 25); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
209 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
210 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
211 |
static void addParagraph(Paragraph p) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
212 |
try { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
213 |
Style s = null; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
214 |
for (int i = 0; i < p.data.length; i++) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
215 |
AttributedContent run = p.data[i]; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
216 |
s = contentAttributes.get(run.attr); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
217 |
doc.insertString(doc.getLength(), run.content, s); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
218 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
219 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
220 |
Style ls = styles.getStyle(p.logical); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
221 |
doc.setLogicalStyle(doc.getLength() - 1, ls); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
222 |
doc.insertString(doc.getLength(), "\n", null); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
223 |
} catch (BadLocationException e) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
224 |
throw new RuntimeException(e); |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
225 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
226 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
227 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
228 |
private static Paragraph[] data = new Paragraph[]{ |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
229 |
new Paragraph("title", new AttributedContent[]{ |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
230 |
new AttributedContent("none", "ALICE'S ADVENTURES IN WONDERLAND") |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
231 |
}), |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
232 |
new Paragraph("author", new AttributedContent[]{ |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
233 |
new AttributedContent("none", "Lewis Carroll") |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
234 |
}), |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
235 |
new Paragraph("heading", new AttributedContent[]{ |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
236 |
new AttributedContent("alice", " ") |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
237 |
})}; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
238 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
239 |
static class Paragraph { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
240 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
241 |
Paragraph(String logical, AttributedContent[] data) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
242 |
this.logical = logical; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
243 |
this.data = data; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
244 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
245 |
String logical; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
246 |
AttributedContent[] data; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
247 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
248 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
249 |
static class AttributedContent { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
250 |
|
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
251 |
AttributedContent(String attr, String content) { |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
252 |
this.attr = attr; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
253 |
this.content = content; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
254 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
255 |
String attr; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
256 |
String content; |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
257 |
} |
f7550ec880cf
8164032: JViewport backing store image is not scaled on HiDPI display
alexsch
parents:
diff
changeset
|
258 |
} |