1 /*
   2  * Copyright (c) 2011, 2013, 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 com.sun.javafx.css;
  27 
  28 import com.sun.javafx.css.converters.SizeConverter;
  29 import java.util.ArrayList;
  30 import java.util.Collections;
  31 import java.util.List;
  32 import javafx.beans.property.DoubleProperty;
  33 import javafx.css.CssMetaData;
  34 import javafx.css.Styleable;
  35 import javafx.css.StyleableDoubleProperty;
  36 import javafx.css.StyleableProperty;
  37 import javafx.scene.Node;
  38 
  39 /** Test Node with styleable property but no getClassCssMetaData method */
  40 class TestNode extends TestNodeBase {
  41 
  42     private DoubleProperty xyzzy;
  43     private DoubleProperty xyzzyProperty() {
  44         if (xyzzy == null) {
  45             xyzzy = new StyleableDoubleProperty(.5) {
  46 
  47                 @Override
  48                 public Object getBean() {
  49                     return TestNode.this;
  50                 }
  51 
  52                 @Override
  53                 public String getName() {
  54                     return "xyzzy";
  55                 }
  56 
  57                 @Override
  58                 public CssMetaData<TestNode, Number> getCssMetaData() {
  59                     return StyleableProperties.XYZZY;
  60                 }
  61                 
  62             };
  63         }
  64         return xyzzy;
  65     }
  66     
  67     public void setXyzzy(double number) {
  68         xyzzyProperty().set(number);
  69     }
  70     
  71     public double getXyzzy() {
  72         return (xyzzy == null ? .5 : xyzzy.get());
  73     }
  74 
  75     public TestNode() {
  76         super();
  77     }
  78     
  79      static class StyleableProperties {
  80 
  81          static final CssMetaData<TestNode, Number> XYZZY = 
  82              new CssMetaData<TestNode, Number>("-fx-xyzzy",
  83                  SizeConverter.getInstance(),
  84                  .5) {
  85 
  86             @Override
  87             public boolean isSettable(TestNode node) {
  88                 return node.xyzzy == null || !node.xyzzy.isBound();
  89             }
  90 
  91             @Override
  92             public StyleableProperty<Number> getStyleableProperty(TestNode node) {
  93                 return (StyleableProperty<Number>)node.xyzzyProperty();
  94             }
  95                      
  96          };
  97             
  98          private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
  99          static {
 100             final List<CssMetaData<? extends Styleable, ?>> styleables = 
 101                 new ArrayList<CssMetaData<? extends Styleable, ?>>(TestNodeBase.getClassCssMetaData());
 102             styleables.add(XYZZY);
 103             STYLEABLES = Collections.unmodifiableList(styleables);
 104          }
 105     }
 106 
 107     /**
 108      * @return The CssMetaData associated with this class, which may include the
 109      * CssMetaData of its super classes.
 110      */
 111     public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
 112         return StyleableProperties.STYLEABLES;
 113     }
 114 
 115     /**
 116      * {@inheritDoc}
 117      *
 118      */
 119     
 120     
 121     @Override
 122     public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
 123         return getClassCssMetaData();
 124     }
 125 
 126 }