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