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