1 /*
   2  * Copyright (c) 2009, 2012, 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 package org.jemmy.fx;
  26 
  27 import javafx.scene.Node;
  28 import javafx.scene.Scene;
  29 import org.jemmy.control.Wrap;
  30 import org.jemmy.interfaces.Parent;
  31 
  32 /**
  33  * This class is intended for static import. It provides some shortcuts
  34  * to the most used functionality of Jemmy classes.
  35  * @author shura
  36  * @deprecated Use Docks.
  37  * @see SceneDock
  38  * @see NodeDock
  39  */
  40 public class Lookups {
  41     /**
  42      * Equivalent to <code>parent.lookup(type, new ByID<T>(id)).wrap(0)</code>
  43      * @param <T>
  44      * @param parent
  45      * @param id
  46      * @param type
  47      * @return
  48      */
  49     public static <T extends Node> Wrap<? extends T> byID(Parent<Node> parent, String id, Class<T> type) {
  50         return parent.lookup(type, new ByID<T>(id)).wrap(0);
  51     }
  52     /**
  53      * Takes <code>parent</code> as <code>Parent</code>. May throw an exception if not a parent.
  54      * @see #byID(org.jemmy.interfaces.Parent, java.lang.String, java.lang.Class)
  55      * @param <T>
  56      * @param parent
  57      * @param id
  58      * @param type
  59      * @return
  60      */
  61     @SuppressWarnings("unchecked")
  62     public static <T extends Node> Wrap<? extends T> byID(Wrap<?> parent, String id, Class<T> type) {
  63         return byID((Parent<Node>) parent.as(Parent.class, Node.class), id, type);
  64     }
  65     /**
  66      * Equivalent to <code>parent.lookup(type, new ByText<T>(text)).wrap(0)</code>
  67      * @param <T>
  68      * @param parent
  69      * @param text
  70      * @param type
  71      * @return
  72      */
  73     public static <T extends Node> Wrap<? extends T> byText(Parent<Node> parent, String text, Class<T> type) {
  74         return parent.lookup(type, new ByText<T>(text)).wrap(0);
  75     }
  76     /**
  77      * Takes <code>parent</code> as <code>Parent</code>. May throw an exception if not a parent.
  78      * @see #byID(org.jemmy.interfaces.Parent, java.lang.String, java.lang.Class)
  79      * @param <T>
  80      * @param parent
  81      * @param id
  82      * @param type
  83      * @return
  84      */
  85     @SuppressWarnings("unchecked")
  86     public static <T extends Node> Wrap<? extends T> byText(Wrap<?> parent, String id, Class<T> type) {
  87         return byText((Parent<Node>) parent.as(Parent.class, Node.class), id, type);
  88     }
  89     /**
  90      * Equivalent to <code>FXRoot.ROOT.lookup(new ByTitleSceneLookup<Scene>(title)).wrap(0).as(Parent.class, Node.class)</code>
  91      * @param title
  92      * @return
  93      */
  94     public static Wrap<? extends Scene> byTitle(String title) {
  95         return Root.ROOT.lookup(new ByTitleSceneLookup<Scene>(title)).wrap(0);
  96     }
  97 }