|
1 /* |
|
2 test |
|
3 @bug 6260659 |
|
4 @summary File Name set programmatically in FileDialog is overridden during navigation, XToolkit |
|
5 @author Dmitry.Cherepanov@SUN.COM area=awt.filedialog |
|
6 @library ../../regtesthelpers |
|
7 @build Sysout |
|
8 @run applet/manual=yesno FileNameOverrideTest.html |
|
9 */ |
|
10 |
|
11 import test.java.awt.regtesthelpers.Sysout; |
|
12 |
|
13 import java.applet.Applet; |
|
14 import java.awt.*; |
|
15 import java.awt.event.ActionEvent; |
|
16 import java.awt.event.ActionListener; |
|
17 import java.io.File; |
|
18 import java.io.IOException; |
|
19 |
|
20 public class FileNameOverrideTest extends Applet implements ActionListener { |
|
21 private final static String fileName = "input"; |
|
22 private final static String clickDirName = "Directory for double click"; |
|
23 private final static String dirPath = "."; |
|
24 private Button showBtn; |
|
25 private FileDialog fd; |
|
26 |
|
27 public void init() { |
|
28 this.setLayout(new GridLayout(1, 1)); |
|
29 |
|
30 fd = new FileDialog(new Frame(), "Open"); |
|
31 |
|
32 showBtn = new Button("Show File Dialog"); |
|
33 showBtn.addActionListener(this); |
|
34 add(showBtn); |
|
35 |
|
36 try { |
|
37 File tmpFileUp = new File(dirPath + File.separator + fileName); |
|
38 File tmpDir = new File(dirPath + File.separator + clickDirName); |
|
39 File tmpFileIn = new File(tmpDir.getAbsolutePath() + File.separator + fileName); |
|
40 tmpDir.mkdir(); |
|
41 tmpFileUp.createNewFile(); |
|
42 tmpFileIn.createNewFile(); |
|
43 } catch (IOException ex) { |
|
44 throw new RuntimeException("Cannot create test folder", ex); |
|
45 } |
|
46 |
|
47 String[] instructions = { |
|
48 "1) Click on 'Show File Dialog' button. A file dialog will come up.", |
|
49 "2) Double-click on '" + clickDirName + "' and click OK.", |
|
50 "3) See result of the test below" |
|
51 }; |
|
52 Sysout.createDialogWithInstructions(instructions); |
|
53 }//End init() |
|
54 |
|
55 public void start() { |
|
56 setSize(200, 200); |
|
57 show(); |
|
58 }// start() |
|
59 |
|
60 public void actionPerformed(ActionEvent e) { |
|
61 if (e.getSource() == showBtn) { |
|
62 fd.setFile(fileName); |
|
63 fd.setDirectory(dirPath); |
|
64 fd.setVisible(true); |
|
65 String output = fd.getFile(); |
|
66 if (fileName.equals(output)) { |
|
67 Sysout.println("TEST PASSED"); |
|
68 } else { |
|
69 Sysout.println("TEST FAILED (output file - " + output + ")"); |
|
70 } |
|
71 } |
|
72 } |
|
73 }// class ManualYesNoTest |