< prev index next >

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

Print this page




   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;
  49 import javafx.scene.shape.Rectangle;
  50 import junit.framework.Assert;
  51 import org.junit.After;
  52 import org.junit.Before;
  53 import org.junit.Ignore;
  54 import org.junit.Test;
  55 
  56 import java.util.concurrent.ExecutionException;
  57 import java.util.concurrent.atomic.AtomicBoolean;

  58 import javafx.scene.ParentShim;
  59 import javafx.stage.Popup;
  60 import javafx.stage.PopupWindow;
  61 import javafx.stage.Screen;
  62 import javafx.stage.Stage;
  63 import javafx.stage.Window;
  64 
  65 import static org.junit.Assert.*;

  66 
  67 public class PopupTest {
  68 
  69     private StubToolkit toolkit;
  70     private Stage stage;
  71     private Scene scene;
  72     private boolean done = false;
  73 
  74     @Before
  75     public void setUp() {
  76         stage = new Stage();
  77         scene = new Scene(new Group(), 500, 500);
  78         stage.setScene(scene);
  79         stage.show();
  80         done = false;
  81         toolkit = (StubToolkit) Toolkit.getToolkit();
  82     }
  83 
  84     @After
  85     public void tearDown() {


 115     public void testShowNoAutofix() {
 116         Popup p1 = new Popup();
 117         p1.setAutoFix(false);
 118         p1.show(stage);
 119         assertTrue(p1.isShowing());
 120     }
 121 
 122     @Test
 123     public void testShowLocation() {
 124         Popup p1 = new Popup();
 125         p1.show(stage, 10, 20);
 126         assertTrue(p1.isShowing());
 127         assertEquals(10, p1.getX(), 1e-100);
 128         assertEquals(20, p1.getY(), 1e-100);
 129         pulse();
 130         StubPopupStage peer = (StubPopupStage) WindowHelper.getPeer(p1);
 131         assertEquals(10, peer.x, 1e-100);
 132         assertEquals(20, peer.y, 1e-100);
 133     }
 134 
 135     private static final class PopupRoot extends Parent {










 136         private final Rectangle geomBoundsRect;
 137 
 138         private double layoutBoundsX;
 139         private double layoutBoundsY;
 140         private double layoutBoundsWidth;
 141         private double layoutBoundsHeight;
 142 




 143         public PopupRoot() {
 144             geomBoundsRect = new Rectangle(0, 0, 100, 100);
 145             layoutBoundsWidth = 100;
 146             layoutBoundsHeight = 100;
 147 
 148             ParentShim.getChildren(this).add(geomBoundsRect);
 149         }
 150 
 151         public void setGeomBounds(final double x, final double y,
 152                                   final double width,
 153                                   final double height) {
 154             geomBoundsRect.setX(x);
 155             geomBoundsRect.setY(y);
 156             geomBoundsRect.setWidth(width);
 157             geomBoundsRect.setHeight(height);
 158         }
 159 
 160         public void setLayoutBounds(final double x, final double y,
 161                                     final double width,
 162                                     final double height) {
 163             layoutBoundsX = x;
 164             layoutBoundsY = y;
 165             layoutBoundsWidth = width;
 166             layoutBoundsHeight = height;
 167 
 168             impl_layoutBoundsChanged();
 169         }
 170 
 171         @Override
 172         protected Bounds impl_computeLayoutBounds() {
 173             return new BoundingBox(layoutBoundsX, layoutBoundsY,
 174                                    layoutBoundsWidth, layoutBoundsHeight);
 175         }
 176     }
 177 
 178     @Test
 179     public void testAnchorPositioning() {
 180         final Popup popup = new Popup();
 181         final PopupRoot root = new PopupRoot();
 182 
 183         root.setGeomBounds(-10, 20, 120, 100);
 184         root.setLayoutBounds(0, 0, 100, 140);
 185 
 186         popup.getScene().setRoot(root);
 187 
 188         popup.setAnchorLocation(PopupWindow.AnchorLocation.WINDOW_BOTTOM_RIGHT);
 189         popup.show(stage, 400, 400);
 190 
 191         final StubPopupStage peer = (StubPopupStage) WindowHelper.getPeer(popup);
 192 




   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.NodeHelper;
  29 import com.sun.javafx.scene.SceneHelper;
  30 import com.sun.javafx.stage.WindowHelper;
  31 import test.com.sun.javafx.pgstub.StubPopupStage;
  32 import test.com.sun.javafx.pgstub.StubStage;
  33 import test.com.sun.javafx.pgstub.StubToolkit;
  34 import test.com.sun.javafx.pgstub.StubToolkit.ScreenConfiguration;
  35 import test.com.sun.javafx.test.MouseEventGenerator;
  36 import com.sun.javafx.tk.Toolkit;
  37 import javafx.concurrent.Task;
  38 import javafx.event.Event;
  39 import javafx.event.EventHandler;
  40 import javafx.geometry.BoundingBox;
  41 import javafx.geometry.Bounds;
  42 import javafx.geometry.Rectangle2D;
  43 import javafx.scene.Cursor;
  44 import javafx.scene.Group;
  45 import javafx.scene.Parent;
  46 import javafx.scene.Scene;
  47 import javafx.scene.input.KeyCode;
  48 import javafx.scene.input.KeyEvent;
  49 import javafx.scene.input.MouseEvent;
  50 import javafx.scene.shape.Rectangle;
  51 import junit.framework.Assert;
  52 import org.junit.After;
  53 import org.junit.Before;
  54 import org.junit.Ignore;
  55 import org.junit.Test;
  56 
  57 import java.util.concurrent.ExecutionException;
  58 import java.util.concurrent.atomic.AtomicBoolean;
  59 import javafx.scene.Node;
  60 import javafx.scene.ParentShim;
  61 import javafx.stage.Popup;
  62 import javafx.stage.PopupWindow;
  63 import javafx.stage.Screen;
  64 import javafx.stage.Stage;
  65 import javafx.stage.Window;
  66 
  67 import static org.junit.Assert.*;
  68 import test.com.sun.javafx.stage.PopupRootHelper;
  69 
  70 public class PopupTest {
  71 
  72     private StubToolkit toolkit;
  73     private Stage stage;
  74     private Scene scene;
  75     private boolean done = false;
  76 
  77     @Before
  78     public void setUp() {
  79         stage = new Stage();
  80         scene = new Scene(new Group(), 500, 500);
  81         stage.setScene(scene);
  82         stage.show();
  83         done = false;
  84         toolkit = (StubToolkit) Toolkit.getToolkit();
  85     }
  86 
  87     @After
  88     public void tearDown() {


 118     public void testShowNoAutofix() {
 119         Popup p1 = new Popup();
 120         p1.setAutoFix(false);
 121         p1.show(stage);
 122         assertTrue(p1.isShowing());
 123     }
 124 
 125     @Test
 126     public void testShowLocation() {
 127         Popup p1 = new Popup();
 128         p1.show(stage, 10, 20);
 129         assertTrue(p1.isShowing());
 130         assertEquals(10, p1.getX(), 1e-100);
 131         assertEquals(20, p1.getY(), 1e-100);
 132         pulse();
 133         StubPopupStage peer = (StubPopupStage) WindowHelper.getPeer(p1);
 134         assertEquals(10, peer.x, 1e-100);
 135         assertEquals(20, peer.y, 1e-100);
 136     }
 137 
 138     public static final class PopupRoot extends Parent {
 139         static {
 140             PopupRootHelper.setPopupRootAccessor(
 141                     new PopupRootHelper.PopupRootAccessor() {
 142                 @Override
 143                 public Bounds doComputeLayoutBounds(Node node) {
 144                     return ((PopupRoot) node).doComputeLayoutBounds();
 145                 }
 146             });
 147         }
 148 
 149         private final Rectangle geomBoundsRect;
 150 
 151         private double layoutBoundsX;
 152         private double layoutBoundsY;
 153         private double layoutBoundsWidth;
 154         private double layoutBoundsHeight;
 155 
 156         {
 157             // To initialize the class helper at the begining each constructor of this class
 158             PopupRootHelper.initHelper(this);
 159         }
 160         public PopupRoot() {
 161             geomBoundsRect = new Rectangle(0, 0, 100, 100);
 162             layoutBoundsWidth = 100;
 163             layoutBoundsHeight = 100;
 164 
 165             ParentShim.getChildren(this).add(geomBoundsRect);
 166         }
 167 
 168         public void setGeomBounds(final double x, final double y,
 169                                   final double width,
 170                                   final double height) {
 171             geomBoundsRect.setX(x);
 172             geomBoundsRect.setY(y);
 173             geomBoundsRect.setWidth(width);
 174             geomBoundsRect.setHeight(height);
 175         }
 176 
 177         public void setLayoutBounds(final double x, final double y,
 178                                     final double width,
 179                                     final double height) {
 180             layoutBoundsX = x;
 181             layoutBoundsY = y;
 182             layoutBoundsWidth = width;
 183             layoutBoundsHeight = height;
 184 
 185             NodeHelper.layoutBoundsChanged(this);
 186         }
 187 
 188         private Bounds doComputeLayoutBounds() {

 189             return new BoundingBox(layoutBoundsX, layoutBoundsY,
 190                                    layoutBoundsWidth, layoutBoundsHeight);
 191         }
 192     }
 193 
 194     @Test
 195     public void testAnchorPositioning() {
 196         final Popup popup = new Popup();
 197         final PopupRoot root = new PopupRoot();
 198 
 199         root.setGeomBounds(-10, 20, 120, 100);
 200         root.setLayoutBounds(0, 0, 100, 140);
 201 
 202         popup.getScene().setRoot(root);
 203 
 204         popup.setAnchorLocation(PopupWindow.AnchorLocation.WINDOW_BOTTOM_RIGHT);
 205         popup.show(stage, 400, 400);
 206 
 207         final StubPopupStage peer = (StubPopupStage) WindowHelper.getPeer(popup);
 208 


< prev index next >