modules/graphics/src/main/java/com/sun/javafx/scene/layout/region/BackgroundSizeConverter.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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.scene.layout.region;
  27 
  28 import javafx.css.ParsedValue;
  29 import com.sun.javafx.css.Size;
  30 import com.sun.javafx.css.SizeUnits;
  31 import com.sun.javafx.css.StyleConverterImpl;
  32 import com.sun.javafx.css.converters.BooleanConverter;
  33 import javafx.scene.layout.BackgroundSize;
  34 import javafx.scene.text.Font;
  35 
  36 /**
  37  */
  38 public final class BackgroundSizeConverter  extends StyleConverterImpl<ParsedValue[], BackgroundSize> {
  39     private static final BackgroundSizeConverter BACKGROUND_SIZE_CONVERTER =
  40             new BackgroundSizeConverter();
  41 
  42     public static BackgroundSizeConverter getInstance() {
  43         return BACKGROUND_SIZE_CONVERTER;
  44     }
  45 
  46     // Disallow instantiation
  47     private BackgroundSizeConverter() { }
  48 
  49     @Override
  50     public BackgroundSize convert(ParsedValue<ParsedValue[], BackgroundSize> value, Font font) {
  51         ParsedValue[] values = value.getValue();
  52 
  53         // A Size that is null represents that we are "auto" for that dimension
  54         final Size wSize = (values[0] != null)
  55                 ? ((ParsedValue<?, Size>) values[0]).convert(font) : null;
  56         final Size hSize = (values[1] != null)
  57                 ? ((ParsedValue<?, Size>) values[1]).convert(font) : null;
  58 




   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.scene.layout.region;
  27 
  28 import javafx.css.ParsedValue;
  29 import javafx.css.Size;
  30 import javafx.css.SizeUnits;
  31 import javafx.css.StyleConverter;
  32 import javafx.css.converter.BooleanConverter;
  33 import javafx.scene.layout.BackgroundSize;
  34 import javafx.scene.text.Font;
  35 
  36 /**
  37  */
  38 public final class BackgroundSizeConverter  extends StyleConverter<ParsedValue[], BackgroundSize> {
  39     private static final BackgroundSizeConverter BACKGROUND_SIZE_CONVERTER =
  40             new BackgroundSizeConverter();
  41 
  42     public static BackgroundSizeConverter getInstance() {
  43         return BACKGROUND_SIZE_CONVERTER;
  44     }
  45 
  46     // Disallow instantiation
  47     private BackgroundSizeConverter() { }
  48 
  49     @Override
  50     public BackgroundSize convert(ParsedValue<ParsedValue[], BackgroundSize> value, Font font) {
  51         ParsedValue[] values = value.getValue();
  52 
  53         // A Size that is null represents that we are "auto" for that dimension
  54         final Size wSize = (values[0] != null)
  55                 ? ((ParsedValue<?, Size>) values[0]).convert(font) : null;
  56         final Size hSize = (values[1] != null)
  57                 ? ((ParsedValue<?, Size>) values[1]).convert(font) : null;
  58