< prev index next >

test/java/awt/Choice/ChoicePopupLocation/ChoicePopupLocation.java

Print this page




  25 import java.awt.FlowLayout;
  26 import java.awt.Frame;
  27 import java.awt.GraphicsConfiguration;
  28 import java.awt.GraphicsDevice;
  29 import java.awt.GraphicsEnvironment;
  30 import java.awt.Insets;
  31 import java.awt.Point;
  32 import java.awt.Rectangle;
  33 import java.awt.Robot;
  34 import java.awt.Toolkit;
  35 import java.awt.event.InputEvent;
  36 
  37 /**
  38  * @test
  39  * @bug 8176448
  40  * @run main/timeout=300 ChoicePopupLocation
  41  */
  42 public final class ChoicePopupLocation {
  43 
  44     private static final int SIZE = 350;

  45 
  46     public static void main(final String[] args) throws Exception {
  47         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  48         GraphicsDevice[] sds = ge.getScreenDevices();
  49         Point left = null;

  50         for (GraphicsDevice sd : sds) {
  51             GraphicsConfiguration gc = sd.getDefaultConfiguration();
  52             Rectangle bounds = gc.getBounds();
  53             if (left == null || left.x > bounds.x) {
  54                 left = new Point(bounds.x, bounds.y + bounds.height / 2);
  55             }




  56 
  57             Point point = new Point(bounds.x, bounds.y);
  58             Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
  59             while (point.y < bounds.y + bounds.height - insets.bottom - SIZE ) {
  60                 while (point.x < bounds.x + bounds.width - insets.right - SIZE) {
  61                     test(point);
  62                     point.translate(bounds.width / 5, 0);
  63                 }
  64                 point.setLocation(bounds.x, point.y + bounds.height / 5);
  65             }
  66 
  67         }
  68         if (left != null) {
  69             left.translate(-50, 0);
  70             test(left);
  71         }




  72     }
  73 
  74     private static void test(final Point tmp) throws Exception {
  75         Choice choice = new Choice();
  76         for (int i = 1; i < 7; i++) {
  77             choice.add("Long-long-long-long-long text in the item-" + i);
  78         }
  79         Frame frame = new Frame();
  80         try {
  81             frame.setAlwaysOnTop(true);
  82             frame.setLayout(new FlowLayout());
  83             frame.add(choice);
  84             frame.pack();
  85             frame.setSize(frame.getWidth(), SIZE);

  86             frame.setVisible(true);
  87             frame.setLocation(tmp.x, tmp.y);
  88             openPopup(choice);
  89         } finally {
  90             frame.dispose();
  91         }
  92     }
  93 
  94     private static void openPopup(final Choice choice) throws Exception {
  95         Robot robot = new Robot();
  96         robot.setAutoDelay(100);
  97         robot.setAutoWaitForIdle(true);
  98         robot.waitForIdle();
  99         Point pt = choice.getLocationOnScreen();
 100         robot.mouseMove(pt.x + choice.getWidth() / 2,
 101                         pt.y + choice.getHeight() / 2);
 102         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
 103         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
 104         int x = pt.x + choice.getWidth() / 2;
 105         int y = pt.y + choice.getHeight() / 2 + 70;


  25 import java.awt.FlowLayout;
  26 import java.awt.Frame;
  27 import java.awt.GraphicsConfiguration;
  28 import java.awt.GraphicsDevice;
  29 import java.awt.GraphicsEnvironment;
  30 import java.awt.Insets;
  31 import java.awt.Point;
  32 import java.awt.Rectangle;
  33 import java.awt.Robot;
  34 import java.awt.Toolkit;
  35 import java.awt.event.InputEvent;
  36 
  37 /**
  38  * @test
  39  * @bug 8176448
  40  * @run main/timeout=300 ChoicePopupLocation
  41  */
  42 public final class ChoicePopupLocation {
  43 
  44     private static final int SIZE = 350;
  45     private static int frameWidth;
  46 
  47     public static void main(final String[] args) throws Exception {
  48         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  49         GraphicsDevice[] sds = ge.getScreenDevices();
  50         Point left = null;
  51         Point right = null;
  52         for (GraphicsDevice sd : sds) {
  53             GraphicsConfiguration gc = sd.getDefaultConfiguration();
  54             Rectangle bounds = gc.getBounds();
  55             if (left == null || left.x > bounds.x) {
  56                 left = new Point(bounds.x, bounds.y + bounds.height / 2);
  57             }
  58             if (right == null || right.x < bounds.x + bounds.width) {
  59                 right = new Point(bounds.x + bounds.width,
  60                                   bounds.y + bounds.height / 2);
  61             }
  62 
  63             Point point = new Point(bounds.x, bounds.y);
  64             Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
  65             while (point.y < bounds.y + bounds.height - insets.bottom - SIZE ) {
  66                 while (point.x < bounds.x + bounds.width - insets.right - SIZE) {
  67                     test(point);
  68                     point.translate(bounds.width / 5, 0);
  69                 }
  70                 point.setLocation(bounds.x, point.y + bounds.height / 5);
  71             }
  72 
  73         }
  74         if (left != null) {
  75             left.translate(-50, 0);
  76             test(left);
  77         }
  78         if (right != null) {
  79             right.translate(-frameWidth + 50, 0);
  80             test(right);
  81         }
  82     }
  83 
  84     private static void test(final Point tmp) throws Exception {
  85         Choice choice = new Choice();
  86         for (int i = 1; i < 7; i++) {
  87             choice.add("Long-long-long-long-long text in the item-" + i);
  88         }
  89         Frame frame = new Frame();
  90         try {
  91             frame.setAlwaysOnTop(true);
  92             frame.setLayout(new FlowLayout());
  93             frame.add(choice);
  94             frame.pack();
  95             frameWidth = frame.getWidth();
  96             frame.setSize(frameWidth, SIZE);
  97             frame.setVisible(true);
  98             frame.setLocation(tmp.x, tmp.y);
  99             openPopup(choice);
 100         } finally {
 101             frame.dispose();
 102         }
 103     }
 104 
 105     private static void openPopup(final Choice choice) throws Exception {
 106         Robot robot = new Robot();
 107         robot.setAutoDelay(100);
 108         robot.setAutoWaitForIdle(true);
 109         robot.waitForIdle();
 110         Point pt = choice.getLocationOnScreen();
 111         robot.mouseMove(pt.x + choice.getWidth() / 2,
 112                         pt.y + choice.getHeight() / 2);
 113         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
 114         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
 115         int x = pt.x + choice.getWidth() / 2;
 116         int y = pt.y + choice.getHeight() / 2 + 70;
< prev index next >