1 /*
   2  * Copyright (c) 2006, 2010, 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 /*
  25   test
  26   @bug 6448069
  27   @summary namefilter is not called for file dialog on windows
  28   @author oleg.sukhodolsky: area= awt.filedialog
  29   @run applet FilenameFilterTest.html
  30 */
  31 
  32 /**
  33  * FilenameFilterTest.java
  34  *
  35  * summary: namefilter is not called for file dialog on windows
  36  */
  37 
  38 import java.applet.Applet;
  39 import java.awt.*;
  40 
  41 import java.io.File;
  42 import java.io.FilenameFilter;
  43 
  44 import test.java.awt.regtesthelpers.Util;
  45 
  46 public class FilenameFilterTest extends Applet
  47 {
  48     //Declare things used in the test, like buttons and labels here
  49     volatile boolean filter_was_called = false;
  50     FileDialog fd;
  51 
  52     public void init()
  53     {
  54         // Set up the environment -- set the layout manager, add
  55         // buttons, etc.
  56 
  57         setLayout (new BorderLayout ());
  58 
  59     }//End  init()
  60 
  61     public void start ()
  62     {
  63         //Get things going.  Request focus, set size, et cetera
  64         setSize (200,200);
  65         setVisible(true);
  66         validate();
  67 
  68         EventQueue.invokeLater(new Runnable() {
  69                 public void run() {
  70                     fd = new FileDialog(new Frame(""), "hello world", FileDialog.LOAD);
  71                     fd.setFilenameFilter(new FilenameFilter() {
  72                             public boolean accept(File dir, String name) {
  73                                 filter_was_called = true;
  74                                 System.out.println(Thread.currentThread() + " name = " + name );
  75                                 return true;
  76                             }
  77                         });
  78                     fd.setDirectory(System.getProperty("test.src"));
  79                     fd.setVisible(true);
  80                 }
  81             });
  82         Util.waitForIdle(null);
  83         if (fd == null) {
  84             throw new RuntimeException("fd is null (very unexpected thing :(");
  85         }
  86         //Wait a little; some native dialog implementations may take a while
  87         //to initialize and call the filter. See 6959787 for an example.
  88         try {
  89             Thread.sleep(5000);
  90         } catch (Exception ex) {
  91         }
  92         fd.dispose();
  93         if (!filter_was_called) {
  94             throw new RuntimeException("Filter was not called");
  95         }
  96     }// start()
  97 
  98 }// class FilenameFilterTest