< prev index next >

modules/graphics/src/main/java/javafx/stage/Window.java

Print this page




  50 import javafx.event.EventDispatcher;
  51 import javafx.event.EventHandler;
  52 import javafx.event.EventTarget;
  53 import javafx.event.EventType;
  54 import javafx.geometry.Rectangle2D;
  55 import javafx.scene.Scene;
  56 
  57 import com.sun.javafx.util.Utils;
  58 import com.sun.javafx.css.StyleManager;
  59 import com.sun.javafx.stage.WindowEventDispatcher;
  60 import com.sun.javafx.stage.WindowHelper;
  61 import com.sun.javafx.stage.WindowPeerListener;
  62 import com.sun.javafx.tk.TKPulseListener;
  63 import com.sun.javafx.tk.TKScene;
  64 import com.sun.javafx.tk.TKStage;
  65 import com.sun.javafx.tk.Toolkit;
  66 import javafx.beans.property.BooleanProperty;
  67 import javafx.beans.property.SimpleBooleanProperty;
  68 
  69 import static com.sun.javafx.FXPermissions.ACCESS_WINDOW_LIST_PERMISSION;

  70 import com.sun.javafx.scene.SceneHelper;
  71 
  72 
  73 /**
  74  * <p>
  75  *     A top level window within which a scene is hosted, and with which the user
  76  *     interacts. A Window might be a {@link Stage}, {@link PopupWindow}, or other
  77  *     such top level. A Window is used also for browser plug-in based deployments.
  78  * </p>
  79  *
  80  * @since JavaFX 2.0
  81  */
  82 public class Window implements EventTarget {
  83 
  84     /**
  85      * A list of all the currently _showing_ windows. This is publicly accessible via the unmodifiableWindows wrapper.
  86      */
  87     private static ObservableList<Window> windows = FXCollections.observableArrayList();
  88     private static ObservableList<Window> unmodifiableWindows = FXCollections.unmodifiableObservableList(windows);
  89 


 780             }
 781             if (newScene != null) {
 782                 final Window oldWindow = newScene.getWindow();
 783                 if (oldWindow != null) {
 784                     // if the new scene was previously set to a window
 785                     // we need to remove it from that window
 786                     // NOTE: can this "scene" property be bound?
 787                     oldWindow.setScene(null);
 788                 }
 789 
 790                 // Set the "window" on the new scene. This will also trigger
 791                 // scene's peer creation.
 792                 SceneHelper.setWindow(newScene, Window.this);
 793                 // Set scene impl on stage impl
 794                 updatePeerScene(SceneHelper.getPeer(newScene));
 795 
 796                 // Fix for RT-15432: we should update new Scene's stylesheets, if the
 797                 // window is already showing. For not yet shown windows, the update is
 798                 // performed in doVisibleChanging()
 799                 if (isShowing()) {
 800                     newScene.getRoot().impl_reapplyCSS();
 801 
 802                     if (!widthExplicit || !heightExplicit) {
 803                         SceneHelper.preferredSize(getScene());
 804                         adjustSize(true);
 805                     }
 806                 }
 807             }
 808 
 809             oldScene = newScene;
 810         }
 811 
 812         @Override
 813         public Object getBean() {
 814             return Window.this;
 815         }
 816 
 817         @Override
 818         public String getName() {
 819             return "scene";
 820         }


