コード例 #1
0
 public void testContextIsJFrameWhenJFrameIsShown() {
   JFrame frame = new JFrame();
   JButton comp = new JButton();
   frame.getContentPane().add(comp);
   windowContext.setActiveWindow(comp);
   assertSame(frame, windowContext.activeWindow());
 }
コード例 #2
0
 public void testContextIsJAppletWhenJAppletIsShown() {
   JApplet applet = new JApplet();
   JButton button = new JButton();
   applet.getContentPane().add(button);
   windowContext.setActiveWindow(applet);
   assertSame(applet, windowContext.activeWindow());
 }
コード例 #3
0
 public void testContextIsJDialogWhenJDialogIsShown() {
   JDialog dialog = new JDialog();
   JButton comp = new JButton();
   dialog.getContentPane().add(comp);
   windowContext.setActiveWindow(comp);
   assertSame(dialog, windowContext.activeWindow());
 }
コード例 #4
0
 public void testFiresDialogOpenedEventWhenDialogIsShown() {
   Mock mockWindowContextListener = mock(WindowContextListener.class);
   windowContext.addWindowContextListener(
       (WindowContextListener) mockWindowContextListener.proxy());
   mockWindowContextListener.expects(once()).method("dialogShown");
   windowContext.setActiveWindow(new JDialog((Frame) null, "test"));
 }
コード例 #5
0
 public void testListenerIsNotNotifiedWhenRemoved() {
   Mock mockWindowContextListener = mock(WindowContextListener.class);
   WindowContextListener listener = (WindowContextListener) mockWindowContextListener.proxy();
   windowContext.addWindowContextListener(listener);
   windowContext.removeWindowContextListener(listener);
   mockWindowContextListener.expects(never()).method("dialogShown");
   windowContext.setActiveWindow(new JDialog((Frame) null, "test"));
 }
コード例 #6
0
 public void testFindsTopLevelWindowIfActiveWindowIsInternalFrame() {
   JFrame frame = new JFrame("testTopLevelWindow");
   JDesktopPane pane = new JDesktopPane();
   JInternalFrame internalFrame = new JInternalFrame("Test");
   pane.add(internalFrame);
   frame.setContentPane(pane);
   windowContext.setActiveWindow(internalFrame);
   assertSame(frame, windowContext.activeTopLevelWindow());
   frame.dispose();
 }
コード例 #7
0
 public void testContextIsJAppletWhenACompentInItHasFocus() {
   Frame frame = new Frame();
   JApplet applet = new JApplet();
   JButton button = new JButton();
   frame.add(applet);
   applet.getContentPane().add(button);
   setFocusManager(button);
   windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, button));
   assertSame(applet, windowContext.activeWindow());
 }
コード例 #8
0
 public void testWaitForDialogWithActiveWindowAsTargetDialog() throws InterruptedException {
   JFrame frame = new JFrame();
   JDialog testDialog = new JDialog(frame, "testDialog");
   setFocusManager(testDialog);
   windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, testDialog));
   windowContext.waitForDialogOpening("testDialog", 10);
   assertSame(testDialog, windowContext.activeWindow());
   testDialog.dispose();
   frame.dispose();
 }
コード例 #9
0
 public void testContextIsJFrameWhenInternalFrameIsShown() {
   JFrame frame = new JFrame();
   JInternalFrame internalFrame = new JInternalFrame();
   JTextField textField = new JTextField();
   setFocusManager(textField);
   internalFrame.getContentPane().add(textField);
   frame.getContentPane().add(internalFrame);
   windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, textField));
   assertSame(frame, windowContext.activeWindow());
   assertSame(frame, windowContext.activeTopLevelWindow());
 }
コード例 #10
0
 public void testClosesOpenDialogs() {
   final JDialog dialog = new JDialog();
   windowContext.setActiveWindow(dialog);
   new Thread(
           new Runnable() {
             public void run() {
               windowContext.propertyChange(
                   new PropertyChangeEvent(this, "focusOwner", null, dialog));
             }
           })
       .start();
   windowContext.closeAllDialogs();
 }
コード例 #11
0
 public void testWaitForActiveDialogWhenDialogIsNotReady() throws InterruptedException {
   final JDialog testDialog = new JDialog(new JFrame(), "testDialog");
   setFocusManager(testDialog);
   new Thread(
           new Runnable() {
             public void run() {
               windowContext.propertyChange(
                   new PropertyChangeEvent(this, "focusOwner", null, testDialog));
             }
           })
       .start();
   windowContext.waitForDialogOpening("testDialog", 10);
   assertEquals(testDialog, windowContext.activeWindow());
   testDialog.dispose();
 }
コード例 #12
0
 public void testWaitsForDialogToClose() {
   final JDialog dialog = new JDialog((Frame) null, "title");
   setFocusManager(dialog);
   windowContext.setActiveWindow(dialog);
   final JFrame frame = new JFrame("newFocusOwner");
   new Thread(
           new Runnable() {
             public void run() {
               windowContext.setActiveWindow(frame);
             }
           })
       .start();
   windowContext.waitForDialogClosing("title", 1000);
   assertSame(frame, windowContext.activeWindow());
 }
コード例 #13
0
  public void testWaitsTillProgressBarCompletes() {
    final JFrame frame = new JFrame();

    final JProgressBar progressBar1 = new JProgressBar();
    final JProgressBar progressBar2 = new JProgressBar(0, 10);
    createProgressBarsInFrame(frame, progressBar1, progressBar2);
    setFocusManager(frame);

    windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, progressBar2));

    long before = System.currentTimeMillis();

    Thread thread1 = spawnFirstThreadToInactivateFirstProgressBar(progressBar1);
    Thread thread2 = spawnSecondThreadToInactivateSecondProgressBar(progressBar2);

    windowContext.waitForProgressBar();
    long after = System.currentTimeMillis();

    assertTrue((after - before) > 500);
    ThreadUtil.sleep(100);
    assertFalse(thread1.isAlive());
    assertFalse(thread2.isAlive());
    frame.dispose();
  }
コード例 #14
0
 public void testSetsActiveWindowToNullIfThereIsNoRootPaneContainer() {
   JButton button = new JButton();
   KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKeyboardFocusManager(button));
   windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, button));
   assertNull(windowContext.activeWindow());
 }
コード例 #15
0
 protected void tearDown() throws Exception {
   super.tearDown();
   windowContext.close();
   KeyboardFocusManager.setCurrentKeyboardFocusManager(defaultKeyboardFocusManager);
 }
コード例 #16
0
 public void testSetsActiveWindowWhenFocusChanges() {
   JFrame frame = new JFrame();
   KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKeyboardFocusManager(frame));
   windowContext.propertyChange(new PropertyChangeEvent(this, "focusOwner", null, frame));
   assertSame(frame, windowContext.activeWindow());
 }
コード例 #17
0
 public void testReturnsCurrentFocusOwner() {
   JLabel focusOwner = new JLabel("test");
   setFocusManager(focusOwner);
   assertSame(focusOwner, windowContext.focusOwner());
 }