Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.css; 027 028import com.sun.javafx.css.PseudoClassState; 029 030/** 031 * PseudoClass represents one unique pseudo-class state. Introducing a 032 * pseudo-class into a JavaFX class only requires that the method 033 * {@link javafx.scene.Node#pseudoClassStateChanged(javafx.css.PseudoClass, boolean)} 034 * be called when the pseudo-class state changes. Typically, the 035 * {@code pseudoClassStateChanged} method is called from the 036 * {@code protected void invalidated()} method of one of the property base 037 * classes in the {@code javafx.beans.property} package. 038 * <p> 039 * Note that if a node has a default pseudo-class state, a horizontal orientation 040 * for example, {@code pseudoClassStateChanged} should be called from the 041 * constructor to set the initial state. 042 * <p> 043 * The following example would allow "xyzzy" to be used as a 044 * pseudo-class in a CSS selector. 045 * <code> 046 * <pre> 047 * public boolean isMagic() { 048 * return magic.get(); 049 * } 050 * 051 * public BooleanProperty magicProperty() { 052 * return magic; 053 * } 054 * 055 * public BooleanProperty magic = 056 * new BooleanPropertyBase(false) { 057 * 058 * {@literal @}Override protected void invalidated() { 059 * pseudoClassStateChanged(MAGIC_PSEUDO_CLASS. get()); 060 * } 061 * 062 * {@literal @}Override public Object getBean() { 063 * return MyControl.this; 064 * } 065 * 066 * {@literal @}Override public String getName() { 067 * return "magic"; 068 * } 069 * } 070 * 071 * private static final PseudoClass 072 * MAGIC_PSEUDO_CLASS = PseudoClass.getPseudoClassName("xyzzy"); 073 * </pre> 074 * </code> 075 */ 076public abstract class PseudoClass { 077 078 /** 079 * There is only one PseudoClass instance for a given pseudoClass. 080 * @return The PseudoClass for the given pseudoClass. Will not return null. 081 * @throws IllegalArgumentException if pseudoClass parameter is null or an empty String 082 */ 083 public static PseudoClass getPseudoClass(String pseudoClass) { 084 085 final PseudoClass instance = PseudoClassState.getPseudoClass(pseudoClass); 086 return instance; 087 } 088 089 /** @return the pseudo-class state */ 090 abstract public String getPseudoClassName(); 091 092}