1 /*
   2  * Copyright (c) 2007, 2015, 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 import javax.swing.*;
  25 import java.awt.*;
  26 import java.util.Locale;
  27 
  28 /*
  29  * @test
  30  * @summary Check that Box.Filler constructors and methods do not throw
  31  *          unexpected exceptions in headless mode
  32  * @run main/othervm -Djava.awt.headless=true HeadlessBox_Filler
  33  */
  34 
  35 public class HeadlessBox_Filler {
  36     public static void main(String args[]) {
  37         Box.Filler bf = new Box.Filler(new Dimension(10, 10),
  38                 new Dimension(20, 20),
  39                 new Dimension(30, 30));
  40         bf.getMinimumSize();
  41         bf.getPreferredSize();
  42         bf.getMaximumSize();
  43         bf.getAccessibleContext();
  44         bf.requestFocus();
  45         bf.requestFocusInWindow();
  46         bf.contains(1, 2);
  47         Component c1 = bf.add(new Component(){});
  48         Component c2 = bf.add(new Component(){});
  49         Component c3 = bf.add(new Component(){});
  50         Insets ins = bf.getInsets();
  51         bf.getAlignmentY();
  52         bf.getAlignmentX();
  53         bf.getGraphics();
  54         bf.setVisible(false);
  55         bf.setVisible(true);
  56         bf.setEnabled(false);
  57         bf.setEnabled(true);
  58         bf.setForeground(Color.red);
  59         bf.setBackground(Color.red);
  60         for (String font : Toolkit.getDefaultToolkit().getFontList()) {
  61             for (int j = 8; j < 17; j++) {
  62                 Font f1 = new Font(font, Font.PLAIN, j);
  63                 Font f2 = new Font(font, Font.BOLD, j);
  64                 Font f3 = new Font(font, Font.ITALIC, j);
  65                 Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);
  66 
  67                 bf.setFont(f1);
  68                 bf.setFont(f2);
  69                 bf.setFont(f3);
  70                 bf.setFont(f4);
  71 
  72                 bf.getFontMetrics(f1);
  73                 bf.getFontMetrics(f2);
  74                 bf.getFontMetrics(f3);
  75                 bf.getFontMetrics(f4);
  76             }
  77         }
  78         bf.enable();
  79         bf.disable();
  80         bf.reshape(10, 10, 10, 10);
  81         bf.getBounds(new Rectangle(1, 1, 1, 1));
  82         bf.getSize(new Dimension(1, 2));
  83         bf.getLocation(new Point(1, 2));
  84         bf.getX();
  85         bf.getY();
  86         bf.getWidth();
  87         bf.getHeight();
  88         bf.isOpaque();
  89         bf.isValidateRoot();
  90         bf.isOptimizedDrawingEnabled();
  91         bf.isDoubleBuffered();
  92         bf.getComponentCount();
  93         bf.countComponents();
  94         bf.getComponent(1);
  95         bf.getComponent(2);
  96         Component[] cs = bf.getComponents();
  97         bf.getLayout();
  98         bf.setLayout(new FlowLayout());
  99         bf.doLayout();
 100         bf.layout();
 101         bf.invalidate();
 102         bf.validate();
 103         bf.preferredSize();
 104         bf.remove(0);
 105         bf.remove(c2);
 106         bf.removeAll();
 107         bf.minimumSize();
 108         bf.getComponentAt(1, 2);
 109         bf.locate(1, 2);
 110         bf.getComponentAt(new Point(1, 2));
 111         bf.isFocusCycleRoot(new Container());
 112         bf.transferFocusBackward();
 113         bf.setName("goober");
 114         bf.getName();
 115         bf.getParent();
 116         bf.getGraphicsConfiguration();
 117         bf.getTreeLock();
 118         bf.getToolkit();
 119         bf.isValid();
 120         bf.isDisplayable();
 121         bf.isVisible();
 122         bf.isShowing();
 123         bf.isEnabled();
 124         bf.enable(false);
 125         bf.enable(true);
 126         bf.enableInputMethods(false);
 127         bf.enableInputMethods(true);
 128         bf.show();
 129         bf.show(false);
 130         bf.show(true);
 131         bf.hide();
 132         bf.getForeground();
 133         bf.isForegroundSet();
 134         bf.getBackground();
 135         bf.isBackgroundSet();
 136         bf.getFont();
 137         bf.isFontSet();
 138 
 139         Container c = new Container();
 140         c.add(bf);
 141         bf.getLocale();
 142 
 143         for (Locale locale : Locale.getAvailableLocales())
 144             bf.setLocale(locale);
 145 
 146         bf.getColorModel();
 147         bf.getLocation();
 148 
 149         boolean exceptions = false;
 150         try {
 151             bf.getLocationOnScreen();
 152         } catch (IllegalComponentStateException e) {
 153             exceptions = true;
 154         }
 155         if (!exceptions)
 156             throw new RuntimeException("IllegalComponentStateException did not occur when expected");
 157 
 158         bf.setLocation(1, 2);
 159         bf.move(1, 2);
 160         bf.setLocation(new Point(1, 2));
 161         bf.getSize();
 162         bf.size();
 163         bf.setSize(1, 32);
 164         bf.resize(1, 32);
 165         bf.setSize(new Dimension(1, 32));
 166         bf.resize(new Dimension(1, 32));
 167         bf.getBounds();
 168         bf.bounds();
 169         bf.setBounds(10, 10, 10, 10);
 170         bf.setBounds(new Rectangle(10, 10, 10, 10));
 171         bf.isLightweight();
 172         bf.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
 173         bf.getCursor();
 174         bf.isCursorSet();
 175         bf.inside(1, 2);
 176         bf.contains(new Point(1, 2));
 177         bf.isFocusTraversable();
 178         bf.isFocusable();
 179         bf.setFocusable(true);
 180         bf.setFocusable(false);
 181         bf.transferFocus();
 182         bf.getFocusCycleRootAncestor();
 183         bf.nextFocus();
 184         bf.transferFocusUpCycle();
 185         bf.hasFocus();
 186         bf.isFocusOwner();
 187         bf.toString();
 188         bf.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
 189         bf.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
 190         bf.setComponentOrientation(ComponentOrientation.UNKNOWN);
 191         bf.getComponentOrientation();
 192     }
 193 }