< prev index next >

test/java/awt/ComponentOrientation/WindowTest.java

Print this page




  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     4108453 4778440 6304785
  28  * @summary Test Window.applyResourceBundle orientation support
  29  *
  30  * @build TestBundle TestBundle_es TestBundle_iw
  31  * @build TestBundle1 TestBundle1_ar
  32  * @run main WindowTest
  33  */
  34 
  35 import java.awt.*;
  36 import java.applet.*;
  37 import java.util.Locale;
  38 import java.util.ResourceBundle;
  39 
  40 public class WindowTest extends Applet {
  41     static Exception failure=null;
  42     static Thread mainThread=null;
  43 
  44     public static void main(String args[]) throws Exception {
  45         mainThread = Thread.currentThread();
  46         WindowTest app = new WindowTest();
  47         app.start();
  48         try {
  49             Thread.sleep(300000);
  50         } catch (InterruptedException e) {
  51             if (failure != null) {
  52                 throw failure;
  53             }
  54         }
  55     }
  56 
  57     public void start() {




  58         try {
  59             doTest();
  60         } catch (Exception e) {
  61             failure = e;

  62         }
  63         mainThread.interrupt();
  64     }
  65 
  66     public void doTest() {
  67         System.out.println("WindowTest {");
  68 
  69         ResourceBundle rb;
  70         Frame myFrame;
  71 
  72         // Create a window containing a hierarchy of components.
  73         System.out.println("  Creating component hierarchy...");
  74         myFrame = new Frame();
  75         myFrame.setLayout(new FlowLayout());
  76         Panel panel1 = new Panel();
  77         panel1.setLayout(new BorderLayout());
  78         panel1.add("North", new Button("North"));
  79         panel1.add("South", new Button("South"));
  80         panel1.add("East", new Button("East"));
  81         panel1.add("West", new Button("West"));
  82         panel1.add("Center", new Button("Center"));
  83         myFrame.add(panel1);
  84 
  85         Panel panel2 = new Panel();
  86         panel2.setLayout(new BorderLayout());
  87         panel2.add(BorderLayout.BEFORE_FIRST_LINE, new Button("FirstLine"));
  88         panel2.add(BorderLayout.AFTER_LAST_LINE, new Button("LastLine"));
  89         panel2.add(BorderLayout.BEFORE_LINE_BEGINS, new Button("FirstItem"));
  90         panel2.add(BorderLayout.AFTER_LINE_ENDS, new Button("LastItem"));
  91         panel2.add("Center", new Button("Center"));
  92         myFrame.add(panel2);
  93 
  94         // After construction, all of the components' orientations should be
  95         // set to ComponentOrientation.UNKNOWN.
  96         System.out.println("  Verifying orientation is UNKNOWN...");
  97         verifyOrientation(myFrame, ComponentOrientation.UNKNOWN);
  98 
  99         // This will load TestBundle1 using the default locale and apply
 100         // it to the component hierarchy.  Since the bundle has no Orientation
 101         // specified, this should fall back to the bundle-locale's orientation
 102         System.out.println("  Applying TestBundle1 by name and verifying...");
 103         myFrame.applyResourceBundle("TestBundle1");
 104         verifyOrientation(myFrame,
 105                     ComponentOrientation.getOrientation(
 106                         ResourceBundle.getBundle("TestBundle1", Locale.getDefault())));
 107 
 108         System.out.println("  Applying TestBundle_iw and verifying...");
 109         rb = ResourceBundle.getBundle("TestBundle", new Locale("iw", ""));
 110         myFrame.applyResourceBundle(rb);
 111         verifyOrientation(myFrame, ComponentOrientation.RIGHT_TO_LEFT);
 112 
 113         System.out.println("  Applying TestBundle_es and verifying...");
 114         rb = ResourceBundle.getBundle("TestBundle", new Locale("es", ""));
 115         myFrame.applyResourceBundle(rb);
 116         verifyOrientation(myFrame, ComponentOrientation.LEFT_TO_RIGHT);
 117 
 118 
 119         myFrame.setVisible(false);
 120         myFrame.dispose();
 121         System.out.println("}");
 122     }
 123 
 124     static void verifyOrientation(Component c, ComponentOrientation orient) {
 125 
 126         ComponentOrientation o = c.getComponentOrientation();
 127 
 128         if (o != orient) {
 129             throw new RuntimeException("ERROR: expected " + oString(orient) +
 130                                         ", got " + oString(o) +
 131                                         " on component " + c);
 132         }
 133 
 134         if (c instanceof Container) {
 135             Container cont = (Container) c;
 136             int ncomponents = cont.getComponentCount();
 137 
 138             for (int i = 0 ; i < ncomponents ; ++i) {
 139                 Component comp = cont.getComponent(i);
 140                 verifyOrientation(comp, orient);


  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     4108453 4778440 6304785
  28  * @summary Test Window.applyResourceBundle orientation support
  29  *


  30  * @run main WindowTest
  31  */
  32 
  33 import java.awt.*;







  34 
  35 public class WindowTest {











  36 
  37 
  38     public static void main(String args[]) throws Exception {
  39         Frame frame  = new Frame();
  40         frame.setSize(200,200);
  41         frame.setVisible(true);
  42         try {
  43             doTest(frame);
  44         } finally {
  45             frame.setVisible(false);
  46             frame.dispose();
  47         }

  48     }
  49 
  50     public static void doTest (Frame  myFrame) throws Exception{
  51         System.out.println("WindowTest {");
  52 



  53         // Create a window containing a hierarchy of components.
  54         System.out.println("  Creating component hierarchy...");

  55         myFrame.setLayout(new FlowLayout());
  56         Panel panel1 = new Panel();
  57         panel1.setLayout(new BorderLayout());
  58         panel1.add("North", new Button("North"));
  59         panel1.add("South", new Button("South"));
  60         panel1.add("East", new Button("East"));
  61         panel1.add("West", new Button("West"));
  62         panel1.add("Center", new Button("Center"));
  63         myFrame.add(panel1);
  64 
  65         Panel panel2 = new Panel();
  66         panel2.setLayout(new BorderLayout());
  67         panel2.add(BorderLayout.BEFORE_FIRST_LINE, new Button("FirstLine"));
  68         panel2.add(BorderLayout.AFTER_LAST_LINE, new Button("LastLine"));
  69         panel2.add(BorderLayout.BEFORE_LINE_BEGINS, new Button("FirstItem"));
  70         panel2.add(BorderLayout.AFTER_LINE_ENDS, new Button("LastItem"));
  71         panel2.add("Center", new Button("Center"));
  72         myFrame.add(panel2);
  73 
  74         // After construction, all of the components' orientations should be
  75         // set to ComponentOrientation.UNKNOWN.
  76         System.out.println("  Verifying orientation is UNKNOWN...");
  77         verifyOrientation(myFrame, ComponentOrientation.UNKNOWN);
  78 
  79         System.out.println("  Applying RIGHT_TO_LEFT orientation and verifying...");
  80         myFrame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);;










  81         verifyOrientation(myFrame, ComponentOrientation.RIGHT_TO_LEFT);
  82 
  83         System.out.println("  Applying LEFT_TO_RIGHT orientation and verifying...");
  84         myFrame.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

  85         verifyOrientation(myFrame, ComponentOrientation.LEFT_TO_RIGHT);
  86 



  87         System.out.println("}");
  88     }
  89 
  90     static void verifyOrientation(Component c, ComponentOrientation orient) {
  91 
  92         ComponentOrientation o = c.getComponentOrientation();
  93 
  94         if (o != orient) {
  95             throw new RuntimeException("ERROR: expected " + oString(orient) +
  96                                         ", got " + oString(o) +
  97                                         " on component " + c);
  98         }
  99 
 100         if (c instanceof Container) {
 101             Container cont = (Container) c;
 102             int ncomponents = cont.getComponentCount();
 103 
 104             for (int i = 0 ; i < ncomponents ; ++i) {
 105                 Component comp = cont.getComponent(i);
 106                 verifyOrientation(comp, orient);
< prev index next >