|
22 | 22 | */
|
23 | 23 |
|
24 | 24 | import java.awt.BorderLayout;
|
| 25 | +import java.awt.Window; |
25 | 26 | import java.awt.event.ActionEvent;
|
26 | 27 | import java.awt.event.ActionListener;
|
27 | 28 | import java.beans.PropertyChangeEvent;
|
28 | 29 | import java.beans.PropertyChangeListener;
|
29 | 30 | import java.io.File;
|
30 |
| -import java.lang.reflect.InvocationTargetException; |
31 | 31 | import java.util.Arrays;
|
| 32 | +import java.util.List; |
32 | 33 |
|
33 | 34 | import javax.swing.JCheckBox;
|
34 | 35 | import javax.swing.JFileChooser;
|
35 | 36 | import javax.swing.JFrame;
|
36 | 37 | import javax.swing.JPanel;
|
37 |
| -import javax.swing.JTextArea; |
38 | 38 | import javax.swing.JScrollPane;
|
39 |
| -import javax.swing.SwingUtilities; |
| 39 | +import javax.swing.JTextArea; |
40 | 40 | import javax.swing.WindowConstants;
|
41 | 41 |
|
42 | 42 | /*
|
|
51 | 51 | * @run main/manual FileChooserSymLinkTest
|
52 | 52 | */
|
53 | 53 | public class FileChooserSymLinkTest {
|
| 54 | + private static final String INSTRUCTIONS = """ |
| 55 | + <html><body> |
| 56 | + Instructions to Test: |
| 57 | + <ol> |
| 58 | + <li>Open an elevated <i>Command Prompt</i>. |
| 59 | + <li>Paste the following commands: |
| 60 | + <pre><code>cd /d C:\\ |
| 61 | + mkdir FileChooserTest |
| 62 | + cd FileChooserTest |
| 63 | + mkdir target |
| 64 | + mklink /d link target</code></pre> |
| 65 | +
|
| 66 | + <li>Navigate to <code>C:\\FileChooserTest</code> in |
| 67 | + the <code>JFileChooser</code>. |
| 68 | + <li>Perform testing in single- and multi-selection modes: |
| 69 | + <ul style="margin-bottom: 0px"> |
| 70 | + <li><strong>Single-selection:</strong> |
| 71 | + <ol> |
| 72 | + <li>Ensure <b>Enable multi-selection</b> is cleared |
| 73 | + (the default state). |
| 74 | + <li>Click <code>link</code> directory, |
| 75 | + the absolute path of the symbolic |
| 76 | + link should be displayed.<br> |
| 77 | + If it's <code>null</code>, click <b>Fail</b>. |
| 78 | + <li>Click <code>target</code> directory, |
| 79 | + its absolute path should be displayed. |
| 80 | + </ol> |
| 81 | + <li><strong>Multi-selection:</strong> |
| 82 | + <ol> |
| 83 | + <li>Select <b>Enable multi-selection</b>. |
| 84 | + <li>Click <code>link</code>, |
| 85 | + <li>Press <kbd>Ctrl</kbd> and |
| 86 | + then click <code>target</code>. |
| 87 | + <li>Both should be selected and |
| 88 | + their absolute paths should be displayed. |
| 89 | + <li>If <code>link</code> can't be selected or |
| 90 | + if its absolute path is <code>null</code>, |
| 91 | + click <b>Fail</b>. |
| 92 | + </ol> |
| 93 | + </ul> |
| 94 | + <p>If <code>link</code> can be selected in both |
| 95 | + single- and multi-selection modes, click <b>Pass</b>.</p> |
| 96 | + <li>When done with testing, paste the following commands to |
| 97 | + remove the <code>FileChooserTest</code> directory: |
| 98 | + <pre><code>cd \\ |
| 99 | + rmdir /s /q C:\\FileChooserTest</code></pre> |
| 100 | +
|
| 101 | + or use File Explorer to clean it up. |
| 102 | + </ol> |
| 103 | + """; |
| 104 | + |
54 | 105 | static JFrame frame;
|
55 | 106 | static JFileChooser jfc;
|
56 | 107 | static JPanel panel;
|
57 | 108 | static JTextArea pathList;
|
58 | 109 | static JCheckBox multiSelection;
|
59 |
| - static PassFailJFrame passFailJFrame; |
60 | 110 |
|
61 | 111 | public static void main(String[] args) throws Exception {
|
62 |
| - SwingUtilities.invokeAndWait(new Runnable() { |
63 |
| - public void run() { |
64 |
| - try { |
65 |
| - initialize(); |
66 |
| - } catch (InterruptedException | InvocationTargetException e) { |
67 |
| - throw new RuntimeException(e); |
68 |
| - } |
69 |
| - } |
70 |
| - }); |
71 |
| - passFailJFrame.awaitAndCheck(); |
| 112 | + PassFailJFrame.builder() |
| 113 | + .instructions(INSTRUCTIONS) |
| 114 | + .rows(35) |
| 115 | + .columns(50) |
| 116 | + .testUI(FileChooserSymLinkTest::createTestUI) |
| 117 | + .build() |
| 118 | + .awaitAndCheck(); |
72 | 119 | }
|
73 | 120 |
|
74 |
| - static void initialize() throws InterruptedException, InvocationTargetException { |
75 |
| - //Initialize the components |
76 |
| - final String INSTRUCTIONS = """ |
77 |
| - <html><body> |
78 |
| - Instructions to Test: |
79 |
| - <ol> |
80 |
| - <li>Open an elevated <i>Command Prompt</i>. |
81 |
| - <li>Paste the following commands: |
82 |
| - <pre><code>cd /d C:\\ |
83 |
| - mkdir FileChooserTest |
84 |
| - cd FileChooserTest |
85 |
| - mkdir target |
86 |
| - mklink /d link target</code></pre> |
87 |
| -
|
88 |
| - <li>Navigate to <code>C:\\FileChooserTest</code> in |
89 |
| - the <code>JFileChooser</code>. |
90 |
| - <li>Perform testing in single- and multi-selection modes: |
91 |
| - <ul style="margin-bottom: 0px"> |
92 |
| - <li><strong>Single-selection:</strong> |
93 |
| - <ol> |
94 |
| - <li>Ensure <b>Enable multi-selection</b> is cleared |
95 |
| - (the default state). |
96 |
| - <li>Click <code>link</code> directory, |
97 |
| - the absolute path of the symbolic |
98 |
| - link should be displayed.<br> |
99 |
| - If it's <code>null</code>, click <b>Fail</b>. |
100 |
| - <li>Click <code>target</code> directory, |
101 |
| - its absolute path should be displayed. |
102 |
| - </ol> |
103 |
| - <li><strong>Multi-selection:</strong> |
104 |
| - <ol> |
105 |
| - <li>Select <b>Enable multi-selection</b>. |
106 |
| - <li>Click <code>link</code>, |
107 |
| - <li>Press <kbd>Ctrl</kbd> and |
108 |
| - then click <code>target</code>. |
109 |
| - <li>Both should be selected and |
110 |
| - their absolute paths should be displayed. |
111 |
| - <li>If <code>link</code> can't be selected or |
112 |
| - if its absolute path is <code>null</code>, |
113 |
| - click <b>Fail</b>. |
114 |
| - </ol> |
115 |
| - </ul> |
116 |
| - <p>If <code>link</code> can be selected in both |
117 |
| - single- and multi-selection modes, click <b>Pass</b>.</p> |
118 |
| - <li>When done with testing, paste the following commands to |
119 |
| - remove the <code>FileChooserTest</code> directory: |
120 |
| - <pre><code>cd \\ |
121 |
| - rmdir /s /q C:\\FileChooserTest</code></pre> |
122 |
| -
|
123 |
| - or use File Explorer to clean it up. |
124 |
| - </ol> |
125 |
| - """; |
| 121 | + private static List<Window> createTestUI() { |
126 | 122 | frame = new JFrame("JFileChooser Symbolic Link test");
|
127 | 123 | panel = new JPanel(new BorderLayout());
|
128 | 124 | multiSelection = new JCheckBox("Enable Multi-Selection");
|
129 | 125 | pathList = new JTextArea(10, 50);
|
130 | 126 | jfc = new JFileChooser(new File("C:\\"));
|
131 |
| - passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 35, 50); |
132 | 127 |
|
133 |
| - PassFailJFrame.addTestWindow(frame); |
134 |
| - PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL); |
135 | 128 | frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
136 | 129 | panel.add(multiSelection, BorderLayout.EAST);
|
137 | 130 | panel.add(new JScrollPane(pathList), BorderLayout.WEST);
|
@@ -166,6 +159,6 @@ public void propertyChange(PropertyChangeEvent evt) {
|
166 | 159 | frame.add(panel, BorderLayout.NORTH);
|
167 | 160 | frame.add(jfc, BorderLayout.CENTER);
|
168 | 161 | frame.pack();
|
169 |
| - frame.setVisible(true); |
| 162 | + return List.of(frame); |
170 | 163 | }
|
171 | 164 | }
|
0 commit comments