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.bin.Jalview;
27 import jalview.gui.JvOptionPane;
29 import java.awt.Button;
30 import java.awt.Event;
31 import java.awt.Toolkit;
32 import java.awt.event.MouseEvent;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
37 public class PlatformTest
40 @BeforeClass(alwaysRun = true)
41 public void setUpJvOptionPane()
43 JvOptionPane.setInteractiveMode(false);
44 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
47 Button b = new Button();
50 * isControlDown for Mac should answer true for Meta-down, but not for right
51 * mouse (popup trigger)
53 @Test(groups = "Functional")
54 public void testIsControlDown_mac()
57 boolean isPopupTrigger = false;
58 int buttonNo = MouseEvent.BUTTON1;
61 assertFalse(Jalview.isHeadlessMode());
62 Toolkit toolkit = Toolkit.getDefaultToolkit();
63 System.err.println("Toolkit is " + toolkit.getClass().getName());
64 System.err.println("getMenuShortcutKeyMask is "
65 + toolkit.getMenuShortcutKeyMask());
68 // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
69 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
70 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
72 mods = Event.CTRL_MASK;
73 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
74 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
76 mods = Event.META_MASK;
77 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
78 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
80 isPopupTrigger = true;
81 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
82 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
84 isPopupTrigger = false;
85 buttonNo = MouseEvent.BUTTON2;
87 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
88 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
92 * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
95 @Test(groups = "Functional")
96 public void testIsControlDown_notMac()
99 boolean isPopupTrigger = false;
100 int buttonNo = MouseEvent.BUTTON1;
104 // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
105 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
106 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
108 mods = Event.CTRL_MASK;
109 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
110 0, 0, clickCount, isPopupTrigger, buttonNo), mac));
112 mods = Event.CTRL_MASK | Event.SHIFT_MASK | Event.ALT_MASK;
115 isPopupTrigger = true;
116 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
117 0, 0, clickCount, isPopupTrigger, buttonNo), mac));