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