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