1 /*
   2  * Copyright (c) 2011, 2014, 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 static junit.framework.Assert.assertEquals;
  29 import static junit.framework.Assert.assertTrue;
  30 import static junit.framework.Assert.assertNotNull;
  31 import javafx.beans.property.DoubleProperty;
  32 import javafx.beans.property.SimpleDoubleProperty;
  33 
  34 import org.junit.Before;
  35 import org.junit.Test;
  36 
  37 import test.com.sun.javafx.pgstub.StubStage;
  38 import test.com.sun.javafx.pgstub.StubToolkit;
  39 import com.sun.javafx.tk.TKStage;
  40 import com.sun.javafx.tk.Toolkit;
  41 import javafx.stage.Stage;
  42 import javafx.stage.Window;
  43 
  44 public final class WindowTest {
  45     private StubToolkit toolkit;
  46     private Stage testWindow;
  47 
  48     @Before
  49     public void setUp() {
  50         toolkit = (StubToolkit) Toolkit.getToolkit();
  51         testWindow = new Stage();
  52     }
  53 
  54     @Test
  55     public void testOpacityBind() {
  56         final DoubleProperty variable = new SimpleDoubleProperty(0.5);
  57 
  58         testWindow.show();
  59         final StubStage peer = getPeer(testWindow);
  60 
  61         testWindow.opacityProperty().bind(variable);
  62         toolkit.fireTestPulse();
  63 
  64         assertEquals(0.5f, peer.opacity);
  65 
  66         variable.set(1.0f);
  67         toolkit.fireTestPulse();
  68 
  69         assertEquals(1.0f, peer.opacity);
  70     }
  71     
  72     @Test public void testProperties() {
  73         javafx.collections.ObservableMap<Object, Object> properties = testWindow.getProperties();
  74 
  75         /* If we ask for it, we should get it.
  76          */
  77         assertNotNull(properties);
  78 
  79         /* What we put in, we should get out.
  80          */
  81         properties.put("MyKey", "MyValue");
  82         assertEquals("MyValue", properties.get("MyKey"));
  83 
  84         /* If we ask for it again, we should get the same thing.
  85          */
  86         javafx.collections.ObservableMap<Object, Object> properties2 = testWindow.getProperties();
  87         assertEquals(properties2, properties);
  88 
  89         /* What we put in to the other one, we should get out of this one because
  90          * they should be the same thing.
  91          */
  92         assertEquals("MyValue", properties2.get("MyKey"));
  93     }
  94 
  95     private static StubStage getPeer(final Window window) {
  96         final TKStage unkPeer = window.impl_getPeer();
  97         assertTrue(unkPeer instanceof StubStage);
  98         return (StubStage) unkPeer;
  99     }
 100 }