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