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