1 /* 2 * Copyright (c) 1998, 2016, 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 4108453 27 * @summary Test ComponentOrientation (Bidi) support in BorderLayout 28 */ 29 /* 30 * (C) Copyright IBM Corp. 1998 - All Rights Reserved 31 * 32 * The original version of this source code and documentation is copyrighted 33 * and owned by IBM, Inc. These materials are provided under terms of a 34 * License Agreement between IBM and Sun. This technology is protected by 35 * multiple US and International patents. This notice and attribution to IBM 36 * may not be removed. 37 */ 38 39 import java.awt.*; 40 import java.awt.event.*; 41 import java.applet.Applet; 42 43 public class BorderTest extends Applet { 44 Panel panel1; 45 Panel panel2; 46 47 public BorderTest() { 48 setLayout(new GridLayout(0,2)); 49 50 // Create a panel with a BorderLayout and a bunch of buttons in it 51 panel1 = new Panel(); 52 panel1.setLayout(new BorderLayout()); 53 panel1.add("North", new Button("North")); 54 panel1.add("South", new Button("South")); 55 panel1.add("East", new Button("East")); 56 panel1.add("West", new Button("West")); 57 panel1.add("Center", new Button("Center")); 58 add(panel1); 59 60 // Create a panel with a BorderLayout and a bunch of buttons in it 61 panel2 = new Panel(); 62 panel2.setLayout(new BorderLayout()); 63 panel2.add(BorderLayout.BEFORE_FIRST_LINE, new Button("FirstLine")); 64 panel2.add(BorderLayout.AFTER_LAST_LINE, new Button("LastLine")); 65 panel2.add(BorderLayout.BEFORE_LINE_BEGINS, new Button("FirstItem")); 66 panel2.add(BorderLayout.AFTER_LINE_ENDS, new Button("LastItem")); 67 panel2.add("Center", new Button("Center")); 68 add(panel2); 69 70 // Create a popup menu for switching between orientations 71 { 72 Choice c = new Choice(); 73 c.addItem("LEFT_TO_RIGHT"); 74 c.addItem("RIGHT_TO_LEFT"); 75 c.addItem("UNKNOWN"); 76 c.addItemListener( new ItemListener() { 77 public void itemStateChanged(ItemEvent e) { 78 String item = (String)(e.getItem()); 79 80 ComponentOrientation o = ComponentOrientation.UNKNOWN; 81 if (item.equals("LEFT_TO_RIGHT")) { 82 o = ComponentOrientation.LEFT_TO_RIGHT; 83 } else if (item.equals("RIGHT_TO_LEFT")) { 84 o = ComponentOrientation.RIGHT_TO_LEFT; 85 } 86 panel1.setComponentOrientation(o); 87 panel2.setComponentOrientation(o); 88 panel1.layout(); 89 panel2.layout(); 90 panel1.repaint(); 91 panel2.repaint(); 92 } 93 } ); 94 add(c); 95 } 96 } 97 98 public static void main(String args[]) { 99 Frame f = new Frame("BorderTest"); 100 101 f.addWindowListener( new WindowAdapter() { 102 public void windowClosing(WindowEvent e) { 103 e.getWindow().hide(); 104 e.getWindow().dispose(); 105 System.exit(0); 106 }; 107 } ); 108 109 BorderTest BorderTest = new BorderTest(); 110 BorderTest.init(); 111 BorderTest.start(); 112 113 f.add("Center", BorderTest); 114 f.setSize(450, 300); 115 f.show(); 116 } 117 }