< prev index next >

test/jdk/java/awt/regtesthelpers/PassFailJFrame.java

Print this page

  30 import java.awt.Image;
  31 import java.awt.Insets;
  32 import java.awt.Point;
  33 import java.awt.Rectangle;
  34 import java.awt.Robot;
  35 import java.awt.Toolkit;
  36 import java.awt.Window;
  37 import java.awt.event.ActionEvent;
  38 import java.awt.event.ActionListener;
  39 import java.awt.event.WindowAdapter;
  40 import java.awt.event.WindowEvent;
  41 import java.awt.event.WindowListener;
  42 import java.awt.image.RenderedImage;
  43 import java.io.File;
  44 import java.io.IOException;
  45 import java.lang.reflect.InvocationTargetException;
  46 import java.util.ArrayList;
  47 import java.util.Arrays;
  48 import java.util.Collection;
  49 import java.util.List;

  50 import java.util.Objects;
  51 import java.util.concurrent.CountDownLatch;
  52 import java.util.concurrent.TimeUnit;
  53 import java.util.concurrent.atomic.AtomicInteger;
  54 
  55 import javax.imageio.ImageIO;
  56 import javax.swing.JButton;
  57 import javax.swing.JComboBox;
  58 import javax.swing.JComponent;
  59 import javax.swing.JDialog;
  60 import javax.swing.JEditorPane;
  61 import javax.swing.JFrame;
  62 import javax.swing.JLabel;
  63 import javax.swing.JOptionPane;
  64 import javax.swing.JPanel;
  65 import javax.swing.JScrollPane;
  66 import javax.swing.JTextArea;
  67 import javax.swing.Timer;
  68 import javax.swing.text.JTextComponent;
  69 import javax.swing.text.html.HTMLEditorKit;

 525         @Override
 526         public void actionPerformed(ActionEvent e) {
 527             long leftTime = endTime - System.currentTimeMillis();
 528             if (leftTime < 0) {
 529                 timer.stop();
 530                 setFailureReason(FAILURE_REASON
 531                                  + "Timeout - User did not perform testing.");
 532                 latch.countDown();
 533             }
 534             updateTime(leftTime);
 535         }
 536 
 537         private void updateTime(final long leftTime) {
 538             if (leftTime < 0) {
 539                 label.setText("Test timeout: 00:00:00");
 540                 return;
 541             }
 542             long hours = leftTime / 3_600_000;
 543             long minutes = (leftTime - hours * 3_600_000) / 60_000;
 544             long seconds = (leftTime - hours * 3_600_000 - minutes * 60_000) / 1_000;
 545             label.setText(String.format("Test timeout: %02d:%02d:%02d",

 546                                         hours, minutes, seconds));
 547         }
 548 
 549         public void stop() {
 550             timer.stop();
 551         }
 552     }
 553 
 554 
 555     private static final class WindowClosingHandler extends WindowAdapter {
 556         @Override
 557         public void windowClosing(WindowEvent e) {
 558             setFailureReason(FAILURE_REASON
 559                              + "User closed a window");
 560             latch.countDown();
 561         }
 562     }
 563 
 564     private static final WindowListener windowClosingHandler =
 565             new WindowClosingHandler();

  30 import java.awt.Image;
  31 import java.awt.Insets;
  32 import java.awt.Point;
  33 import java.awt.Rectangle;
  34 import java.awt.Robot;
  35 import java.awt.Toolkit;
  36 import java.awt.Window;
  37 import java.awt.event.ActionEvent;
  38 import java.awt.event.ActionListener;
  39 import java.awt.event.WindowAdapter;
  40 import java.awt.event.WindowEvent;
  41 import java.awt.event.WindowListener;
  42 import java.awt.image.RenderedImage;
  43 import java.io.File;
  44 import java.io.IOException;
  45 import java.lang.reflect.InvocationTargetException;
  46 import java.util.ArrayList;
  47 import java.util.Arrays;
  48 import java.util.Collection;
  49 import java.util.List;
  50 import java.util.Locale;
  51 import java.util.Objects;
  52 import java.util.concurrent.CountDownLatch;
  53 import java.util.concurrent.TimeUnit;
  54 import java.util.concurrent.atomic.AtomicInteger;
  55 
  56 import javax.imageio.ImageIO;
  57 import javax.swing.JButton;
  58 import javax.swing.JComboBox;
  59 import javax.swing.JComponent;
  60 import javax.swing.JDialog;
  61 import javax.swing.JEditorPane;
  62 import javax.swing.JFrame;
  63 import javax.swing.JLabel;
  64 import javax.swing.JOptionPane;
  65 import javax.swing.JPanel;
  66 import javax.swing.JScrollPane;
  67 import javax.swing.JTextArea;
  68 import javax.swing.Timer;
  69 import javax.swing.text.JTextComponent;
  70 import javax.swing.text.html.HTMLEditorKit;

 526         @Override
 527         public void actionPerformed(ActionEvent e) {
 528             long leftTime = endTime - System.currentTimeMillis();
 529             if (leftTime < 0) {
 530                 timer.stop();
 531                 setFailureReason(FAILURE_REASON
 532                                  + "Timeout - User did not perform testing.");
 533                 latch.countDown();
 534             }
 535             updateTime(leftTime);
 536         }
 537 
 538         private void updateTime(final long leftTime) {
 539             if (leftTime < 0) {
 540                 label.setText("Test timeout: 00:00:00");
 541                 return;
 542             }
 543             long hours = leftTime / 3_600_000;
 544             long minutes = (leftTime - hours * 3_600_000) / 60_000;
 545             long seconds = (leftTime - hours * 3_600_000 - minutes * 60_000) / 1_000;
 546             label.setText(String.format(Locale.ENGLISH,
 547                                         "Test timeout: %02d:%02d:%02d",
 548                                         hours, minutes, seconds));
 549         }
 550 
 551         public void stop() {
 552             timer.stop();
 553         }
 554     }
 555 
 556 
 557     private static final class WindowClosingHandler extends WindowAdapter {
 558         @Override
 559         public void windowClosing(WindowEvent e) {
 560             setFailureReason(FAILURE_REASON
 561                              + "User closed a window");
 562             latch.countDown();
 563         }
 564     }
 565 
 566     private static final WindowListener windowClosingHandler =
 567             new WindowClosingHandler();
< prev index next >