1 /* 2 * Copyright (c) 2010, 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 org.jtregext.GuiTestListener; 25 import com.sun.swingset3.demos.splitpane.SplitPaneDemo; 26 import static com.sun.swingset3.demos.splitpane.SplitPaneDemo.*; 27 import java.awt.event.KeyEvent; 28 import javax.swing.JSplitPane; 29 import static org.testng.AssertJUnit.*; 30 import org.testng.annotations.Test; 31 import org.netbeans.jemmy.ClassReference; 32 import org.netbeans.jemmy.operators.JButtonOperator; 33 import org.netbeans.jemmy.operators.JCheckBoxOperator; 34 import org.netbeans.jemmy.operators.JFrameOperator; 35 import org.netbeans.jemmy.operators.JRadioButtonOperator; 36 import org.netbeans.jemmy.operators.JSplitPaneOperator; 37 import org.netbeans.jemmy.operators.JTextFieldOperator; 38 import static org.jemmy2ext.JemmyExt.*; 39 import org.testng.annotations.Listeners; 40 41 /* 42 * @test 43 * @key headful 44 * @summary Verifies SwingSet3 SplitPaneDemo by performing OneClick expansion, 45 * changing size of the divier, moving the divider to different positions 46 * and changing the divider orientation. 47 * 48 * @library /sanity/client/lib/jemmy/src 49 * @library /sanity/client/lib/Extensions/src 50 * @library /sanity/client/lib/SwingSet3/src 51 * @build org.jemmy2ext.JemmyExt 52 * @build com.sun.swingset3.demos.splitpane.SplitPaneDemo 53 * @run testng SplitPaneDemoTest 54 */ 55 @Listeners(GuiTestListener.class) 56 public class SplitPaneDemoTest { 57 58 @Test 59 public void test() throws Exception { 60 61 new ClassReference(SplitPaneDemo.class.getCanonicalName()).startApplication(); 62 63 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); 64 65 JSplitPaneOperator splitPane = new JSplitPaneOperator(frame); 66 67 // Toggle OneTouch Expandable 68 checkOneTouch(frame, splitPane, true); 69 checkOneTouch(frame, splitPane, false); 70 71 // Check changing divider size to minimum and maximum values 72 changeDividerSize(frame, splitPane, 50); 73 changeDividerSize(frame, splitPane, 6); 74 75 // Check moving the divider 76 checkDividerMoves(frame, splitPane, false); 77 checkDividerMoves(frame, splitPane, true); 78 79 // Check different minumum Day/Night sizes 80 changeMinimumSizes(frame, splitPane, 100); 81 changeMinimumSizes(frame, splitPane, 0); 82 } 83 84 // Check for different day and night minimum size 85 public void changeMinimumSizes(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception { 86 for (String label : new String[]{FIRST_COMPONENT_MIN_SIZE, SECOND_COMPONENT_MIN_SIZE}) { 87 JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, label)); 88 size.enterText(Integer.toString(amount)); 89 size.pressKey(KeyEvent.VK_ENTER); 90 } 91 checkDividerMoves(frame, splitPane, false); 92 checkDividerMoves(frame, splitPane, true); 93 } 94 95 // Check moving of divider 96 public void checkDividerMoves(JFrameOperator frame, JSplitPaneOperator splitPane, boolean isVertical) throws Exception { 97 if (isVertical) { 98 new JRadioButtonOperator(frame, VERTICAL_SPLIT).doClick(); 99 } else { 100 new JRadioButtonOperator(frame, HORIZONTAL_SPLIT).doClick(); 101 } 102 103 splitPane.moveDivider(0.0); 104 assertEquals("Move Minimum, dividerLocation is at minimumDividerLocation", 105 splitPane.getMinimumDividerLocation(), splitPane.getDividerLocation()); 106 107 // use getMaximumDividerLocation() to move divider to here because using proportion 1.0 does not work 108 splitPane.moveDivider(1.0); 109 110 assertEquals("Move Maximum, dividerLocation is at maximumDividerLocation", 111 splitPane.getMaximumDividerLocation(), splitPane.getDividerLocation()); 112 113 splitPane.moveDivider(0.5); 114 assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations", 115 (splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation()); 116 } 117 118 // Check changing the size of the divider 119 public void changeDividerSize(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception { 120 JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, DIVIDER_SIZE)); 121 size.clearText(); 122 size.typeText(Integer.toString(amount)); 123 size.pressKey(KeyEvent.VK_ENTER); 124 125 assertEquals("Change Divider Size", amount, splitPane.getDividerSize()); 126 } 127 128 public void checkOneTouch(JFrameOperator frame, JSplitPaneOperator splitPane, boolean oneTouch) throws Exception { 129 JCheckBoxOperator checkBox = new JCheckBoxOperator(frame, ONE_TOUCH_EXPANDABLE); 130 JButtonOperator buttonLeft = new JButtonOperator(splitPane.getDivider(), 0); 131 JButtonOperator buttonRight = new JButtonOperator(splitPane.getDivider(), 1); 132 int initDividerLocation = splitPane.getDividerLocation(); 133 134 if (oneTouch) { 135 if (!checkBox.isSelected()) { 136 // uncheck 137 checkBox.doClick(); 138 } 139 140 int left = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().left); 141 System.out.println("left = " + left); 142 int right = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().right); 143 System.out.println("right = " + right); 144 145 // expand full left 146 buttonLeft.push(); 147 assertEquals("Expandable Left", left, splitPane.getDividerLocation()); 148 149 // expand back from full left 150 buttonRight.push(); 151 assertEquals("Expandable Back to Original from Left", 152 initDividerLocation, splitPane.getDividerLocation()); 153 154 // expand all the way right 155 buttonRight.push(); 156 assertEquals("Expandable Right", 157 splitPane.getWidth() - splitPane.getDividerSize() - right, 158 splitPane.getDividerLocation()); 159 160 // Click to move back from right expansion 161 buttonLeft.push(); 162 assertEquals("Expandable Back to Original from Right", 163 initDividerLocation, splitPane.getDividerLocation()); 164 } 165 166 // Test for case where one touch expandable is disabled 167 if (!oneTouch) { 168 if (checkBox.isSelected()) { 169 // uncheck 170 checkBox.doClick(); 171 } 172 assertFalse("One Touch Expandable Off", splitPane.isOneTouchExpandable()); 173 } 174 } 175 176 }