< prev index next >

test/jdk/javax/swing/JFileChooser/8041694/bug8041694.java

Print this page
rev 51542 : 8210039: move OSInfo to top level testlibrary
Reviewed-by: duke


  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 8041694
  28  * @summary JFileChooser removes trailing spaces in the selected directory name
  29  * @author Anton Litvinov
  30  * @library ../../../../lib/testlibrary
  31  * @build jdk.testlibrary.OSInfo
  32  * @run main bug8041694
  33  */
  34 
  35 import java.awt.AWTException;
  36 import java.awt.Robot;
  37 import java.awt.event.KeyEvent;
  38 import java.io.File;
  39 import java.io.IOException;
  40 import java.nio.file.Files;
  41 import java.util.concurrent.CountDownLatch;
  42 import javax.swing.JFileChooser;
  43 import javax.swing.SwingUtilities;
  44 import javax.swing.UIManager;
  45 import javax.swing.UnsupportedLookAndFeelException;
  46 import javax.swing.plaf.metal.MetalLookAndFeel;
  47 
  48 import jdk.testlibrary.OSInfo;
  49 
  50 public class bug8041694 {
  51     private static volatile File dir1;
  52     private static File dir2;
  53     private static volatile File selectedDir;
  54 
  55     private static void runTest() {
  56         try {
  57             // Set Metal L&F to make the test compatible with OS X.
  58             UIManager.setLookAndFeel(new MetalLookAndFeel());
  59             Robot robot = new Robot();
  60 
  61             dir1 = Files.createTempDirectory("bug8041694").toFile();
  62             if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
  63                 dir2 = new File(String.format(
  64                     "\\\\?\\%s\\d ", dir1.getAbsolutePath().replace('/', '\\')));
  65             } else {
  66                 dir2 = new File(dir1.getAbsolutePath() + File.separator + "d ");
  67             }
  68             dir2.mkdir();
  69 
  70             final CountDownLatch fChooserClosedSignal = new CountDownLatch(1);
  71             SwingUtilities.invokeLater(new Runnable() {
  72                 @Override
  73                 public void run() {
  74                     try {
  75                         JFileChooser fChooser = new JFileChooser(dir1);
  76                         fChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  77                         if (fChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  78                             selectedDir = fChooser.getSelectedFile();
  79                         }
  80                     } finally {
  81                         fChooserClosedSignal.countDown();
  82                     }




  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 8041694
  28  * @summary JFileChooser removes trailing spaces in the selected directory name
  29  * @author Anton Litvinov
  30  * @library /test/lib
  31  * @build jdk.test.lib.Platform
  32  * @run main bug8041694
  33  */
  34 
  35 import java.awt.AWTException;
  36 import java.awt.Robot;
  37 import java.awt.event.KeyEvent;
  38 import java.io.File;
  39 import java.io.IOException;
  40 import java.nio.file.Files;
  41 import java.util.concurrent.CountDownLatch;
  42 import javax.swing.JFileChooser;
  43 import javax.swing.SwingUtilities;
  44 import javax.swing.UIManager;
  45 import javax.swing.UnsupportedLookAndFeelException;
  46 import javax.swing.plaf.metal.MetalLookAndFeel;
  47 
  48 import jdk.test.lib.Platform;
  49 
  50 public class bug8041694 {
  51     private static volatile File dir1;
  52     private static File dir2;
  53     private static volatile File selectedDir;
  54 
  55     private static void runTest() {
  56         try {
  57             // Set Metal L&F to make the test compatible with OS X.
  58             UIManager.setLookAndFeel(new MetalLookAndFeel());
  59             Robot robot = new Robot();
  60 
  61             dir1 = Files.createTempDirectory("bug8041694").toFile();
  62             if (Platform.isWindows()) {
  63                 dir2 = new File(String.format(
  64                     "\\\\?\\%s\\d ", dir1.getAbsolutePath().replace('/', '\\')));
  65             } else {
  66                 dir2 = new File(dir1.getAbsolutePath() + File.separator + "d ");
  67             }
  68             dir2.mkdir();
  69 
  70             final CountDownLatch fChooserClosedSignal = new CountDownLatch(1);
  71             SwingUtilities.invokeLater(new Runnable() {
  72                 @Override
  73                 public void run() {
  74                     try {
  75                         JFileChooser fChooser = new JFileChooser(dir1);
  76                         fChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  77                         if (fChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  78                             selectedDir = fChooser.getSelectedFile();
  79                         }
  80                     } finally {
  81                         fChooserClosedSignal.countDown();
  82                     }


< prev index next >