1177     protected void show() {
1178         setShowing(true);
1179     }
1180 
1181     /**
1182      * Attempts to hide this Window by setting the visibility to false.
1183      *
1184      * @throws IllegalStateException if this method is called on a thread
1185      * other than the JavaFX Application Thread.
1186      */
1187     public void hide() {
1188         setShowing(false);
1189     }
1190 
1191     /*
1192      * This can be replaced by listening for the onShowing/onHiding events
1193      * Note: This method MUST only be called via its accessor method.
1194      */
1195     private void doVisibleChanging(boolean visible) {
1196         if (visible && (getScene() != null)) {
1197             getScene().getRoot().impl_reapplyCSS();
1198         }
1199     }
1200 
1201     /*
1202      * This can be replaced by listening for the onShown/onHidden events
1203      * Note: This method MUST only be called via its accessor method.
1204      */
1205     private void doVisibleChanged(boolean visible) {
1206         assert peer != null;
1207         if (!visible) {
1208             peerListener = null;
1209             peer = null;
1210         }
1211     }
1212 
1213     // PENDING_DOC_REVIEW
1214     /**
1215      * Specifies the event dispatcher for this node. The default event
1216      * dispatcher sends the received events to the registered event handlers and
1217      * filters. When replacing the value with a new {@code EventDispatcher},




  50 import javafx.event.EventDispatcher;
  51 import javafx.event.EventHandler;
  52 import javafx.event.EventTarget;
  53 import javafx.event.EventType;
  54 import javafx.geometry.Rectangle2D;
  55 import javafx.scene.Scene;
  56 
  57 import com.sun.javafx.util.Utils;
  58 import com.sun.javafx.css.StyleManager;
  59 import com.sun.javafx.stage.WindowEventDispatcher;
  60 import com.sun.javafx.stage.WindowHelper;
  61 import com.sun.javafx.stage.WindowPeerListener;
  62 import com.sun.javafx.tk.TKPulseListener;
  63 import com.sun.javafx.tk.TKScene;
  64 import com.sun.javafx.tk.TKStage;
  65 import com.sun.javafx.tk.Toolkit;
  66 import javafx.beans.property.BooleanProperty;
  67 import javafx.beans.property.SimpleBooleanProperty;
  68 
  69 import static com.sun.javafx.FXPermissions.ACCESS_WINDOW_LIST_PERMISSION;
  70 import com.sun.javafx.scene.NodeHelper;
  71 import com.sun.javafx.scene.SceneHelper;
  72 
  73 
  74 /**
  75  * <p>
  76  *     A top level window within which a scene is hosted, and with which the user
  77  *     interacts. A Window might be a {@link Stage}, {@link PopupWindow}, or other
  78  *     such top level. A Window is used also for browser plug-in based deployments.
  79  * </p>
  80  *
  81  * @since JavaFX 2.0
  82  */
  83 public class Window implements EventTarget {
  84 
  85     /**
  86      * A list of all the currently _showing_ windows. This is publicly accessible via the unmodifiableWindows wrapper.
  87      */
  88     private static ObservableList<Window> windows = FXCollections.observableArrayList();
  89     private static ObservableList<Window> unmodifiableWindows = FXCollections.unmodifiableObservableList(windows);
  90 


 781             }
 782             if (newScene != null) {
 783                 final Window oldWindow = newScene.getWindow();
 784                 if (oldWindow != null) {
 785                     // if the new scene was previously set to a window
 786                     // we need to remove it from that window
 787                     // NOTE: can this "scene" property be bound?
 788                     oldWindow.setScene(null);
 789                 }
 790 
 791                 // Set the "window" on the new scene. This will also trigger
 792                 // scene's peer creation.
 793                 SceneHelper.setWindow(newScene, Window.this);
 794                 // Set scene impl on stage impl
 795                 updatePeerScene(SceneHelper.getPeer(newScene));
 796 
 797                 // Fix for RT-15432: we should update new Scene's stylesheets, if the
 798                 // window is already showing. For not yet shown windows, the update is
 799                 // performed in doVisibleChanging()
 800                 if (isShowing()) {
 801                     NodeHelper.reapplyCSS(newScene.getRoot());
 802 
 803                     if (!widthExplicit || !heightExplicit) {
 804                         SceneHelper.preferredSize(getScene());
 805                         adjustSize(true);
 806                     }
 807                 }
 808             }
 809 
 810             oldScene = newScene;
 811         }
 812 
 813         @Override
 814         public Object getBean() {
 815             return Window.this;
 816         }
 817 
 818         @Override
 819         public String getName() {
 820             return "scene";
 821         }


1178     protected void show() {
1179         setShowing(true);
1180     }
1181 
1182     /**
1183      * Attempts to hide this Window by setting the visibility to false.
1184      *
1185      * @throws IllegalStateException if this method is called on a thread
1186      * other than the JavaFX Application Thread.
1187      */
1188     public void hide() {
1189         setShowing(false);
1190     }
1191 
1192     /*
1193      * This can be replaced by listening for the onShowing/onHiding events
1194      * Note: This method MUST only be called via its accessor method.
1195      */
1196     private void doVisibleChanging(boolean visible) {
1197         if (visible && (getScene() != null)) {
1198             NodeHelper.reapplyCSS(getScene().getRoot());
1199         }
1200     }
1201 
1202     /*
1203      * This can be replaced by listening for the onShown/onHidden events
1204      * Note: This method MUST only be called via its accessor method.
1205      */
1206     private void doVisibleChanged(boolean visible) {
1207         assert peer != null;
1208         if (!visible) {
1209             peerListener = null;
1210             peer = null;
1211         }
1212     }
1213 
1214     // PENDING_DOC_REVIEW
1215     /**
1216      * Specifies the event dispatcher for this node. The default event
1217      * dispatcher sends the received events to the registered event handlers and
1218      * filters. When replacing the value with a new {@code EventDispatcher},


< prev index next >