コード例 #1
0
    @Override
    public void paint(Graphics g) {
      if ((target instanceof Frame && !(target instanceof JFrame))
          || (target instanceof Dialog && !(target instanceof JDialog))) {
        SwingBaseWindow<?, ?> sf = SwingBaseWindow.this;
        Window f = target;

        Color bg = f.getBackground();
        if (bg == null) bg = UIManager.getColor("window");
        if (bg == null) bg = UIManager.getColor("control");
        if (bg == null) bg = Color.GRAY;

        g.setColor(bg);
        g.fillRect(0, 0, getWidth(), getHeight());

        Point f_loc = sf.getLocationOnScreen();
        Point p_loc = this.getLocationOnScreen();

        int dx = p_loc.x - f_loc.x;
        int dy = p_loc.y - f_loc.y;

        for (Component c : f.getComponents()) {
          Graphics cg = g.create(c.getX() - dx, c.getY() - dy, c.getWidth(), c.getHeight());
          c.paintAll(cg);
          cg.dispose();
        }
      }
    }
コード例 #2
0
 private static void repaintMnemonics(@NotNull Component focusOwner, boolean pressed) {
   if (pressed != myAltPressed) return;
   Window window = SwingUtilities.windowForComponent(focusOwner);
   if (window != null) {
     for (Component component : window.getComponents()) {
       if (component instanceof JComponent) {
         for (JComponent c :
             UIUtil.findComponentsOfType((JComponent) component, JComponent.class)) {
           if ((c instanceof JLabel && ((JLabel) c).getDisplayedMnemonicIndex() != -1)
               || (c instanceof AbstractButton
                   && ((AbstractButton) c).getDisplayedMnemonicIndex() != -1)) {
             c.repaint();
           }
         }
       }
     }
   }
 }
