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