BorderTest.java revision 14851:980da45565c8
1116576Smurray/*
2116576Smurray * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
3116576Smurray * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4116576Smurray *
5116576Smurray * This code is free software; you can redistribute it and/or modify it
6116576Smurray * under the terms of the GNU General Public License version 2 only, as
7116576Smurray * published by the Free Software Foundation.
8116576Smurray *
9270114Sse * This code is distributed in the hope that it will be useful, but WITHOUT
10270114Sse * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11116576Smurray * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12116576Smurray * version 2 for more details (a copy is included in the LICENSE file that
13116576Smurray * accompanied this code).
14116576Smurray *
15116576Smurray * You should have received a copy of the GNU General Public License version
16116576Smurray * 2 along with this work; if not, write to the Free Software Foundation,
17116576Smurray * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18270114Sse *
19270114Sse * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20116576Smurray * or visit www.oracle.com if you need additional information or have any
21116576Smurray * questions.
22116576Smurray */
23116576Smurray
24270114Sse/*
25116576Smurray * @test
26116576Smurray * @key headful
27116576Smurray * @bug     4108453
28116576Smurray * @summary Test ComponentOrientation (Bidi) support in BorderLayout
29116576Smurray */
30116576Smurray/*
31116576Smurray * (C) Copyright IBM Corp. 1998 - All Rights Reserved
32270114Sse *
33116576Smurray * The original version of this source code and documentation is copyrighted
34116576Smurray * and owned by IBM, Inc. These materials are provided under terms of a
35116576Smurray * License Agreement between IBM and Sun. This technology is protected by
36116576Smurray * multiple US and International patents. This notice and attribution to IBM
37116576Smurray * may not be removed.
38116576Smurray */
39116576Smurray
40116576Smurrayimport java.awt.*;
41116576Smurrayimport java.awt.event.*;
42116576Smurrayimport java.applet.Applet;
43116576Smurray
44116576Smurraypublic class BorderTest extends Applet {
45270114Sse    Panel       panel1;
46270114Sse    Panel       panel2;
47270114Sse
48116576Smurray    public BorderTest() {
49116576Smurray        setLayout(new GridLayout(0,2));
50116576Smurray
51116576Smurray        // Create a panel with a BorderLayout and a bunch of buttons in it
52116576Smurray        panel1 = new Panel();
53116576Smurray        panel1.setLayout(new BorderLayout());
54116576Smurray        panel1.add("North", new Button("North"));
55116576Smurray        panel1.add("South", new Button("South"));
56270114Sse        panel1.add("East", new Button("East"));
57116576Smurray        panel1.add("West", new Button("West"));
58116576Smurray        panel1.add("Center", new Button("Center"));
59116576Smurray        add(panel1);
60116576Smurray
61116576Smurray        // Create a panel with a BorderLayout and a bunch of buttons in it
62116576Smurray        panel2 = new Panel();
63116576Smurray        panel2.setLayout(new BorderLayout());
64116576Smurray        panel2.add(BorderLayout.BEFORE_FIRST_LINE, new Button("FirstLine"));
65116576Smurray        panel2.add(BorderLayout.AFTER_LAST_LINE, new Button("LastLine"));
66116576Smurray        panel2.add(BorderLayout.BEFORE_LINE_BEGINS, new Button("FirstItem"));
67116576Smurray        panel2.add(BorderLayout.AFTER_LINE_ENDS, new Button("LastItem"));
68116576Smurray        panel2.add("Center", new Button("Center"));
69116576Smurray        add(panel2);
70116576Smurray
71116576Smurray        // Create a popup menu for switching between orientations
72116576Smurray        {
73116576Smurray            Choice c = new Choice();
74116576Smurray            c.addItem("LEFT_TO_RIGHT");
75116576Smurray            c.addItem("RIGHT_TO_LEFT");
76116576Smurray            c.addItem("UNKNOWN");
77116576Smurray            c.addItemListener( new ItemListener() {
78116576Smurray                public void itemStateChanged(ItemEvent e) {
79116576Smurray                    String item = (String)(e.getItem());
80116576Smurray
81116576Smurray                    ComponentOrientation o = ComponentOrientation.UNKNOWN;
82116576Smurray                    if (item.equals("LEFT_TO_RIGHT")) {
83116576Smurray                        o = ComponentOrientation.LEFT_TO_RIGHT;
84116576Smurray                    } else if (item.equals("RIGHT_TO_LEFT")) {
85116576Smurray                        o = ComponentOrientation.RIGHT_TO_LEFT;
86116576Smurray                    }
87116576Smurray                    panel1.setComponentOrientation(o);
88116576Smurray                    panel2.setComponentOrientation(o);
89116576Smurray                    panel1.layout();
90116576Smurray                    panel2.layout();
91116576Smurray                    panel1.repaint();
92270114Sse                    panel2.repaint();
93116576Smurray                }
94116576Smurray            } );
95116576Smurray            add(c);
96116576Smurray        }
97116576Smurray    }
98116576Smurray
99116576Smurray    public static void main(String args[]) {
100116576Smurray        Frame f = new Frame("BorderTest");
101116576Smurray
102116576Smurray        f.addWindowListener( new WindowAdapter() {
103116576Smurray            public void windowClosing(WindowEvent e) {
104116576Smurray                e.getWindow().hide();
105116576Smurray                e.getWindow().dispose();
106116576Smurray                System.exit(0);
107116576Smurray            };
108116576Smurray        } );
109270114Sse
110116576Smurray        BorderTest BorderTest = new BorderTest();
111116576Smurray        BorderTest.init();
112116576Smurray        BorderTest.start();
113116576Smurray
114116576Smurray        f.add("Center", BorderTest);
115116576Smurray        f.setSize(450, 300);
116270114Sse        f.show();
117270114Sse    }
118270114Sse}
119270114Sse