Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/ComponentOrientation/WindowTest.java
47490 views
/*1* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4108453 4778440 630478526* @summary Test Window.applyResourceBundle orientation support27*28* @build TestBundle TestBundle_es TestBundle_iw29* @build TestBundle1 TestBundle1_ar30* @run main WindowTest31*/3233import java.awt.*;34import java.applet.*;35import java.util.Locale;36import java.util.ResourceBundle;3738public class WindowTest extends Applet {39static Exception failure=null;40static Thread mainThread=null;4142public static void main(String args[]) throws Exception {43mainThread = Thread.currentThread();44WindowTest app = new WindowTest();45app.start();46try {47Thread.sleep(300000);48} catch (InterruptedException e) {49if (failure != null) {50throw failure;51}52}53}5455public void start() {56try {57doTest();58} catch (Exception e) {59failure = e;60}61mainThread.interrupt();62}6364public void doTest() {65System.out.println("WindowTest {");6667ResourceBundle rb;68Frame myFrame;6970// Create a window containing a hierarchy of components.71System.out.println(" Creating component hierarchy...");72myFrame = new Frame();73myFrame.setLayout(new FlowLayout());74Panel panel1 = new Panel();75panel1.setLayout(new BorderLayout());76panel1.add("North", new Button("North"));77panel1.add("South", new Button("South"));78panel1.add("East", new Button("East"));79panel1.add("West", new Button("West"));80panel1.add("Center", new Button("Center"));81myFrame.add(panel1);8283Panel panel2 = new Panel();84panel2.setLayout(new BorderLayout());85panel2.add(BorderLayout.BEFORE_FIRST_LINE, new Button("FirstLine"));86panel2.add(BorderLayout.AFTER_LAST_LINE, new Button("LastLine"));87panel2.add(BorderLayout.BEFORE_LINE_BEGINS, new Button("FirstItem"));88panel2.add(BorderLayout.AFTER_LINE_ENDS, new Button("LastItem"));89panel2.add("Center", new Button("Center"));90myFrame.add(panel2);9192// After construction, all of the components' orientations should be93// set to ComponentOrientation.UNKNOWN.94System.out.println(" Verifying orientation is UNKNOWN...");95verifyOrientation(myFrame, ComponentOrientation.UNKNOWN);9697// This will load TestBundle1 using the default locale and apply98// it to the component hierarchy. Since the bundle has no Orientation99// specified, this should fall back to the bundle-locale's orientation100System.out.println(" Applying TestBundle1 by name and verifying...");101myFrame.applyResourceBundle("TestBundle1");102verifyOrientation(myFrame,103ComponentOrientation.getOrientation(104ResourceBundle.getBundle("TestBundle1", Locale.getDefault())));105106System.out.println(" Applying TestBundle_iw and verifying...");107rb = ResourceBundle.getBundle("TestBundle", new Locale("iw", ""));108myFrame.applyResourceBundle(rb);109verifyOrientation(myFrame, ComponentOrientation.RIGHT_TO_LEFT);110111System.out.println(" Applying TestBundle_es and verifying...");112rb = ResourceBundle.getBundle("TestBundle", new Locale("es", ""));113myFrame.applyResourceBundle(rb);114verifyOrientation(myFrame, ComponentOrientation.LEFT_TO_RIGHT);115116117myFrame.setVisible(false);118myFrame.dispose();119System.out.println("}");120}121122static void verifyOrientation(Component c, ComponentOrientation orient) {123124ComponentOrientation o = c.getComponentOrientation();125126if (o != orient) {127throw new RuntimeException("ERROR: expected " + oString(orient) +128", got " + oString(o) +129" on component " + c);130}131132if (c instanceof Container) {133Container cont = (Container) c;134int ncomponents = cont.getComponentCount();135136for (int i = 0 ; i < ncomponents ; ++i) {137Component comp = cont.getComponent(i);138verifyOrientation(comp, orient);139}140}141}142143static String oString(ComponentOrientation o) {144if (o == ComponentOrientation.LEFT_TO_RIGHT) {145return "LEFT_TO_RIGHT";146}147else if (o == ComponentOrientation.RIGHT_TO_LEFT) {148return "RIGHT_TO_LEFT";149}150else {151return "UNKNOWN";152}153}154}155156157