< prev index next >

test/javax/swing/JMenuItem/8158566/CloseOnMouseClickPropertyTest.java

Print this page
rev 17565 : 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
Summary: Add new keyword 'printer'. Some minor test fixes to show headless exception. Add some @requires windows.
Reviewed-by: serb, mbaesken
   1 /*
   2  * Copyright (c) 2016, 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 java.awt.Point;
  25 import java.awt.Rectangle;
  26 import java.awt.Robot;
  27 import java.awt.event.InputEvent;
  28 import javax.swing.JCheckBoxMenuItem;
  29 import javax.swing.JComponent;
  30 import javax.swing.JFrame;
  31 import javax.swing.JMenu;
  32 import javax.swing.JMenuBar;
  33 import javax.swing.JMenuItem;
  34 import javax.swing.JRadioButtonMenuItem;
  35 import javax.swing.SwingUtilities;
  36 import javax.swing.UIManager;
  37 
  38 /*
  39  * @test

  40  * @bug 8158566 8160879 8160977 8158566
  41  * @summary Provide a Swing property which modifies MenuItemUI behaviour
  42  */

  43 public class CloseOnMouseClickPropertyTest {
  44 
  45     private static final String CHECK_BOX_PROP = "CheckBoxMenuItem."
  46             + "doNotCloseOnMouseClick";
  47     private static final String RADIO_BUTTON_PROP = "RadioButtonMenuItem"
  48             + ".doNotCloseOnMouseClick";
  49 
  50     private static JFrame frame;
  51     private static JMenu menu;
  52 
  53     private static TestItem[] TEST_ITEMS = {
  54         new TestItem(TestType.CHECK_BOX_MENU_ITEM, true, true),
  55         new TestItem(TestType.CHECK_BOX_MENU_ITEM, true, false),
  56         new TestItem(TestType.CHECK_BOX_MENU_ITEM, false, true),
  57         new TestItem(TestType.CHECK_BOX_MENU_ITEM, false, false),
  58 
  59         new TestItem(TestType.CHECK_BOX_MENU_ITEM, null, true),
  60         new TestItem(TestType.CHECK_BOX_MENU_ITEM, null, false),
  61         new TestItem(TestType.CHECK_BOX_MENU_ITEM, true, null),
  62         new TestItem(TestType.CHECK_BOX_MENU_ITEM, false, null),


 203                 default:
 204                     menuItem.putClientProperty(CHECK_BOX_PROP, compDoNotCloseOnMouseClick);
 205                     menuItem.putClientProperty(RADIO_BUTTON_PROP, compDoNotCloseOnMouseClick);
 206                     UIManager.put(CHECK_BOX_PROP, lafDoNotCloseOnMouseClick);
 207                     UIManager.put(RADIO_BUTTON_PROP, lafDoNotCloseOnMouseClick);
 208             }
 209         }
 210 
 211         JMenuItem getMenuItem() {
 212             switch (type) {
 213                 case CHECK_BOX_MENU_ITEM:
 214                     return new JCheckBoxMenuItem("Check Box");
 215                 case RADIO_BUTTON_MENU_ITEM:
 216                     return new JRadioButtonMenuItem("Radio Button");
 217                 default:
 218                     return new JMenuItem("Menu Item");
 219             }
 220         }
 221     }
 222 }

   1 /*
   2  * Copyright (c) 2016, 2017, 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 java.awt.Point;
  25 import java.awt.Rectangle;
  26 import java.awt.Robot;
  27 import java.awt.event.InputEvent;
  28 import javax.swing.JCheckBoxMenuItem;
  29 import javax.swing.JComponent;
  30 import javax.swing.JFrame;
  31 import javax.swing.JMenu;
  32 import javax.swing.JMenuBar;
  33 import javax.swing.JMenuItem;
  34 import javax.swing.JRadioButtonMenuItem;
  35 import javax.swing.SwingUtilities;
  36 import javax.swing.UIManager;
  37 
  38 /**
  39  * @test
  40  * @key headful
  41  * @bug 8158566 8160879 8160977 8158566
  42  * @summary Provide a Swing property which modifies MenuItemUI behaviour
  43  */
  44 
  45 public class CloseOnMouseClickPropertyTest {
  46 
  47     private static final String CHECK_BOX_PROP = "CheckBoxMenuItem."
  48             + "doNotCloseOnMouseClick";
  49     private static final String RADIO_BUTTON_PROP = "RadioButtonMenuItem"
  50             + ".doNotCloseOnMouseClick";
  51 
  52     private static JFrame frame;
  53     private static JMenu menu;
  54 
  55     private static TestItem[] TEST_ITEMS = {
  56         new TestItem(TestType.CHECK_BOX_MENU_ITEM, true, true),
  57         new TestItem(TestType.CHECK_BOX_MENU_ITEM, true, false),
  58         new TestItem(TestType.CHECK_BOX_MENU_ITEM, false, true),
  59         new TestItem(TestType.CHECK_BOX_MENU_ITEM, false, false),
  60 
  61         new TestItem(TestType.CHECK_BOX_MENU_ITEM, null, true),
  62         new TestItem(TestType.CHECK_BOX_MENU_ITEM, null, false),
  63         new TestItem(TestType.CHECK_BOX_MENU_ITEM, true, null),
  64         new TestItem(TestType.CHECK_BOX_MENU_ITEM, false, null),


 205                 default:
 206                     menuItem.putClientProperty(CHECK_BOX_PROP, compDoNotCloseOnMouseClick);
 207                     menuItem.putClientProperty(RADIO_BUTTON_PROP, compDoNotCloseOnMouseClick);
 208                     UIManager.put(CHECK_BOX_PROP, lafDoNotCloseOnMouseClick);
 209                     UIManager.put(RADIO_BUTTON_PROP, lafDoNotCloseOnMouseClick);
 210             }
 211         }
 212 
 213         JMenuItem getMenuItem() {
 214             switch (type) {
 215                 case CHECK_BOX_MENU_ITEM:
 216                     return new JCheckBoxMenuItem("Check Box");
 217                 case RADIO_BUTTON_MENU_ITEM:
 218                     return new JRadioButtonMenuItem("Radio Button");
 219                 default:
 220                     return new JMenuItem("Menu Item");
 221             }
 222         }
 223     }
 224 }
 225 
< prev index next >