apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/util/Deprecation.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 package com.oracle.javafx.scenebuilder.kit.util;
  33 
  34 import com.sun.glass.ui.Application;
  35 import com.sun.glass.ui.Application.EventHandler;
  36 import com.sun.javafx.css.Style;
  37 import com.sun.javafx.geom.PickRay;
  38 import com.sun.javafx.scene.control.skin.MenuBarSkin;
  39 import com.sun.javafx.scene.input.PickResultChooser;
  40 
  41 import java.net.MalformedURLException;
  42 import java.net.URL;
  43 import java.util.LinkedList;
  44 import java.util.List;
  45 import java.util.Map;
  46 
  47 import javafx.collections.ObservableMap;
  48 import javafx.css.CssMetaData;
  49 import javafx.css.Styleable;
  50 import javafx.css.StyleableProperty;
  51 import javafx.fxml.FXMLLoader;
  52 import javafx.fxml.JavaFXBuilderFactory;
  53 import javafx.geometry.Bounds;
  54 import javafx.geometry.Point2D;
  55 import javafx.scene.Group;
  56 import javafx.scene.Node;
  57 import javafx.scene.Parent;
  58 import javafx.scene.SubScene;
  59 import javafx.scene.control.MenuBar;
  60 import javafx.scene.control.MenuItem;
  61 import javafx.scene.control.PopupControl;
  62 import javafx.scene.control.TableColumn;
  63 import javafx.scene.control.TreeItem;
  64 import javafx.scene.control.TreeTableColumn;
  65 import javafx.scene.control.TreeView;
  66 import javafx.scene.image.Image;
  67 import javafx.scene.layout.GridPane;
  68 
  69 @SuppressWarnings("deprecation")
  70 public class Deprecation {
  71 
  72     private Deprecation() {


  83     public static final String MODENA_TOUCH_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch.css"; //NOI18N
  84     public static final String MODENA_HIGHCONTRAST_BLACKONWHITE_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-blackOnWhite.css"; //NOI18N
  85     public static final String MODENA_HIGHCONTRAST_WHITEONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-whiteOnBlack.css"; //NOI18N
  86     public static final String MODENA_HIGHCONTRAST_YELLOWONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-yellowOnBlack.css"; //NOI18N
  87     public static final String MODENA_TOUCH_HIGHCONTRAST_BLACKONWHITE_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-blackOnWhite.css"; //NOI18N
  88     public static final String MODENA_TOUCH_HIGHCONTRAST_WHITEONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-whiteOnBlack.css"; //NOI18N
  89     public static final String MODENA_TOUCH_HIGHCONTRAST_YELLOWONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-yellowOnBlack.css"; //NOI18N
  90 
  91     // Deprecated stuff in Node
  92 //    // RT-21247 : Promote impl_getAllParentStylesheets to public API
  93     public static Group createGroupWithNullParentStylesheets() {
  94         return new Group() {
  95             @Override
  96             public List<String> impl_getAllParentStylesheets() {
  97                 return null;
  98             }
  99         };
 100     }
 101 
 102 //    // RT-21096 : Promote impl_getStyleMap / impl_setStyleMap to public API
 103     public static void setStyleMap(Node node, ObservableMap<StyleableProperty<?>, List<com.sun.javafx.css.Style>> map) {
 104         node.impl_setStyleMap(map);
 105     }
 106 
 107 //    // RT-21096 : Promote impl_getStyleMap / impl_setStyleMap to public API
 108     public static Map<StyleableProperty<?>, List<Style>> getStyleMap(Node node) {
 109         return node.impl_findStyles(null);
 110     }
 111 
 112     public static void reapplyCSS(Parent parent, String stylesheetPath) {
 113         assert parent != null;
 114         
 115         final List<String> stylesheets = parent.getStylesheets();
 116         for (String s : new LinkedList<>(stylesheets)) {
 117             if (s.endsWith(stylesheetPath)) {
 118                 final int index = stylesheets.indexOf(s);
 119                 assert index != -1;
 120                 stylesheets.remove(index);
 121                 stylesheets.add(index, s);
 122                 break;
 123             }


 167     // Deprecated stuff in Image
 168     // RT-21216 : Promote impl_getUrl to public API
 169     public static String getUrl(Image image) {
 170         return image.impl_getUrl();
 171     }
 172 
 173 //    // RT-21217 : Promote impl_fromPlatformImage to public API
 174 //    public static Image fromPlatformImage(Object platformImage) {
 175 //        return Image.impl_fromPlatformImage(platformImage);
 176 //    }
 177 //    // RT-21219 : Promote impl_getPlatformImage to public API
 178 //    public static Object getPlatformImage(Image image) {
 179 //        return image.impl_getPlatformImage();
 180 //    }
 181     // Deprecated stuff in FXMLLoader
 182     // RT-21226 : Promote setStaticLoad to public API
 183     public static void setStaticLoad(FXMLLoader loader, boolean staticLoad) {
 184         loader.impl_setStaticLoad(staticLoad);
 185     }
 186 
 187     // RT-21228 : Promote setLoadListener to public API
 188     public static void setLoadListener(FXMLLoader loader, com.sun.javafx.fxml.LoadListener loadListener) {
 189         loader.impl_setLoadListener(loadListener);
 190     }
 191 
 192     // RT-20184 : FX should provide a Parent.pick() routine
 193     public static Node pick(Node node, double sceneX, double sceneY) {
 194         final Point2D p = node.sceneToLocal(sceneX, sceneY, true /* rootScene */);
 195         final PickRay pickRay = new PickRay(p.getX(), p.getY(), 1.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
 196         final PickResultChooser prc = new PickResultChooser();
 197         node.impl_pickNode(pickRay, prc);
 198         return prc.getIntersectedNode();






















 199     }
 200 
 201     // RT-19857 : Keeping menu in the Mac menu bar when there is no more stage
 202     public static void setDefaultSystemMenuBar(MenuBar menuBar) {
 203         MenuBarSkin.setDefaultSystemMenuBar(menuBar);
 204     }
 205 
 206 //    // RT-21475 : Promote FXMLLoader.setLoadListener to public API
 207 //    public static ParseTraceElement[] getParseTrace(FXMLLoader loader) {
 208 //        return loader.getParseTrace();
 209 //    }
 210 
 211     public static void setPlatformEventHandler(EventHandler eventHandler) {
 212         Application.GetApplication().setEventHandler(eventHandler);
 213     }
 214 
 215     public static EventHandler getPlatformEventHandler() {
 216         return Application.GetApplication().getEventHandler();
 217     }
 218 
 219     public static int getGridPaneColumnCount(GridPane gridPane) {
 220         return gridPane.impl_getColumnCount();
 221     }
 222 
 223     public static int getGridPaneRowCount(GridPane gridPane) {
 224         return gridPane.impl_getRowCount();
 225     }
 226 
 227     public static Bounds getGridPaneCellBounds(GridPane gridPane, int c, int r) {
 228         return gridPane.impl_getCellBounds(c, r);
 229     }
 230 
 231     // RT-33675 : Promote TableColumn.impl_setReorderable() to public API
 232     @SuppressWarnings("rawtypes")
 233     public static void setTableColumnReordable(TableColumn tableColumn, boolean reordable) {
 234         tableColumn.impl_setReorderable(reordable);
 235     }
 236 
 237     // Returns the corresponding text css (.css) from a binary css (.bss)
 238     public static URL getThemeTextStylesheet(String binaryCssUrlStr) {
 239         String textCssUrlStr = binaryCssUrlStr.replaceAll(".bss", ".css"); //NOI18N
 240         try {
 241             return new URL(textCssUrlStr);
 242         } catch (MalformedURLException ex) {
 243             // should never happen
 244             return null;
 245         }
 246     }
 247 
 248     public static JavaFXBuilderFactory newJavaFXBuilderFactory(ClassLoader classLoader) {
 249         return new JavaFXBuilderFactory(classLoader);
 250     }
 251     
 252     // Deprecated as of FX 8 u20, and replaced by new method getTreeItemLevel:
 253     // using it would break ability to compile over JDK 8 GA, not an option for now.
 254     public static int getNodeLevel(TreeItem<?> item) {
 255         return TreeView.getNodeLevel(item);
 256     } 
 257     
 258     public static Point2D localToLocal(Node source, double sourceX, double sourceY, Node target) {
 259         final Point2D sceneXY = source.localToScene(sourceX, sourceY, true /* rootScene */);
 260         return target.sceneToLocal(sceneXY, true /* rootScene */);
 261     }
 262     
 263     public static Bounds localToLocal(Node source, Bounds sourceBounds, Node target) {
 264         final Bounds sceneBounds = source.localToScene(sourceBounds, true /* rootScene */);
 265         return target.sceneToLocal(sceneBounds, true /* rootScene */);
 266     }
 267 }


  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 package com.oracle.javafx.scenebuilder.kit.util;
  33 
  34 import javafx.css.Style;
  35 import javafx.scene.control.skin.MenuBarSkin;




  36 
  37 import java.net.MalformedURLException;
  38 import java.net.URL;
  39 import java.util.LinkedList;
  40 import java.util.List;
  41 import java.util.Map;
  42 
  43 import javafx.collections.ObservableMap;
  44 import javafx.css.CssMetaData;
  45 import javafx.css.Styleable;
  46 import javafx.css.StyleableProperty;
  47 import javafx.fxml.FXMLLoader;

  48 import javafx.geometry.Bounds;
  49 import javafx.geometry.Point2D;
  50 import javafx.scene.Group;
  51 import javafx.scene.Node;
  52 import javafx.scene.Parent;
  53 import javafx.scene.SubScene;
  54 import javafx.scene.control.MenuBar;
  55 import javafx.scene.control.MenuItem;
  56 import javafx.scene.control.PopupControl;
  57 import javafx.scene.control.TableColumn;
  58 import javafx.scene.control.TreeItem;
  59 import javafx.scene.control.TreeTableColumn;
  60 import javafx.scene.control.TreeView;
  61 import javafx.scene.image.Image;
  62 import javafx.scene.layout.GridPane;
  63 
  64 @SuppressWarnings("deprecation")
  65 public class Deprecation {
  66 
  67     private Deprecation() {


  78     public static final String MODENA_TOUCH_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch.css"; //NOI18N
  79     public static final String MODENA_HIGHCONTRAST_BLACKONWHITE_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-blackOnWhite.css"; //NOI18N
  80     public static final String MODENA_HIGHCONTRAST_WHITEONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-whiteOnBlack.css"; //NOI18N
  81     public static final String MODENA_HIGHCONTRAST_YELLOWONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-yellowOnBlack.css"; //NOI18N
  82     public static final String MODENA_TOUCH_HIGHCONTRAST_BLACKONWHITE_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-blackOnWhite.css"; //NOI18N
  83     public static final String MODENA_TOUCH_HIGHCONTRAST_WHITEONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-whiteOnBlack.css"; //NOI18N
  84     public static final String MODENA_TOUCH_HIGHCONTRAST_YELLOWONBLACK_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-yellowOnBlack.css"; //NOI18N
  85 
  86     // Deprecated stuff in Node
  87 //    // RT-21247 : Promote impl_getAllParentStylesheets to public API
  88     public static Group createGroupWithNullParentStylesheets() {
  89         return new Group() {
  90             @Override
  91             public List<String> impl_getAllParentStylesheets() {
  92                 return null;
  93             }
  94         };
  95     }
  96 
  97 //    // RT-21096 : Promote impl_getStyleMap / impl_setStyleMap to public API
  98     public static void setStyleMap(Node node, ObservableMap<StyleableProperty<?>, List<javafx.css.Style>> map) {
  99         node.impl_setStyleMap(map);
 100     }
 101 
 102 //    // RT-21096 : Promote impl_getStyleMap / impl_setStyleMap to public API
 103     public static Map<StyleableProperty<?>, List<Style>> getStyleMap(Node node) {
 104         return node.impl_findStyles(null);
 105     }
 106 
 107     public static void reapplyCSS(Parent parent, String stylesheetPath) {
 108         assert parent != null;
 109         
 110         final List<String> stylesheets = parent.getStylesheets();
 111         for (String s : new LinkedList<>(stylesheets)) {
 112             if (s.endsWith(stylesheetPath)) {
 113                 final int index = stylesheets.indexOf(s);
 114                 assert index != -1;
 115                 stylesheets.remove(index);
 116                 stylesheets.add(index, s);
 117                 break;
 118             }


 162     // Deprecated stuff in Image
 163     // RT-21216 : Promote impl_getUrl to public API
 164     public static String getUrl(Image image) {
 165         return image.impl_getUrl();
 166     }
 167 
 168 //    // RT-21217 : Promote impl_fromPlatformImage to public API
 169 //    public static Image fromPlatformImage(Object platformImage) {
 170 //        return Image.impl_fromPlatformImage(platformImage);
 171 //    }
 172 //    // RT-21219 : Promote impl_getPlatformImage to public API
 173 //    public static Object getPlatformImage(Image image) {
 174 //        return image.impl_getPlatformImage();
 175 //    }
 176     // Deprecated stuff in FXMLLoader
 177     // RT-21226 : Promote setStaticLoad to public API
 178     public static void setStaticLoad(FXMLLoader loader, boolean staticLoad) {
 179         loader.impl_setStaticLoad(staticLoad);
 180     }
 181 





 182     // RT-20184 : FX should provide a Parent.pick() routine
 183     public static Node pick(Node node, double sceneX, double sceneY) {
 184         Point2D p = node.sceneToLocal(sceneX, sceneY, true /* rootScene */);
 185 
 186         // check if the given node has the point inside it, or else we drop out
 187         if (!node.contains(p)) return null;
 188 
 189         // at this point we know that _at least_ the given node is a valid
 190         // answer to the given point, so we will return that if we don't find
 191         // a better child option
 192         if (node instanceof Parent) {
 193             // we iterate through all children (recursively). We don't stop
 194             // iteration when we hit the first child that also contains the bounds,
 195             // as we know that later nodes have a higher z-ordering, so they
 196             // should be picked before the earlier nodes.
 197             Node bestMatchingChild = null;
 198             for (Node child : ((Parent)node).getChildrenUnmodifiable()) {
 199                 p = child.sceneToLocal(sceneX, sceneY, true /* rootScene */);
 200                 if (child.contains(p)) {
 201                     bestMatchingChild = child;
 202                 }
 203             }
 204 
 205             if (bestMatchingChild != null) {
 206                 return pick(bestMatchingChild, sceneX, sceneY);
 207             }
 208         }
 209 
 210         return node;
 211     }
 212 
 213     // RT-19857 : Keeping menu in the Mac menu bar when there is no more stage
 214     public static void setDefaultSystemMenuBar(MenuBar menuBar) {
 215         MenuBarSkin.setDefaultSystemMenuBar(menuBar);
 216     }
 217 
 218 //    // RT-21475 : Promote FXMLLoader.setLoadListener to public API
 219 //    public static ParseTraceElement[] getParseTrace(FXMLLoader loader) {
 220 //        return loader.getParseTrace();
 221 //    }
 222 








 223     public static int getGridPaneColumnCount(GridPane gridPane) {
 224         return gridPane.impl_getColumnCount();
 225     }
 226 
 227     public static int getGridPaneRowCount(GridPane gridPane) {
 228         return gridPane.impl_getRowCount();
 229     }
 230 
 231     public static Bounds getGridPaneCellBounds(GridPane gridPane, int c, int r) {
 232         return gridPane.impl_getCellBounds(c, r);
 233     }
 234 
 235     // RT-33675 : Promote TableColumn.impl_setReorderable() to public API
 236     @SuppressWarnings("rawtypes")
 237     public static void setTableColumnReordable(TableColumn tableColumn, boolean reordable) {
 238         tableColumn.impl_setReorderable(reordable);
 239     }
 240 
 241     // Returns the corresponding text css (.css) from a binary css (.bss)
 242     public static URL getThemeTextStylesheet(String binaryCssUrlStr) {
 243         String textCssUrlStr = binaryCssUrlStr.replaceAll(".bss", ".css"); //NOI18N
 244         try {
 245             return new URL(textCssUrlStr);
 246         } catch (MalformedURLException ex) {
 247             // should never happen
 248             return null;
 249         }
 250     }
 251 




 252     // Deprecated as of FX 8 u20, and replaced by new method getTreeItemLevel:
 253     // using it would break ability to compile over JDK 8 GA, not an option for now.
 254     public static int getNodeLevel(TreeItem<?> item) {
 255         return TreeView.getNodeLevel(item);
 256     } 
 257     
 258     public static Point2D localToLocal(Node source, double sourceX, double sourceY, Node target) {
 259         final Point2D sceneXY = source.localToScene(sourceX, sourceY, true /* rootScene */);
 260         return target.sceneToLocal(sceneXY, true /* rootScene */);
 261     }
 262     
 263     public static Bounds localToLocal(Node source, Bounds sourceBounds, Node target) {
 264         final Bounds sceneBounds = source.localToScene(sourceBounds, true /* rootScene */);
 265         return target.sceneToLocal(sceneBounds, true /* rootScene */);
 266     }
 267 }