test/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java

Print this page




  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 
  25 import java.awt.Color;
  26 import java.awt.Dimension;
  27 import java.awt.GridLayout;
  28 import java.awt.Point;
  29 import java.awt.Robot;
  30 import java.awt.event.ActionEvent;
  31 import java.awt.event.ActionListener;
  32 import java.awt.event.InputEvent;
  33 import javax.swing.JButton;
  34 import javax.swing.JFrame;
  35 import javax.swing.JPanel;
  36 import javax.swing.JScrollPane;
  37 import javax.swing.JSplitPane;
  38 import javax.swing.SwingUtilities;

  39 
  40 /**
  41  * AWT/Swing overlapping test for {@link javax.swing.JSplitPane } component.
  42  * <p>This test creates puts heavyweight and lightweight components into different panels and test if splitter image and components itself are drawn correctly.
  43  * <p>See base class for test info.
  44  */
  45 /*
  46 @test
  47 @bug 6986109
  48 @summary Overlapping test for javax.swing.JSplitPane
  49 @author sergey.grinev@oracle.com: area=awt.mixing


  50 @run main JSplitPaneOverlapping
  51  */
  52 public class JSplitPaneOverlapping extends OverlappingTestBase {
  53 
  54     private boolean clicked = false;
  55     private Point splitterLoc;
  56     private JScrollPane sp1;
  57     private JScrollPane sp2;
  58 
  59     protected void prepareControls() {
  60         JFrame frame = new JFrame("SplitPane Mixing");
  61         JPanel p = new JPanel(new GridLayout());
  62         p.setPreferredSize(new Dimension(500, 500));
  63         propagateAWTControls(p);
  64         sp1 = new JScrollPane(p);
  65 
  66         JButton button = new JButton("JButton");
  67         button.setBackground(Color.RED);
  68         button.addActionListener(new ActionListener() {
  69 


  82         frame.getContentPane().add(splitPane);
  83         frame.pack();
  84         frame.setVisible(true);
  85     }
  86 
  87     private static final boolean ignoreFail = false;
  88 
  89     @Override
  90     protected boolean performTest() {
  91         try {
  92             SwingUtilities.invokeAndWait(new Runnable() {
  93                 public void run() {
  94                     splitterLoc = sp2.getLocationOnScreen();
  95                     Point leftLoc = sp1.getLocationOnScreen();
  96                     leftLoc.translate(sp1.getWidth(), 0);
  97                     splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);
  98                 }
  99             });
 100         } catch (Exception e) {
 101             e.printStackTrace();
 102             System.exit(1);
 103         }
 104         // run robot
 105         Robot robot = Util.createRobot();
 106         robot.setAutoDelay(ROBOT_DELAY);
 107 
 108         robot.mouseMove(splitterLoc.x, splitterLoc.y);
 109         Util.waitForIdle(robot);
 110 
 111         robot.mousePress(InputEvent.BUTTON1_MASK);
 112         robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);
 113         Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);
 114         System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);
 115         if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {
 116             fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");
 117         }
 118         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 119 
 120         clickAndBlink(robot, splitterLoc);
 121 
 122         return clicked;


  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 
  25 import java.awt.Color;
  26 import java.awt.Dimension;
  27 import java.awt.GridLayout;
  28 import java.awt.Point;
  29 import java.awt.Robot;
  30 import java.awt.event.ActionEvent;
  31 import java.awt.event.ActionListener;
  32 import java.awt.event.InputEvent;
  33 import javax.swing.JButton;
  34 import javax.swing.JFrame;
  35 import javax.swing.JPanel;
  36 import javax.swing.JScrollPane;
  37 import javax.swing.JSplitPane;
  38 import javax.swing.SwingUtilities;
  39 import test.java.awt.regtesthelpers.Util;
  40 
  41 /**
  42  * AWT/Swing overlapping test for {@link javax.swing.JSplitPane } component.
  43  * <p>This test creates puts heavyweight and lightweight components into different panels and test if splitter image and components itself are drawn correctly.
  44  * <p>See base class for test info.
  45  */
  46 /*
  47 @test
  48 @bug 6986109
  49 @summary Overlapping test for javax.swing.JSplitPane
  50 @author sergey.grinev@oracle.com: area=awt.mixing
  51 @library ../../regtesthelpers
  52 @build Util
  53 @run main JSplitPaneOverlapping
  54  */
  55 public class JSplitPaneOverlapping extends OverlappingTestBase {
  56 
  57     private boolean clicked = false;
  58     private Point splitterLoc;
  59     private JScrollPane sp1;
  60     private JScrollPane sp2;
  61 
  62     protected void prepareControls() {
  63         JFrame frame = new JFrame("SplitPane Mixing");
  64         JPanel p = new JPanel(new GridLayout());
  65         p.setPreferredSize(new Dimension(500, 500));
  66         propagateAWTControls(p);
  67         sp1 = new JScrollPane(p);
  68 
  69         JButton button = new JButton("JButton");
  70         button.setBackground(Color.RED);
  71         button.addActionListener(new ActionListener() {
  72 


  85         frame.getContentPane().add(splitPane);
  86         frame.pack();
  87         frame.setVisible(true);
  88     }
  89 
  90     private static final boolean ignoreFail = false;
  91 
  92     @Override
  93     protected boolean performTest() {
  94         try {
  95             SwingUtilities.invokeAndWait(new Runnable() {
  96                 public void run() {
  97                     splitterLoc = sp2.getLocationOnScreen();
  98                     Point leftLoc = sp1.getLocationOnScreen();
  99                     leftLoc.translate(sp1.getWidth(), 0);
 100                     splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);
 101                 }
 102             });
 103         } catch (Exception e) {
 104             e.printStackTrace();
 105             throw new RuntimeException("Where is splitter?");
 106         }
 107         // run robot
 108         Robot robot = Util.createRobot();
 109         robot.setAutoDelay(ROBOT_DELAY);
 110 
 111         robot.mouseMove(splitterLoc.x, splitterLoc.y);
 112         Util.waitForIdle(robot);
 113 
 114         robot.mousePress(InputEvent.BUTTON1_MASK);
 115         robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);
 116         Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);
 117         System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);
 118         if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {
 119             fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");
 120         }
 121         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 122 
 123         clickAndBlink(robot, splitterLoc);
 124 
 125         return clicked;