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 FlowLayout 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 FlowTest extends Applet { 45 Panel panel; 46 47 public FlowTest() { 48 setLayout(new BorderLayout()); 49 50 // Create a panel with a FlowLayout and a bunch of buttons in it 51 panel = new Panel(); 52 panel.setLayout(new FlowLayout(FlowLayout.LEFT)); 53 panel.add(new Button("one")); 54 panel.add(new Button("two")); 55 panel.add(new Button("three")); 56 panel.add(new Button("four")); 57 panel.add(new Button("five")); 58 panel.add(new Button("six")); 59 panel.add(new Button("seven")); 60 panel.add(new Button("eight")); 61 panel.add(new Button("nine")); 62 panel.add(new Button("ten")); 63 panel.add(new Button("eleven")); 64 65 add("Center", panel); 66 67 Panel controls = new Panel(); 68 controls.setLayout(new GridLayout(0, 2)); 69 70 // Menu for setting the alignment of the main FlowLayout panel 71 { 72 Choice c = new Choice(); 73 c.addItem("LEFT"); 74 c.addItem("CENTER"); 75 c.addItem("RIGHT"); 76 c.addItem("LEADING"); 77 c.addItem("TRAILING"); 78 c.addItemListener( new ItemListener() { 79 public void itemStateChanged(ItemEvent e) { 80 String item = (String)(e.getItem()); 81 FlowLayout layout = (FlowLayout) panel.getLayout(); 82 83 if (item.equals("LEFT")) { 84 layout.setAlignment(FlowLayout.LEFT); 85 } else if (item.equals("CENTER")) { 86 layout.setAlignment(FlowLayout.CENTER); 87 } else if (item.equals("RIGHT")) { 88 layout.setAlignment(FlowLayout.RIGHT); 89 } else if (item.equals("LEADING")) { 90 layout.setAlignment(FlowLayout.LEADING); 91 } else if (item.equals("TRAILING")) { 92 layout.setAlignment(FlowLayout.TRAILING); 93 } 94 panel.layout(); 95 panel.repaint(); 96 } 97 } ); 98 controls.add(new Label("FlowLayout Alignment:")); 99 controls.add(c); 100 } 101 102 // Create a popup menu for switching the Panel between orientations 103 { 104 Choice c = new Choice(); 105 c.addItem("LEFT_TO_RIGHT"); 106 c.addItem("RIGHT_TO_LEFT"); 107 c.addItem("UNKNOWN"); 108 c.addItemListener( new ItemListener() { 109 public void itemStateChanged(ItemEvent e) { 110 String item = (String)(e.getItem()); 111 112 if (item.equals("LEFT_TO_RIGHT")) { 113 panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); 114 } else if (item.equals("RIGHT_TO_LEFT")) { 115 panel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 116 } else { 117 panel.setComponentOrientation(ComponentOrientation.UNKNOWN); 118 } 119 panel.layout(); 120 panel.repaint(); 121 } 122 } ); 123 124 controls.add(new Label("ComponentOrientation:")); 125 controls.add(c); 126 } 127 128 add("South", controls); 129 130 } 131 132 public static void main(String args[]) { 133 Frame f = new Frame("FlowTest"); 134 135 f.addWindowListener( new WindowAdapter() { 136 public void windowClosing(WindowEvent e) { 137 e.getWindow().hide(); 138 e.getWindow().dispose(); 139 System.exit(0); 140 }; 141 } ); 142 143 FlowTest flowTest = new FlowTest(); 144 flowTest.init(); 145 flowTest.start(); 146 147 f.add("Center", flowTest); 148 f.setSize(300, 300); 149 f.show(); 150 } 151 }