コード例 #3
0
  public static void doScreenshots(File shotdir) throws Exception {
    shotdir.mkdirs();
    String prefix = "jgridstart-screenshot-";
    // setup temporary environment
    logger.info("Setting up jGridstart interactive screenshot and testing environment");
    File tmphome = FileUtils.createTempDir("jgridstart-home");
    Window mainwnd = null;
    try {
      System.setProperty("jgridstart.ca.provider", "LocalCA");
      System.setProperty("jgridstart.ca.local.hold", "true");
      System.setProperty("user.home", tmphome.getCanonicalPath());
      // create standard gui
      nl.nikhef.jgridstart.gui.Main.main(new String[] {});
      LogHelper.setupLogging(true);
      // move mouse here since closing window may give up focus later
      Thread.sleep(2000);
      guiSleep();
      mainwnd = AWT.getActiveWindow();
      assertNotNull(mainwnd);
      tester.mouseMove(mainwnd.getComponents()[0]);
      assertWindowname("jgridstart-main-window");

      /*
       * Request new
       */
      logger.info("Interactive testing scenario: Request New");
      // start screen
      saveScreenshot(new File(shotdir, prefix + "newrequest01.png"));
      // new request wizard
      guiSleep();
      tester.key(new Integer('N'), InputEvent.CTRL_MASK);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest02.png"));
      // enter details
      guiSleep();
      assertWindowname("jgridstart-requestwizard-0");
      focusByName("givenname");
      keyString("John\t");
      keyString("Doe\t");
      keyString("[email protected]\t");
      keyString("N\t");
      keyString(password + "\t");
      keyString(password + "\t");
      // wait for submission
      tester.key(new Integer('N'), InputEvent.ALT_MASK);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest03.png"));
      assertWindowname("jgridstart-requestwizard-1");
      waitEnabled(JButton.class, "Next");
      // verification form
      System.setProperty("wizard.show.help1", "true"); // simulate help btn1 pressed
      tester.key(new Integer('N'), InputEvent.ALT_MASK);
      guiSleep();
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest04.png"));
      assertWindowname("jgridstart-requestwizard-2");
      // form display
      JButton btn =
          (JButton)
              new BasicFinder()
                  .find(
                      new Matcher() {
                        public boolean matches(Component c) {
                          return c instanceof JButton
                              && ((JButton) c).getText().startsWith("display form");
                        }
                      });
      btn.doClick();
      waitEnabled(JButton.class, "Close");
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest05.png"));
      assertWindowname("jgridstart-verification-form");
      tester.key(new Integer('C'), InputEvent.ALT_MASK);
      // close wizard
      guiSleep();
      assertWindowname("jgridstart-requestwizard-2");
      tester.key(new Integer('C'), InputEvent.ALT_MASK);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest06.png"));
      assertWindowname("jgridstart-main-window");
      // enable certificate in LocalCA and refresh pane
      System.setProperty("jgridstart.ca.local.hold", "false");
      tester.key(KeyEvent.VK_F5);
      Thread.sleep(1000);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest07.png"));
      assertWindowname("jgridstart-main-window");
      // show request wizard again
      tester.key(new Integer('A'), InputEvent.ALT_MASK);
      tester.key('R');
      guiSleep();
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest08.png"));
      assertWindowname("jgridstart-requestwizard-2");
      // install step
      tester.key(new Integer('N'), InputEvent.ALT_MASK);
      Thread.sleep(1000);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest09.png"));
      assertWindowname("jgridstart-requestwizard-3");
      // show final screen
      tester.key(new Integer('N'), InputEvent.ALT_MASK);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest10.png"));
      assertWindowname("jgridstart-requestwizard-4");
      // exit wizard
      tester.key(new Integer('C'), InputEvent.ALT_MASK);
      // save final screenshot
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "newrequest11.png"));
      assertWindowname("jgridstart-main-window");
      guiSleep();

      /*
       * Renewal
       */
      logger.info("Interactive testing scenario: Renewal");
      System.setProperty("jgridstart.ca.local.hold", "true");
      // forget password so we certainly get the password dialog
      PasswordCache.getInstance().clear();
      // start screen
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew01.png"));
      assertWindowname("jgridstart-main-window");
      // personal details
      tester.key(new Integer('A'), InputEvent.ALT_MASK);
      tester.key('W');
      Thread.sleep(500);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew02.png"));
      assertWindowname("jgridstart-requestwizard-0");
      focusByName("email");
      keyString("\t");
      keyString(password + "\t");
      keyString(password + "\t");
      keyString(password + "\t");
      // wait for submission screen
      tester.key(new Integer('N'), InputEvent.ALT_MASK);
      // renew03.png used to be a password dialog, which was removed
      // submit page
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew04.png"));
      assertWindowname("jgridstart-requestwizard-1");
      waitEnabled(JButton.class, "Next");
      // wait for approval page
      tester.key(new Integer('N'), InputEvent.ALT_MASK);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew05.png"));
      assertWindowname("jgridstart-requestwizard-2");
      // close wizard
      guiSleep();
      tester.key(new Integer('C'), InputEvent.ALT_MASK);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew06.png"));
      assertWindowname("jgridstart-main-window");
      // enable certificate in LocalCA and refresh pane
      System.setProperty("jgridstart.ca.local.hold", "false");
      tester.key(KeyEvent.VK_F5);
      Thread.sleep(1000);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew07.png"));
      assertWindowname("jgridstart-main-window");
      // show request wizard again
      tester.key(new Integer('A'), InputEvent.ALT_MASK);
      tester.key('R');
      waitEnabled(JButton.class, "Next");
      Thread.sleep(500);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew08.png"));
      assertWindowname("jgridstart-requestwizard-2");
      // install step
      tester.key(new Integer('N'), InputEvent.ALT_MASK);
      Thread.sleep(1000);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew09.png"));
      assertWindowname("jgridstart-requestwizard-3");
      // exit wizard
      tester.key(new Integer('C'), InputEvent.ALT_MASK);
      // save final screenshot
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "renew10.png"));
      assertWindowname("jgridstart-main-window");
      guiSleep();

      /*
       * Import/export
       */
      logger.info("Interactive testing scenario: Import/Export");
      // forget password so we certainly get the password dialog
      PasswordCache.getInstance().clear();
      // starting screenshot (multiple certificates)
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "importexport01.png"));
      assertWindowname("jgridstart-main-window");
      // export dialog
      tester.key(new Integer('E'), InputEvent.CTRL_MASK);
      waitEnabled(JButton.class, "Export");
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "importexport02.png"));
      assertWindowname("jgridstart-export-file-dialog");
      // enter name and do export
      tester.keyString("jgridstart_test_certificate.p12\n");
      Thread.sleep(2000);
      saveScreenshot(new File(shotdir, prefix + "importexport03.png"));
      assertWindowname("jgridstart-password-entry-decrypt");
      tester.keyString(password + "\n");
      guiSleep();
      assertWindowname("jgridstart-main-window");

      // forget password so we certainly get the password dialog
      PasswordCache.getInstance().clear();

      // import dialog
      tester.key(new Integer('I'), InputEvent.CTRL_MASK);
      waitEnabled(JButton.class, "Import");
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "importexport04.png"));
      assertWindowname("jgridstart-import-file-dialog");
      guiSleep();
      // enter name and do import
      tester.keyString("jgridstart_test_certificate.p12\n");
      Thread.sleep(1000);
      saveScreenshot(new File(shotdir, prefix + "importexport05.png"));
      assertWindowname("jgridstart-password-entry-decrypt");
      keyString(password + "\n");
      guiSleep();

      /*
       * Certificate details
       */
      logger.info("Interactive testing scenario: Certificate details");
      // certificate details view
      mainwnd.setSize(750, 480);
      System.setProperty("view.showdetails", "true");
      URLLauncherCertificate.performAction("viewlist(false)", mainwnd);
      tester.key(KeyEvent.VK_F5);
      Thread.sleep(500);
      guiSleep();
      saveScreenshot(new File(shotdir, prefix + "viewdetails01.png"));
      assertWindowname("jgridstart-main-window");

      /*
       * Exit!
       */
      logger.info("Interactive testing finished");
      /* Quit does a {@link System.exit}, which JUnit doesn't like. The
       * error it gives is something like:
       *   [junit] Test <testclass> FAILED (crashed)
       * So we leave it to the calling function to dispose of the window.
       */
      // tester.key(new Integer('Q'), InputEvent.CTRL_MASK);

    } finally {
      guiSleep();
      Thread.sleep(500); // for screenshot to complete ...
      FileUtils.recursiveDelete(tmphome);
    }
    // exit!
    return;
  }