1 /*
   2  * Copyright (c) 2009, 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 com.sun.javafx.tk;
  27 
  28 import java.security.AccessControlContext;
  29 import javafx.scene.input.KeyCode;
  30 import javafx.scene.input.KeyCodeCombination;
  31 import javafx.scene.input.KeyCombination.ModifierValue;
  32 
  33 /**
  34  * TKStage - Peer interface for a Stage
  35  *
  36  */
  37 public interface TKStage {
  38     /**
  39      * Listener for this stage peer to pass updates and events back to the stage
  40      *
  41      * @param listener The listener provided by the stage
  42      */
  43     public void setTKStageListener(TKStageListener listener);
  44 
  45     /**
  46      * Creates a Scene peer that can be displayed in this Stage peer.
  47      *
  48      * @return scenePeer The peer of the scene to be displayed
  49      */
  50     public TKScene createTKScene(boolean depthBuffer, boolean msaa, AccessControlContext acc);
  51 
  52     /**
  53      * Set the scene to be displayed in this stage
  54      *
  55      * @param scene The peer of the scene to be displayed
  56      */
  57     public void setScene(TKScene scene);
  58 
  59     /**
  60      * Sets the window bounds to the specified values.
  61      *
  62      * Gravity values specify how to correct window location if only its size
  63      * changes (for example when stage decorations are added). User initiated
  64      * resizing should be ignored and must not influence window location through
  65      * this mechanism.
  66      *
  67      * The corresponding correction formulas are:
  68      *
  69      * {@code x -= xGravity * deltaW}
  70      * {@code y -= yGravity * deltaH}
  71      *
  72      * @param x the new window horizontal position, ignored if xSet is set to
  73      *          false
  74      * @param y the new window vertical position, ignored if ySet is set to
  75      *          false
  76      * @param xSet indicates whether the x parameter is valid
  77      * @param ySet indicates whether the y parameter is valid
  78      * @param w the new window width, ignored if set to -1
  79      * @param h the new window height, ignored if set to -1
  80      * @param cw the new window content width, ignored if set to -1
  81      * @param ch the new window content height, ignored if set to -1
  82      * @param xGravity the xGravity coefficient
  83      * @param yGravity the yGravity coefficient
  84      */
  85     public void setBounds(float x, float y, boolean xSet, boolean ySet,
  86                           float w, float h, float cw, float ch,
  87                           float xGravity, float yGravity);
  88 
  89     public float getUIScale();
  90     public float getRenderScale();
  91 
  92     public void setIcons(java.util.List icons);
  93 
  94     public void setTitle(String title);
  95 
  96     /**
  97      * Set if the stage is visible on screen
  98      *
  99      * @param visible True if the stage should be visible
 100      */
 101     public void setVisible(boolean visible);
 102 
 103     public void setOpacity(float opacity);
 104 
 105     public void setIconified(boolean iconified);
 106 
 107     public void setMaximized(boolean maximized);
 108 
 109     public void setAlwaysOnTop(boolean alwaysOnTop);
 110 
 111     public void setResizable(boolean resizable);
 112 
 113     public void setImportant(boolean important);
 114 
 115     public void setMinimumSize(int minWidth, int minHeight);
 116 
 117     public void setMaximumSize(int maxWidth, int maxHeight);
 118 
 119     public void setFullScreen(boolean fullScreen);
 120 
 121     // =================================================================================================================
 122     // Functions
 123 
 124     public void requestFocus();
 125     public void toBack();
 126     public void toFront();
 127     public void close();
 128 
 129     public void requestFocus(FocusCause cause);
 130 
 131     /**
 132      * Grabs focus on this window.
 133      *
 134      * All mouse clicks that occur in this window's client area or client-areas
 135      * of any of its unfocusable owned windows are delivered as usual. Whenever
 136      * a click occurs on another app's window (not related via the ownership
 137      * relation with this one, or a focusable owned window), or on non-client
 138      * area of any window (titlebar, etc.), or any third-party app's window, or
 139      * native OS GUI (e.g. a taskbar), the grab is automatically reset, and the
 140      * window that held the grab receives the FOCUS_UNGRAB event.
 141      *
 142      * Note that for this functionality to work correctly, the window must have
 143      * a focus upon calling this method. All owned popup windows that should be
 144      * operable during the grabbed focus state (e.g. nested popup menus) must
 145      * be unfocusable (see {@link #setFocusable}). Clicking a focusable owned
 146      * window will reset the grab due to a focus transfer.
 147      *
 148      * The click that occurs in another window and causes resetting of the grab
 149      * may or may not be delivered to that other window depending on the native
 150      * OS behavior.
 151      *
 152      * If any of the application's windows already holds the grab, it is reset
 153      * prior to grabbing the focus for this window. The method may be called
 154      * multiple times for one window. Subsequent calls do not affect the grab
 155      * status unless it is reset between the calls, in which case the focus
 156      * is grabbed again.
 157      *
 158      * Note that grabbing the focus on an application window may prevent
 159      * delivering certain events to other applications until the grab is reset.
 160      * Therefore, if the application has finished showing popup windows based
 161      * on a user action (e.g. clicking a menu item), and doesn't require the
 162      * grab any more, it should call the {@link #ungrabFocus} method. The
 163      * FOCUS_UNGRAB event signals that the grab has been reset.
 164      *
 165      * A user event handler associated with a menu item must be invoked after
 166      * resetting the grab. Otherwise, if a developer debugs the application and
 167      * has installed a breakpoint in the event handler, the debugger may become
 168      * unoperable due to events blocking for other applications on some
 169      * platforms.
 170      *
 171      * @return {@code true} if the operation is successful
 172      * @throws IllegalStateException if the window isn't focused currently
 173      */
 174     public boolean grabFocus();
 175 
 176     /**
 177      * Manually ungrabs focus grabbed on this window previously.
 178      *
 179      * This method resets the grab, and forces sending of the FOCUS_UNGRAB
 180      * event. It should be used when popup windows (such as menus) should be
 181      * dismissed manually, e.g. when a user clicks a menu item which usually
 182      * causes the menus to hide.
 183      *
 184      * @see #grabFocus
 185      */
 186     public void ungrabFocus();
 187 
 188     /**
 189      * Requests text input in form of native keyboard for text component
 190      * contained by this Window. Native text input component is drawn on the place
 191      * of JavaFX component to cover it completely and to provide native text editing
 192      * techniques. Any change of text is immediately reflected in JavaFX text component.
 193      *
 194      * @param text text to be shown in the native text input component
 195      * @param type type of text input component @see com.sun.javafx.scene.control.behavior.TextInputTypes
 196      * @param width width of JavaFX text input component
 197      * @param height height of JavaFX text input component
 198      * @param M standard transformation matrix for drawing the native text component derived from JavaFX component
 199      */
 200     void requestInput(String text, int type, double width, double height,
 201                         double Mxx, double Mxy, double Mxz, double Mxt,
 202                         double Myx, double Myy, double Myz, double Myt,
 203                         double Mzx, double Mzy, double Mzz, double Mzt);
 204 
 205     /**
 206      * Native keyboard for text input is no longer necessary.
 207      * Keyboard will be hidden and native text input component too.
 208      */
 209     void releaseInput();
 210 
 211     public void setRTL(boolean b);
 212 
 213     public static final KeyCodeCombination defaultFullScreenExitKeycombo =
 214             new KeyCodeCombination(KeyCode.ESCAPE,
 215             ModifierValue.UP,
 216             ModifierValue.UP,
 217             ModifierValue.UP,
 218             ModifierValue.UP,
 219             ModifierValue.UP);
 220 }