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