modules/graphics/src/test/java/test/javafx/stage/PopupTest.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.stage;
  27 

  28 import com.sun.javafx.stage.WindowHelper;
  29 import test.com.sun.javafx.pgstub.StubPopupStage;
  30 import test.com.sun.javafx.pgstub.StubStage;
  31 import test.com.sun.javafx.pgstub.StubToolkit;
  32 import test.com.sun.javafx.pgstub.StubToolkit.ScreenConfiguration;
  33 import test.com.sun.javafx.test.MouseEventGenerator;
  34 import com.sun.javafx.tk.Toolkit;
  35 import javafx.concurrent.Task;
  36 import javafx.event.Event;
  37 import javafx.event.EventHandler;
  38 import javafx.geometry.BoundingBox;
  39 import javafx.geometry.Bounds;
  40 import javafx.geometry.Rectangle2D;
  41 import javafx.scene.Cursor;
  42 import javafx.scene.Group;
  43 import javafx.scene.Parent;
  44 import javafx.scene.Scene;
  45 import javafx.scene.input.KeyCode;
  46 import javafx.scene.input.KeyEvent;
  47 import javafx.scene.input.MouseEvent;


 366         // doAutoHide on popup should hide just itself or its parent popup as well.
 367         // PopupEventRedirector should probably take care of it.
 368         //assertFalse(p1.isVisible());
 369         assertFalse(p2.isShowing());
 370         assertTrue(p0.isShowing());
 371     }
 372 
 373     @Test
 374     public void testOnAutohide() {
 375         Popup p1 = new Popup();
 376         p1.setAutoHide(true);
 377         p1.show(stage);
 378         p1.setOnAutoHide(e -> {
 379             done = true;
 380         });
 381         Rectangle rect = new Rectangle(20, 20, 50, 50);
 382         p1.getContent().add(rect);
 383         assertFalse(done);
 384 
 385         final MouseEventGenerator generator = new MouseEventGenerator();
 386         scene.impl_processMouseEvent(
 387                 generator.generateMouseEvent(
 388                         MouseEvent.MOUSE_PRESSED, 0, 0));
 389 
 390         // test whether runnable ran
 391         assertTrue(done);
 392     }
 393 
 394 
 395     @Ignore ("Not sure how this ever worked, or what the point is")
 396     @Test
 397     public void testPeerListener() {
 398         Popup p = new Popup();
 399         p.setAutoHide(true);
 400         p.show(stage);
 401 
 402         StubPopupStage peer = (StubPopupStage) WindowHelper.getPeer(p);
 403         p.sizeToScene();
 404 
 405         double width = p.getWidth();
 406         double height = p.getHeight();


   1 /*
   2  * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.stage;
  27 
  28 import com.sun.javafx.scene.SceneHelper;
  29 import com.sun.javafx.stage.WindowHelper;
  30 import test.com.sun.javafx.pgstub.StubPopupStage;
  31 import test.com.sun.javafx.pgstub.StubStage;
  32 import test.com.sun.javafx.pgstub.StubToolkit;
  33 import test.com.sun.javafx.pgstub.StubToolkit.ScreenConfiguration;
  34 import test.com.sun.javafx.test.MouseEventGenerator;
  35 import com.sun.javafx.tk.Toolkit;
  36 import javafx.concurrent.Task;
  37 import javafx.event.Event;
  38 import javafx.event.EventHandler;
  39 import javafx.geometry.BoundingBox;
  40 import javafx.geometry.Bounds;
  41 import javafx.geometry.Rectangle2D;
  42 import javafx.scene.Cursor;
  43 import javafx.scene.Group;
  44 import javafx.scene.Parent;
  45 import javafx.scene.Scene;
  46 import javafx.scene.input.KeyCode;
  47 import javafx.scene.input.KeyEvent;
  48 import javafx.scene.input.MouseEvent;


 367         // doAutoHide on popup should hide just itself or its parent popup as well.
 368         // PopupEventRedirector should probably take care of it.
 369         //assertFalse(p1.isVisible());
 370         assertFalse(p2.isShowing());
 371         assertTrue(p0.isShowing());
 372     }
 373 
 374     @Test
 375     public void testOnAutohide() {
 376         Popup p1 = new Popup();
 377         p1.setAutoHide(true);
 378         p1.show(stage);
 379         p1.setOnAutoHide(e -> {
 380             done = true;
 381         });
 382         Rectangle rect = new Rectangle(20, 20, 50, 50);
 383         p1.getContent().add(rect);
 384         assertFalse(done);
 385 
 386         final MouseEventGenerator generator = new MouseEventGenerator();
 387         SceneHelper.processMouseEvent(scene,
 388                 generator.generateMouseEvent(
 389                         MouseEvent.MOUSE_PRESSED, 0, 0));
 390 
 391         // test whether runnable ran
 392         assertTrue(done);
 393     }
 394 
 395 
 396     @Ignore ("Not sure how this ever worked, or what the point is")
 397     @Test
 398     public void testPeerListener() {
 399         Popup p = new Popup();
 400         p.setAutoHide(true);
 401         p.show(stage);
 402 
 403         StubPopupStage peer = (StubPopupStage) WindowHelper.getPeer(p);
 404         p.sizeToScene();
 405 
 406         double width = p.getWidth();
 407         double height = p.getHeight();