1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  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() {
  68         assert false;
  69     }
  70 
  71     public static final String CASPIAN_STYLESHEET = "com/sun/javafx/scene/control/skin/caspian/caspian.bss"; //NOI18N
  72     public static final String CASPIAN_HIGHCONTRAST_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-highContrast.css"; //NOI18N
  73     public static final String CASPIAN_EMBEDDED_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded.css"; //NOI18N
  74     public static final String CASPIAN_EMBEDDED_HIGHCONTRAST_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded-highContrast.css"; //NOI18N
  75     public static final String CASPIAN_EMBEDDED_QVGA_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded-qvga.css"; //NOI18N
  76     public static final String CASPIAN_EMBEDDED_QVGA_HIGHCONTRAST_STYLESHEET = "com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded-qvga-highContrast.css"; //NOI18N
  77     public static final String MODENA_STYLESHEET = "com/sun/javafx/scene/control/skin/modena/modena.bss"; //NOI18N
  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         System.err.println("Error: impl_getAllParentStylesheets is no longer publicly accessible");
  90         return new Group() {
  91 //            @Override
  92 //            public List<String> impl_getAllParentStylesheets() {
  93 //                return null;
  94 //            }
  95         };
  96     }
  97 
  98 //    // RT-21096 : Promote impl_getStyleMap / impl_setStyleMap to public API
  99     public static void setStyleMap(Node node, ObservableMap<StyleableProperty<?>, List<javafx.css.Style>> map) {
 100         // node.impl_setStyleMap(map);
 101         System.err.println("Error: impl_setStyleMap is no longer publicly accessible");
 102     }
 103 
 104 //    // RT-21096 : Promote impl_getStyleMap / impl_setStyleMap to public API
 105     public static Map<StyleableProperty<?>, List<Style>> getStyleMap(Node node) {
 106 //        return node.impl_findStyles(null);
 107         System.err.println("Error: findStyles is no longer publicly accessible");
 108         return null;
 109     }
 110 
 111     public static void reapplyCSS(Parent parent, String stylesheetPath) {
 112         assert parent != null;
 113 
 114         final List<String> stylesheets = parent.getStylesheets();
 115         for (String s : new LinkedList<>(stylesheets)) {
 116             if (s.endsWith(stylesheetPath)) {
 117                 final int index = stylesheets.indexOf(s);
 118                 assert index != -1;
 119                 stylesheets.remove(index);
 120                 stylesheets.add(index, s);
 121                 break;
 122             }
 123         }
 124 
 125         for (Node child : parent.getChildrenUnmodifiable()) {
 126             if (child instanceof Parent) {
 127                 final Parent childParent = (Parent) child;
 128                 reapplyCSS(childParent, stylesheetPath);
 129             } else if (child instanceof SubScene) {
 130                 final SubScene childSubScene = (SubScene) child;
 131                 reapplyCSS(childSubScene.getRoot(), stylesheetPath);
 132             }
 133         }
 134     }
 135 
 136     @SuppressWarnings("rawtypes")
 137     public static List<Style> getMatchingStyles(CssMetaData cssMetaData, Styleable styleable) {
 138 //        return Node.impl_getMatchingStyles(cssMetaData, styleable);
 139         System.err.println("Error: impl_getMatchingStyles is no longer publicly accessible");
 140         return null;
 141     }
 142 
 143     // Deprecated stuff in Parent
 144 
 145     // Deprecated stuff in FXMLLoader
 146     // RT-21226 : Promote setStaticLoad to public API
 147     public static void setStaticLoad(FXMLLoader loader, boolean staticLoad) {
 148         loader.impl_setStaticLoad(staticLoad);
 149     }
 150 
 151     // RT-20184 : FX should provide a Parent.pick() routine
 152     public static Node pick(Node node, double sceneX, double sceneY) {
 153         Point2D p = node.sceneToLocal(sceneX, sceneY, true /* rootScene */);
 154 
 155         // check if the given node has the point inside it, or else we drop out
 156         if (!node.contains(p)) return null;
 157 
 158         // at this point we know that _at least_ the given node is a valid
 159         // answer to the given point, so we will return that if we don't find
 160         // a better child option
 161         if (node instanceof Parent) {
 162             // we iterate through all children (recursively). We don't stop
 163             // iteration when we hit the first child that also contains the bounds,
 164             // as we know that later nodes have a higher z-ordering, so they
 165             // should be picked before the earlier nodes.
 166             Node bestMatchingChild = null;
 167             for (Node child : ((Parent)node).getChildrenUnmodifiable()) {
 168                 p = child.sceneToLocal(sceneX, sceneY, true /* rootScene */);
 169                 if (child.contains(p)) {
 170                     bestMatchingChild = child;
 171                 }
 172             }
 173 
 174             if (bestMatchingChild != null) {
 175                 return pick(bestMatchingChild, sceneX, sceneY);
 176             }
 177         }
 178 
 179         return node;
 180     }
 181 
 182     // RT-19857 : Keeping menu in the Mac menu bar when there is no more stage
 183     public static void setDefaultSystemMenuBar(MenuBar menuBar) {
 184         MenuBarSkin.setDefaultSystemMenuBar(menuBar);
 185     }
 186 
 187 //    // RT-21475 : Promote FXMLLoader.setLoadListener to public API
 188 //    public static ParseTraceElement[] getParseTrace(FXMLLoader loader) {
 189 //        return loader.getParseTrace();
 190 //    }
 191 
 192     public static int getGridPaneColumnCount(GridPane gridPane) {
 193         return gridPane.getColumnCount();
 194     }
 195 
 196     public static int getGridPaneRowCount(GridPane gridPane) {
 197         return gridPane.getRowCount();
 198     }
 199 
 200     public static Bounds getGridPaneCellBounds(GridPane gridPane, int c, int r) {
 201         return gridPane.getCellBounds(c, r);
 202     }
 203 
 204     // Returns the corresponding text css (.css) from a binary css (.bss)
 205     public static URL getThemeTextStylesheet(String binaryCssUrlStr) {
 206         String textCssUrlStr = binaryCssUrlStr.replaceAll(".bss", ".css"); //NOI18N
 207         try {
 208             return new URL(textCssUrlStr);
 209         } catch (MalformedURLException ex) {
 210             // should never happen
 211             return null;
 212         }
 213     }
 214 
 215     // Deprecated as of FX 8 u20, and replaced by new method getTreeItemLevel:
 216     // using it would break ability to compile over JDK 8 GA, not an option for now.
 217     public static int getNodeLevel(TreeItem<?> item) {
 218         return TreeView.getNodeLevel(item);
 219     }
 220 
 221     public static Point2D localToLocal(Node source, double sourceX, double sourceY, Node target) {
 222         final Point2D sceneXY = source.localToScene(sourceX, sourceY, true /* rootScene */);
 223         return target.sceneToLocal(sceneXY, true /* rootScene */);
 224     }
 225 
 226     public static Bounds localToLocal(Node source, Bounds sourceBounds, Node target) {
 227         final Bounds sceneBounds = source.localToScene(sourceBounds, true /* rootScene */);
 228         return target.sceneToLocal(sceneBounds, true /* rootScene */);
 229     }
 230 }