1 /*
   2  * Copyright (c) 2011, 2016, 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 javafx.css;
  27 
  28 import java.util.List;
  29 
  30 import javafx.collections.ObservableList;
  31 import javafx.collections.ObservableSet;
  32 import javafx.scene.Node;
  33 
  34 /**
  35  * Styleable comprises the minimal interface required for an object to be styled by CSS.
  36  * @see <a href="../scene/doc-files/cssref.html">CSS Reference Guide</a>
  37  * @since JavaFX 8.0
  38  */
  39 public interface Styleable {
  40 
  41     /**
  42      * The type of this {@code Styleable} that is to be used in selector matching.
  43      * This is analogous to an "element" in HTML.
  44      * (<a href="http://www.w3.org/TR/CSS2/selector.html#type-selectors">CSS Type Selector</a>).
  45      */
  46     String getTypeSelector();
  47 
  48     /**
  49      * The id of this {@code Styleable}. This simple string identifier is useful for
  50      * finding a specific Node within the scene graph. While the id of a Node
  51      * should be unique within the scene graph, this uniqueness is not enforced.
  52      * This is analogous to the "id" attribute on an HTML element
  53      * (<a href="http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier">CSS ID Specification</a>).
  54      * <p>
  55      * For example, if a Node is given the id of "myId", then the lookup method can
  56      * be used to find this node as follows: <code>scene.lookup("#myId");</code>.
  57      * </p>
  58      */
  59     String getId();
  60 
  61     /**
  62      * A list of String identifiers which can be used to logically group
  63      * Nodes, specifically for an external style engine. This variable is
  64      * analogous to the "class" attribute on an HTML element and, as such,
  65      * each element of the list is a style class to which this Node belongs.
  66      *
  67      * @see <a href="http://www.w3.org/TR/css3-selectors/#class-html">CSS3 class selectors</a>
  68      */
  69    ObservableList<String> getStyleClass();
  70 
  71     /**
  72      * A string representation of the CSS style associated with this
  73      * specific {@code Node}. This is analogous to the "style" attribute of an
  74      * HTML element. Note that, like the HTML style attribute, this
  75      * variable contains style properties and values and not the
  76      * selector portion of a style rule.
  77      */
  78    String getStyle();
  79 
  80     /**
  81      * The CssMetaData of this Styleable. This may be returned as
  82      * an unmodifiable list.
  83      *
  84      */
  85     List<CssMetaData<? extends Styleable, ?>> getCssMetaData();
  86 
  87     /**
  88      * Return the parent of this Styleable, or null if there is no parent.
  89      */
  90     Styleable getStyleableParent();
  91 
  92     /**
  93      * Return the pseudo-class state of this Styleable. CSS assumes this set is read-only.
  94      */
  95     ObservableSet<PseudoClass> getPseudoClassStates();
  96 
  97     /**
  98      * Returns the Node that represents this Styleable object. This method should be overridden
  99      * in cases where the Styleable is not itself a Node, so that it may optionally
 100      * return the relevant root node representation of itself. By default this method returns
 101      * null, which can mean that either the Styleable itself is a Node, or if that is not
 102      * the case, that the Styleable does not have a node representation available at the
 103      * time of request.
 104      *
 105      * @since 9
 106      */
 107     default Node getStyleableNode() {
 108         return null;
 109     }
 110 }