Path: blob/master/test/jdk/java/awt/ComponentOrientation/FlowTest.java
41149 views
/*1* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 410845327* @summary Test ComponentOrientation (Bidi) support in FlowLayout28*/29/*30* (C) Copyright IBM Corp. 1998 - All Rights Reserved31*32* The original version of this source code and documentation is copyrighted33* and owned by IBM, Inc. These materials are provided under terms of a34* License Agreement between IBM and Sun. This technology is protected by35* multiple US and International patents. This notice and attribution to IBM36* may not be removed.37*/3839import java.awt.*;40import java.awt.event.*;4142public class FlowTest extends Panel {43Panel panel;4445public FlowTest() {46setLayout(new BorderLayout());4748// Create a panel with a FlowLayout and a bunch of buttons in it49panel = new Panel();50panel.setLayout(new FlowLayout(FlowLayout.LEFT));51panel.add(new Button("one"));52panel.add(new Button("two"));53panel.add(new Button("three"));54panel.add(new Button("four"));55panel.add(new Button("five"));56panel.add(new Button("six"));57panel.add(new Button("seven"));58panel.add(new Button("eight"));59panel.add(new Button("nine"));60panel.add(new Button("ten"));61panel.add(new Button("eleven"));6263add("Center", panel);6465Panel controls = new Panel();66controls.setLayout(new GridLayout(0, 2));6768// Menu for setting the alignment of the main FlowLayout panel69{70Choice c = new Choice();71c.addItem("LEFT");72c.addItem("CENTER");73c.addItem("RIGHT");74c.addItem("LEADING");75c.addItem("TRAILING");76c.addItemListener( new ItemListener() {77public void itemStateChanged(ItemEvent e) {78String item = (String)(e.getItem());79FlowLayout layout = (FlowLayout) panel.getLayout();8081if (item.equals("LEFT")) {82layout.setAlignment(FlowLayout.LEFT);83} else if (item.equals("CENTER")) {84layout.setAlignment(FlowLayout.CENTER);85} else if (item.equals("RIGHT")) {86layout.setAlignment(FlowLayout.RIGHT);87} else if (item.equals("LEADING")) {88layout.setAlignment(FlowLayout.LEADING);89} else if (item.equals("TRAILING")) {90layout.setAlignment(FlowLayout.TRAILING);91}92panel.layout();93panel.repaint();94}95} );96controls.add(new Label("FlowLayout Alignment:"));97controls.add(c);98}99100// Create a popup menu for switching the Panel between orientations101{102Choice c = new Choice();103c.addItem("LEFT_TO_RIGHT");104c.addItem("RIGHT_TO_LEFT");105c.addItem("UNKNOWN");106c.addItemListener( new ItemListener() {107public void itemStateChanged(ItemEvent e) {108String item = (String)(e.getItem());109110if (item.equals("LEFT_TO_RIGHT")) {111panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);112} else if (item.equals("RIGHT_TO_LEFT")) {113panel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);114} else {115panel.setComponentOrientation(ComponentOrientation.UNKNOWN);116}117panel.layout();118panel.repaint();119}120} );121122controls.add(new Label("ComponentOrientation:"));123controls.add(c);124}125126add("South", controls);127128}129130public static void main(String args[]) {131Frame f = new Frame("FlowTest");132133f.addWindowListener( new WindowAdapter() {134public void windowClosing(WindowEvent e) {135e.getWindow().hide();136e.getWindow().dispose();137System.exit(0);138};139} );140141FlowTest flowTest = new FlowTest();142143f.add("Center", flowTest);144f.setSize(300, 300);145f.show();146}147}148149150