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