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 8149371
28 * @summary multi-res. image: -Dsun.java2d.uiScale does not work for Window
29 * icons (some ambiguity for Window.setIconImages()?)
30 * @run main/othervm/manual -Dsun.java2d.uiScale=2 MultiResIconTest
31 */
32 import java.awt.Color;
33 import java.awt.Graphics;
34 import java.awt.GridBagConstraints;
35 import java.awt.GridBagLayout;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.WindowAdapter;
39 import java.awt.event.WindowEvent;
40 import java.awt.image.BaseMultiResolutionImage;
41 import java.awt.image.BufferedImage;
42 import java.util.concurrent.CountDownLatch;
43 import javax.swing.JButton;
44 import javax.swing.JDialog;
45 import javax.swing.JFrame;
46 import javax.swing.JLabel;
47 import javax.swing.JPanel;
48 import javax.swing.SwingUtilities;
49
50 public class MultiResIconTest {
51
52 private static GridBagLayout layout;
53 private static JPanel mainControlPanel;
54 private static JPanel resultButtonPanel;
55 private static JLabel instructionText;
56 private static JButton passButton;
57 private static JButton failButton;
58 private static JDialog f;
59 private static CountDownLatch latch;
60 private static TestFrame frame;
61
62 private static BufferedImage generateImage(int x, Color c) {
63
64 BufferedImage img = new BufferedImage(x, x, BufferedImage.TYPE_INT_RGB);
65 Graphics g = img.getGraphics();
66 g.setColor(c);
67 g.fillRect(0, 0, x, x);
68 g.setColor(Color.WHITE);
69 g.fillRect(x / 3, x / 3, x / 3, x / 3);
70 return img;
71 }
72
73 public MultiResIconTest() {
74 try {
75 latch = new CountDownLatch(1);
76 createUI();
77 latch.await();
78 } catch (Exception ex) {
79 }
80 }
81
82 private static void createUI() throws Exception {
83 SwingUtilities.invokeAndWait(() -> {
84 frame = new TestFrame();
85 f = new JDialog(frame);
86 f.setTitle("Instruction Dialog");
87 layout = new GridBagLayout();
88 mainControlPanel = new JPanel(layout);
89 resultButtonPanel = new JPanel(layout);
90 GridBagConstraints gbc = new GridBagConstraints();
91 String instructions
92 = "<html> INSTRUCTIONS:<br><br>"
93 + "1) Test frame title icon and frame color should be green."
94 + "<br>"
95 + "2) Test frame task bar icon should be blue<br>"
96 + "3) If color are same as mentioned in 1 and 2 press pass<br>"
97 + " else press fail.<br><br></html>";
98
99 instructionText = new JLabel();
100 instructionText.setText(instructions);
101
102 gbc.gridx = 0;
103 gbc.gridy = 0;
104 gbc.fill = GridBagConstraints.HORIZONTAL;
105 mainControlPanel.add(instructionText, gbc);
106 passButton = new JButton("Pass");
107 passButton.setActionCommand("Pass");
108 passButton.addActionListener((ActionEvent e) -> {
109 latch.countDown();
110 f.dispose();
111 frame.dispose();
112 });
113 failButton = new JButton("Fail");
114 failButton.setActionCommand("Fail");
115 failButton.addActionListener(new ActionListener() {
116 @Override
117 public void actionPerformed(ActionEvent e) {
118 latch.countDown();
119 f.dispose();
120 frame.dispose();
121 throw new RuntimeException("Test Failed");
122 }
123 });
124 gbc.gridx = 1;
125 gbc.gridy = 0;
126 resultButtonPanel.add(passButton, gbc);
127 gbc.gridx = 2;
128 gbc.gridy = 0;
129 resultButtonPanel.add(failButton, gbc);
130
131 gbc.gridx = 0;
132 gbc.gridy = 1;
133 mainControlPanel.add(resultButtonPanel, gbc);
134
135 f.add(mainControlPanel);
136 f.setSize(400, 200);
137 f.setLocationRelativeTo(null);
138 f.setVisible(true);
139
140 f.addWindowListener(new WindowAdapter() {
141 @Override
174 setTitle("Test Frame");
175 setIconImage(ICON);
176 addWindowListener(new WindowAdapter() {
177 @Override
178 public void windowClosing(WindowEvent e) {
179 dispose();
180 }
181 });
182 setSize(W, W);
183 setLocation(50, 50);
184 setResizable(false);
185 setVisible(true);
186 }
187
188 @Override
189 public void paint(Graphics gr) {
190 gr.drawImage(IMG, 0, 0, this);
191 }
192 }
193
194 public static void main(String[] args) {
195 new MultiResIconTest();
196 }
197 }
198
|
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 8149371
28 * @requires (os.family == "linux" | os.family == "mac")
29 * @summary multi-res. image: -Dsun.java2d.uiScale does not work for Window
30 * icons (some ambiguity for Window.setIconImages()?)
31 * @run main/othervm/manual -Dsun.java2d.uiScale=2 MultiResIconTest
32 */
33 import java.awt.Color;
34 import java.awt.EventQueue;
35 import java.awt.Graphics;
36 import java.awt.GridBagConstraints;
37 import java.awt.GridBagLayout;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.WindowAdapter;
41 import java.awt.event.WindowEvent;
42 import java.awt.image.BaseMultiResolutionImage;
43 import java.awt.image.BufferedImage;
44 import java.util.concurrent.CountDownLatch;
45 import javax.swing.JButton;
46 import javax.swing.JDialog;
47 import javax.swing.JFrame;
48 import javax.swing.JLabel;
49 import javax.swing.JPanel;
50 import javax.swing.SwingUtilities;
51
52 public class MultiResIconTest {
53
54 private static GridBagLayout layout;
55 private static JPanel mainControlPanel;
56 private static JPanel resultButtonPanel;
57 private static JLabel instructionText;
58 private static JButton passButton;
59 private static JButton failButton;
60 private static JDialog f;
61 private static CountDownLatch latch;
62 private static TestFrame frame;
63 private static boolean testPassed = true;
64
65 private static BufferedImage generateImage(int x, Color c) {
66
67 BufferedImage img = new BufferedImage(x, x, BufferedImage.TYPE_INT_RGB);
68 Graphics g = img.getGraphics();
69 g.setColor(c);
70 g.fillRect(0, 0, x, x);
71 g.setColor(Color.WHITE);
72 g.fillRect(x / 3, x / 3, x / 3, x / 3);
73 return img;
74 }
75
76 private static void createUI() throws Exception {
77 SwingUtilities.invokeAndWait(() -> {
78 frame = new TestFrame();
79 f = new JDialog(frame);
80 f.setTitle("Instruction Dialog");
81 layout = new GridBagLayout();
82 mainControlPanel = new JPanel(layout);
83 resultButtonPanel = new JPanel(layout);
84 GridBagConstraints gbc = new GridBagConstraints();
85 String instructions
86 = "<html> INSTRUCTIONS:<br><br>"
87 + "1) Test frame title icon and frame color should be green."
88 + "<br>"
89 + "2) Test frame task bar icon should be blue<br>"
90 + "3) If color are same as mentioned in 1 and 2 press pass<br>"
91 + " else press fail.<br><br></html>";
92
93 instructionText = new JLabel();
94 instructionText.setText(instructions);
95
96 gbc.gridx = 0;
97 gbc.gridy = 0;
98 gbc.fill = GridBagConstraints.HORIZONTAL;
99 mainControlPanel.add(instructionText, gbc);
100 passButton = new JButton("Pass");
101 passButton.setActionCommand("Pass");
102 passButton.addActionListener((ActionEvent e) -> {
103 latch.countDown();
104 f.dispose();
105 frame.dispose();
106 });
107 failButton = new JButton("Fail");
108 failButton.setActionCommand("Fail");
109 failButton.addActionListener(new ActionListener() {
110 @Override
111 public void actionPerformed(ActionEvent e) {
112 testPassed = false;
113 latch.countDown();
114 f.dispose();
115 frame.dispose();
116 }
117 });
118 gbc.gridx = 1;
119 gbc.gridy = 0;
120 resultButtonPanel.add(passButton, gbc);
121 gbc.gridx = 2;
122 gbc.gridy = 0;
123 resultButtonPanel.add(failButton, gbc);
124
125 gbc.gridx = 0;
126 gbc.gridy = 1;
127 mainControlPanel.add(resultButtonPanel, gbc);
128
129 f.add(mainControlPanel);
130 f.setSize(400, 200);
131 f.setLocationRelativeTo(null);
132 f.setVisible(true);
133
134 f.addWindowListener(new WindowAdapter() {
135 @Override
168 setTitle("Test Frame");
169 setIconImage(ICON);
170 addWindowListener(new WindowAdapter() {
171 @Override
172 public void windowClosing(WindowEvent e) {
173 dispose();
174 }
175 });
176 setSize(W, W);
177 setLocation(50, 50);
178 setResizable(false);
179 setVisible(true);
180 }
181
182 @Override
183 public void paint(Graphics gr) {
184 gr.drawImage(IMG, 0, 0, this);
185 }
186 }
187
188 public static void main(String[] args) throws Exception {
189 latch = new CountDownLatch(1);
190 new MultiResIconTest().createUI();
191 latch.await();
192 if (!testPassed) {
193 throw new RuntimeException("Test Failed");
194 }
195 }
196 }
|