2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertFalse;
24 import static org.testng.Assert.assertTrue;
26 import jalview.gui.JvOptionPane;
28 import java.awt.Button;
29 import java.awt.Event;
30 import java.awt.Toolkit;
31 import java.awt.event.MouseEvent;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.Test;
36 public class PlatformTest
39 @BeforeClass(alwaysRun = true)
40 public void setUpJvOptionPane()
42 JvOptionPane.setInteractiveMode(false);
43 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
46 Button b = new Button();
49 * isControlDown for Mac should answer true for Meta-down, but not for right
50 * mouse (popup trigger)
52 @Test(groups = "Functional")
53 public void testIsControlDown_mac()
55 String toolkit = Toolkit.getDefaultToolkit().getClass().getName();
56 if ("sun.awt.X11.XToolkit".equals(toolkit))
59 * this toolkit on the build server fails these tests,
60 * because it returns 2, not 4, for getMenuShortcutKeyMask
66 boolean isPopupTrigger = false;
67 int buttonNo = MouseEvent.BUTTON1;
71 // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
72 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
73 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
75 mods = Event.CTRL_MASK;
76 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
77 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
79 mods = Event.META_MASK;
80 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
81 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
83 isPopupTrigger = true;
84 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
85 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
87 isPopupTrigger = false;
88 buttonNo = MouseEvent.BUTTON2;
90 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
91 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
95 * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
98 @Test(groups = "Functional")
99 public void testIsControlDown_notMac()
102 boolean isPopupTrigger = false;
103 int buttonNo = MouseEvent.BUTTON1;
107 // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
108 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
109 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
111 mods = Event.CTRL_MASK;
112 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
113 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
115 mods = Event.CTRL_MASK | Event.SHIFT_MASK | Event.ALT_MASK;
118 isPopupTrigger = true;
119 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
120 0, 0, clickCount, isPopupTrigger, buttonNo), mac));