Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/7199708/bug7199708.java
41155 views
1
/*
2
* Copyright (c) 2013, 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
import java.awt.Component;
25
import java.awt.Container;
26
import java.awt.Point;
27
import java.awt.Robot;
28
import java.awt.Toolkit;
29
import java.awt.event.InputEvent;
30
import java.awt.event.KeyEvent;
31
import java.io.File;
32
import java.io.IOException;
33
import javax.swing.JFileChooser;
34
import javax.swing.SwingUtilities;
35
36
import java.nio.file.Files;
37
import javax.swing.AbstractButton;
38
import javax.swing.JTable;
39
import javax.swing.UIManager;
40
41
/**
42
* @test
43
* @key headful
44
* @bug 7199708 8159587 8198005
45
* @author Alexander Scherbatiy
46
* @summary FileChooser crashs when opening large folder
47
* @run main/timeout=240 bug7199708
48
*/
49
public class bug7199708 {
50
51
private static int FILE_NUMBER = 30000;
52
private static volatile JFileChooser fileChooser;
53
private static volatile int locationX;
54
private static volatile int locationY;
55
private static volatile int width;
56
private static File largeFolder;
57
private static File files[] = new File[FILE_NUMBER];
58
59
public static void main(String[] args) throws Exception {
60
61
Robot robot = new Robot();
62
robot.setAutoDelay(50);
63
64
try {
65
final File folder = createLargeFolder();
66
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
67
68
SwingUtilities.invokeLater(new Runnable() {
69
public void run() {
70
fileChooser = new JFileChooser(folder);
71
fileChooser.showSaveDialog(null);
72
}
73
});
74
75
robot.waitForIdle();
76
77
SwingUtilities.invokeLater(new Runnable() {
78
public void run() {
79
final String detailsTooltip =
80
UIManager.getString("FileChooser."
81
+ "detailsViewButtonToolTipText",
82
fileChooser.getLocale());
83
84
doAction(fileChooser, new ComponentAction() {
85
@Override
86
public boolean accept(Component component) {
87
return (component instanceof AbstractButton)
88
&& detailsTooltip.equals(
89
((AbstractButton) component).getToolTipText());
90
}
91
92
@Override
93
public void perform(Component component) {
94
((AbstractButton) component).doClick();
95
}
96
});
97
98
doAction(fileChooser, new ComponentAction() {
99
@Override
100
public boolean accept(Component component) {
101
return (component instanceof JTable);
102
}
103
104
@Override
105
public void perform(Component component) {
106
Point tableLocation = component.getLocationOnScreen();
107
locationX = (int) tableLocation.getX();
108
locationY = (int) tableLocation.getY();
109
width = (int) fileChooser.getBounds().getWidth();
110
}
111
});
112
}
113
});
114
115
robot.waitForIdle();
116
117
int d = 25;
118
for (int i = 0; i < width / d; i++) {
119
robot.mouseMove(locationX + i * d, locationY + 5);
120
robot.waitForIdle();
121
robot.mousePress(InputEvent.BUTTON1_MASK);
122
robot.waitForIdle();
123
robot.mouseRelease(InputEvent.BUTTON1_MASK);
124
robot.waitForIdle();
125
}
126
127
robot.keyPress(KeyEvent.VK_ESCAPE);
128
robot.waitForIdle();
129
robot.keyRelease(KeyEvent.VK_ESCAPE);
130
robot.waitForIdle();
131
132
} finally {
133
for (int i = 0; i < FILE_NUMBER; i++) {
134
Files.delete(files[i].toPath());
135
}
136
Files.delete(largeFolder.toPath());
137
}
138
}
139
140
static void doAction(Component component, ComponentAction action) {
141
if (action.accept(component)) {
142
action.perform(component);
143
} else if (component instanceof Container) {
144
for (Component comp : ((Container) component).getComponents()) {
145
doAction(comp, action);
146
}
147
}
148
}
149
150
private static File createLargeFolder() {
151
try {
152
153
largeFolder = Files.createTempDirectory("large_folder").toFile();
154
155
for (int i = 0; i < FILE_NUMBER; i++) {
156
files[i] = new File(largeFolder, "File_" + i + ".txt");
157
files[i].createNewFile();
158
}
159
return largeFolder;
160
} catch (IOException ex) {
161
throw new RuntimeException(ex);
162
}
163
}
164
165
interface ComponentAction {
166
167
boolean accept(Component component);
168
169
void perform(Component component);
170
}
171
}
172
173