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