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 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); | 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.Frame; 36 import java.awt.Panel; 37 import java.awt.FlowLayout; 38 import java.awt.BorderLayout; 39 import java.awt.Button; 40 import java.awt.Component; 41 import java.awt.ComponentOrientation; 42 import java.awt.Container; 43 import java.util.Locale; 44 import java.util.ResourceBundle; 45 46 public class WindowTest { 47 48 public static void main(String args[]) throws Exception { 49 Frame frame = new Frame(); 50 frame.setSize(200,200); 51 frame.setVisible(true); 52 try { 53 doTest(frame); 54 } finally { 55 frame.setVisible(false); 56 frame.dispose(); 57 } 58 } 59 60 public static void doTest (Frame myFrame) throws Exception{ 61 System.out.println("WindowTest {"); 62 63 ResourceBundle rb; 64 65 // Create a window containing a hierarchy of components. 66 System.out.println(" Creating component hierarchy..."); 67 myFrame.setLayout(new FlowLayout()); 68 Panel panel1 = new Panel(); 69 panel1.setLayout(new BorderLayout()); 70 panel1.add("North", new Button("North")); 71 panel1.add("South", new Button("South")); 72 panel1.add("East", new Button("East")); 73 panel1.add("West", new Button("West")); 74 panel1.add("Center", new Button("Center")); 75 myFrame.add(panel1); 76 77 Panel panel2 = new Panel(); 78 panel2.setLayout(new BorderLayout()); 79 panel2.add(BorderLayout.BEFORE_FIRST_LINE, new Button("FirstLine")); 80 panel2.add(BorderLayout.AFTER_LAST_LINE, new Button("LastLine")); 81 panel2.add(BorderLayout.BEFORE_LINE_BEGINS, new Button("FirstItem")); 82 panel2.add(BorderLayout.AFTER_LINE_ENDS, new Button("LastItem")); 83 panel2.add("Center", new Button("Center")); 84 myFrame.add(panel2); 85 86 // After construction, all of the components' orientations should be 90 91 // This will load TestBundle1 using the default locale and apply 92 // it to the component hierarchy. Since the bundle has no Orientation 93 // specified, this should fall back to the bundle-locale's orientation 94 System.out.println(" Applying TestBundle1 by name and verifying..."); 95 myFrame.applyResourceBundle("TestBundle1"); 96 verifyOrientation(myFrame, 97 ComponentOrientation.getOrientation( 98 ResourceBundle.getBundle("TestBundle1", Locale.getDefault()))); 99 100 System.out.println(" Applying TestBundle_iw and verifying..."); 101 rb = ResourceBundle.getBundle("TestBundle", new Locale("iw", "")); 102 myFrame.applyResourceBundle(rb); 103 verifyOrientation(myFrame, ComponentOrientation.RIGHT_TO_LEFT); 104 105 System.out.println(" Applying TestBundle_es and verifying..."); 106 rb = ResourceBundle.getBundle("TestBundle", new Locale("es", "")); 107 myFrame.applyResourceBundle(rb); 108 verifyOrientation(myFrame, ComponentOrientation.LEFT_TO_RIGHT); 109 110 System.out.println("}"); 111 } 112 113 static void verifyOrientation(Component c, ComponentOrientation orient) { 114 115 ComponentOrientation o = c.getComponentOrientation(); 116 117 if (o != orient) { 118 throw new RuntimeException("ERROR: expected " + oString(orient) + 119 ", got " + oString(o) + 120 " on component " + c); 121 } 122 123 if (c instanceof Container) { 124 Container cont = (Container) c; 125 int ncomponents = cont.getComponentCount(); 126 127 for (int i = 0 ; i < ncomponents ; ++i) { 128 Component comp = cont.getComponent(i); 129 verifyOrientation(comp, orient); |