test/java/awt/Mixing/AWT_Mixing/HierarchyBoundsListenerMixingTest.java

Print this page




  59         list.add("Three");
  60         choice = new Choice();
  61         choice.add("Red");
  62         choice.add("Orange");
  63         choice.add("Yellow");
  64         checkbox = new Checkbox("Checkbox");
  65         scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
  66         textfield = new TextField(15);
  67         textarea = new TextArea(5, 15);
  68 
  69         components = new Component[] {
  70             panel, button, label, list, choice, checkbox, scrollbar, textfield, textarea
  71         };
  72         ancestorResized = new boolean[components.length];
  73         ancestorMoved = new boolean[components.length];
  74 
  75         frame.addWindowListener(new WindowAdapter() {
  76             @Override
  77             public void windowClosing(WindowEvent event) {
  78                 System.err.println("User closed the window");
  79                 System.exit(1);
  80             }
  81         });
  82 
  83         HierarchyBoundsListener listener = new HierarchyBoundsListenerImpl();
  84         for (int i = 0; i < components.length; i++) {
  85             components[i].addHierarchyBoundsListener(listener);
  86             frame.add(components[i]);
  87         }
  88         frame.setSize(300, 300);
  89         frame.setVisible(true);
  90     }
  91 
  92     private int frameBorderCounter() {
  93         String JAVA_HOME = System.getProperty("java.home");
  94 
  95         try {
  96             Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter");
  97             try {
  98                 p.waitFor();
  99             } catch (InterruptedException e) {


 114         byte[] buffer = new byte[4096];
 115         int len = 0;
 116         StringBuilder sb = new StringBuilder();
 117         try (InputStreamReader isr = new InputStreamReader(is)) {
 118             while ((len = is.read(buffer)) > 0) {
 119                 sb.append(new String(buffer, 0, len));
 120             }
 121         }
 122         return sb.toString();
 123     }
 124 
 125     protected boolean performTest() {
 126         int BORDER_SHIFT = frameBorderCounter();
 127         BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : BORDER_SHIFT / 2;
 128         Robot robot = null;
 129         try {
 130             robot = new Robot();
 131             Thread.sleep(delay * 10);
 132         } catch (Exception e) {
 133             e.printStackTrace();
 134             System.exit(1);
 135         }
 136 
 137         robot.mouseMove((int) components[0].getLocationOnScreen().x + components[0].getSize().width / 2,
 138                         (int) components[0].getLocationOnScreen().y + components[0].getSize().height / 2);
 139         robot.delay(delay);
 140         robot.mousePress(InputEvent.BUTTON1_MASK);
 141         robot.delay(delay);
 142         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 143         robot.delay(delay);
 144 
 145         resetValues();
 146         try {
 147             EventQueue.invokeAndWait(new Runnable() {
 148                 public void run() {
 149                     frame.setSize(new Dimension(frame.getSize().width + 10, frame.getSize().height + 10));
 150                     frame.invalidate();
 151                     frame.validate();
 152                 }
 153             });
 154         } catch (Exception e) {


 578 to read and understand someone else's test.
 579  ****************************************************/
 580 /**
 581 This is part of the standard test machinery.
 582 It creates a dialog (with the instructions), and is the interface
 583 for sending text messages to the user.
 584 To print the instructions, send an array of strings to Sysout.createDialog
 585 WithInstructions method.  Put one line of instructions per array entry.
 586 To display a message for the tester to see, simply call Sysout.println
 587 with the string to be displayed.
 588 This mimics System.out.println but works within the test harness as well
 589 as standalone.
 590  */
 591 class Sysout {
 592 
 593     private static TestDialog dialog;
 594 
 595     public static void createDialogWithInstructions(String[] instructions) {
 596         dialog = new TestDialog(new Frame(), "Instructions");
 597         dialog.printInstructions(instructions);
 598         dialog.setVisible(true);
 599         println("Any messages for the tester will display here.");
 600     }
 601 
 602     public static void createDialog() {
 603         dialog = new TestDialog(new Frame(), "Instructions");
 604         String[] defInstr = {"Instructions will appear here. ", ""};
 605         dialog.printInstructions(defInstr);
 606         dialog.setVisible(true);
 607         println("Any messages for the tester will display here.");
 608     }
 609 
 610     public static void printInstructions(String[] instructions) {
 611         dialog.printInstructions(instructions);
 612     }
 613 
 614     public static void println(String messageIn) {
 615         dialog.displayMessage(messageIn);
 616         System.out.println(messageIn);
 617     }
 618 }// Sysout  class
 619 
 620 /**
 621 This is part of the standard test machinery.  It provides a place for the
 622 test instructions to be displayed, and a place for interactive messages
 623 to the user to be displayed.
 624 To have the test instructions displayed, see Sysout.
 625 To have a message to the user be displayed, see Sysout.
 626 Do not call anything in this dialog directly.
 627  */
 628 class TestDialog extends Dialog {
 629 
 630     TextArea instructionsText;
 631     TextArea messageText;
 632     int maxStringLength = 80;
 633 
 634     //DO NOT call this directly, go through Sysout
 635     public TestDialog(Frame frame, String name) {
 636         super(frame, name);
 637         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 638         instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
 639         add("North", instructionsText);
 640 
 641         messageText = new TextArea("", 5, maxStringLength, scrollBoth);
 642         add("Center", messageText);
 643 
 644         pack();
 645 
 646         setVisible(true);
 647     }// TestDialog()
 648 
 649     //DO NOT call this directly, go through Sysout
 650     public void printInstructions(String[] instructions) {
 651         //Clear out any current instructions
 652         instructionsText.setText("");
 653 
 654         //Go down array of instruction strings
 655 
 656         String printStr, remainingStr;
 657         for (int i = 0; i < instructions.length; i++) {
 658             //chop up each into pieces maxSringLength long
 659             remainingStr = instructions[i];
 660             while (remainingStr.length() > 0) {
 661                 //if longer than max then chop off first max chars to print
 662                 if (remainingStr.length() >= maxStringLength) {
 663                     //Try to chop on a word boundary
 664                     int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
 665 
 666                     if (posOfSpace <= 0) {




  59         list.add("Three");
  60         choice = new Choice();
  61         choice.add("Red");
  62         choice.add("Orange");
  63         choice.add("Yellow");
  64         checkbox = new Checkbox("Checkbox");
  65         scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
  66         textfield = new TextField(15);
  67         textarea = new TextArea(5, 15);
  68 
  69         components = new Component[] {
  70             panel, button, label, list, choice, checkbox, scrollbar, textfield, textarea
  71         };
  72         ancestorResized = new boolean[components.length];
  73         ancestorMoved = new boolean[components.length];
  74 
  75         frame.addWindowListener(new WindowAdapter() {
  76             @Override
  77             public void windowClosing(WindowEvent event) {
  78                 System.err.println("User closed the window");

  79             }
  80         });
  81 
  82         HierarchyBoundsListener listener = new HierarchyBoundsListenerImpl();
  83         for (int i = 0; i < components.length; i++) {
  84             components[i].addHierarchyBoundsListener(listener);
  85             frame.add(components[i]);
  86         }
  87         frame.setSize(300, 300);
  88         frame.setVisible(true);
  89     }
  90 
  91     private int frameBorderCounter() {
  92         String JAVA_HOME = System.getProperty("java.home");
  93 
  94         try {
  95             Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter");
  96             try {
  97                 p.waitFor();
  98             } catch (InterruptedException e) {


 113         byte[] buffer = new byte[4096];
 114         int len = 0;
 115         StringBuilder sb = new StringBuilder();
 116         try (InputStreamReader isr = new InputStreamReader(is)) {
 117             while ((len = is.read(buffer)) > 0) {
 118                 sb.append(new String(buffer, 0, len));
 119             }
 120         }
 121         return sb.toString();
 122     }
 123 
 124     protected boolean performTest() {
 125         int BORDER_SHIFT = frameBorderCounter();
 126         BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : BORDER_SHIFT / 2;
 127         Robot robot = null;
 128         try {
 129             robot = new Robot();
 130             Thread.sleep(delay * 10);
 131         } catch (Exception e) {
 132             e.printStackTrace();
 133             throw new RuntimeException("Robot creation exception.");
 134         }
 135 
 136         robot.mouseMove((int) components[0].getLocationOnScreen().x + components[0].getSize().width / 2,
 137                         (int) components[0].getLocationOnScreen().y + components[0].getSize().height / 2);
 138         robot.delay(delay);
 139         robot.mousePress(InputEvent.BUTTON1_MASK);
 140         robot.delay(delay);
 141         robot.mouseRelease(InputEvent.BUTTON1_MASK);
 142         robot.delay(delay);
 143 
 144         resetValues();
 145         try {
 146             EventQueue.invokeAndWait(new Runnable() {
 147                 public void run() {
 148                     frame.setSize(new Dimension(frame.getSize().width + 10, frame.getSize().height + 10));
 149                     frame.invalidate();
 150                     frame.validate();
 151                 }
 152             });
 153         } catch (Exception e) {


 577 to read and understand someone else's test.
 578  ****************************************************/
 579 /**
 580 This is part of the standard test machinery.
 581 It creates a dialog (with the instructions), and is the interface
 582 for sending text messages to the user.
 583 To print the instructions, send an array of strings to Sysout.createDialog
 584 WithInstructions method.  Put one line of instructions per array entry.
 585 To display a message for the tester to see, simply call Sysout.println
 586 with the string to be displayed.
 587 This mimics System.out.println but works within the test harness as well
 588 as standalone.
 589  */
 590 class Sysout {
 591 
 592     private static TestDialog dialog;
 593 
 594     public static void createDialogWithInstructions(String[] instructions) {
 595         dialog = new TestDialog(new Frame(), "Instructions");
 596         dialog.printInstructions(instructions);
 597         //dialog.setVisible(true);
 598         println("Any messages for the tester will display here.");
 599     }
 600 
 601     public static void createDialog() {
 602         dialog = new TestDialog(new Frame(), "Instructions");
 603         String[] defInstr = {"Instructions will appear here. ", ""};
 604         dialog.printInstructions(defInstr);
 605         //dialog.setVisible(true);
 606         println("Any messages for the tester will display here.");
 607     }
 608 
 609     public static void printInstructions(String[] instructions) {
 610         dialog.printInstructions(instructions);
 611     }
 612 
 613     public static void println(String messageIn) {
 614         dialog.displayMessage(messageIn);
 615         System.out.println(messageIn);
 616     }
 617 }// Sysout  class
 618 
 619 /**
 620 This is part of the standard test machinery.  It provides a place for the
 621 test instructions to be displayed, and a place for interactive messages
 622 to the user to be displayed.
 623 To have the test instructions displayed, see Sysout.
 624 To have a message to the user be displayed, see Sysout.
 625 Do not call anything in this dialog directly.
 626  */
 627 class TestDialog extends Dialog {
 628 
 629     TextArea instructionsText;
 630     TextArea messageText;
 631     int maxStringLength = 80;
 632 
 633     //DO NOT call this directly, go through Sysout
 634     public TestDialog(Frame frame, String name) {
 635         super(frame, name);
 636         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 637         instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
 638         add("North", instructionsText);
 639 
 640         messageText = new TextArea("", 5, maxStringLength, scrollBoth);
 641         add("Center", messageText);
 642 
 643         pack();
 644 
 645         //setVisible(true);
 646     }// TestDialog()
 647 
 648     //DO NOT call this directly, go through Sysout
 649     public void printInstructions(String[] instructions) {
 650         //Clear out any current instructions
 651         instructionsText.setText("");
 652 
 653         //Go down array of instruction strings
 654 
 655         String printStr, remainingStr;
 656         for (int i = 0; i < instructions.length; i++) {
 657             //chop up each into pieces maxSringLength long
 658             remainingStr = instructions[i];
 659             while (remainingStr.length() > 0) {
 660                 //if longer than max then chop off first max chars to print
 661                 if (remainingStr.length() >= maxStringLength) {
 662                     //Try to chop on a word boundary
 663                     int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
 664 
 665                     if (posOfSpace <= 0) {