1 /*
   2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 package com.oracle.javafx.scenebuilder.kit.metadata.property.value;
  33 
  34 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument;
  35 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
  36 import com.oracle.javafx.scenebuilder.kit.metadata.util.InspectorPath;
  37 import com.oracle.javafx.scenebuilder.kit.metadata.util.PropertyName;
  38 import com.oracle.javafx.scenebuilder.kit.util.MathUtils;
  39 import java.util.Objects;
  40 import javafx.geometry.VPos;
  41 import javafx.scene.layout.Priority;
  42 import javafx.scene.layout.RowConstraints;
  43 
  44 /**
  45  *
  46  */
  47 public class RowConstraintsPropertyMetadata extends ComplexPropertyMetadata<RowConstraints> {
  48 
  49     private static final RowConstraints DEFAULT = new RowConstraints();
  50 
  51     private final BooleanPropertyMetadata fillHeightMetadata
  52             = new BooleanPropertyMetadata(new PropertyName("fillHeight"),
  53                     true, DEFAULT.isFillHeight(), InspectorPath.UNUSED);
  54     private final DoublePropertyMetadata maxHeightMetadata
  55             = new DoublePropertyMetadata(new PropertyName("maxHeight"),
  56                     DoublePropertyMetadata.DoubleKind.USE_COMPUTED_SIZE, true,
  57                     DEFAULT.getMaxHeight(), InspectorPath.UNUSED);
  58     private final DoublePropertyMetadata minHeightMetadata
  59             = new DoublePropertyMetadata(new PropertyName("minHeight"),
  60             DoublePropertyMetadata.DoubleKind.USE_COMPUTED_SIZE, true,
  61                     DEFAULT.getMinHeight(), InspectorPath.UNUSED);
  62     private final DoublePropertyMetadata percentHeightMetadata
  63             = new DoublePropertyMetadata(new PropertyName("percentHeight"),
  64             DoublePropertyMetadata.DoubleKind.PERCENTAGE, true,
  65                     DEFAULT.getPercentHeight(), InspectorPath.UNUSED);
  66     private final DoublePropertyMetadata prefHeightMetadata
  67             = new DoublePropertyMetadata(new PropertyName("prefHeight"),
  68             DoublePropertyMetadata.DoubleKind.USE_PREF_SIZE, true,
  69                     DEFAULT.getPrefHeight(), InspectorPath.UNUSED);
  70     private final EnumerationPropertyMetadata valignmentMetadata
  71             = new EnumerationPropertyMetadata(new PropertyName("valignment"),
  72             VPos.class, EnumerationPropertyMetadata.EQUIV_INHERITED, true, InspectorPath.UNUSED);
  73     private final EnumerationPropertyMetadata vgrowMetadata
  74             = new EnumerationPropertyMetadata(new PropertyName("vgrow"),
  75             Priority.class, EnumerationPropertyMetadata.EQUIV_INHERITED, true, InspectorPath.UNUSED);
  76 
  77     public RowConstraintsPropertyMetadata(PropertyName name, boolean readWrite,
  78             RowConstraints defaultValue, InspectorPath inspectorPath) {
  79         super(name, RowConstraints.class, readWrite, defaultValue, inspectorPath);
  80     }
  81 
  82     /*
  83      * Utility
  84      */
  85 
  86     public static boolean equals(RowConstraints r1, RowConstraints r2) {
  87         assert r1 != null;
  88         assert r2 != null;
  89 
  90         final boolean result;
  91         if (r1 == r2) {
  92             result = true;
  93         } else {
  94             result = Objects.equals(r1.getValignment(),r2.getValignment())
  95                     && Objects.equals(r1.getVgrow(), r2.getVgrow())
  96                     && MathUtils.equals(r1.getMaxHeight(), r2.getMaxHeight())
  97                     && MathUtils.equals(r1.getMinHeight(), r2.getMinHeight())
  98                     && MathUtils.equals(r1.getPercentHeight(), r2.getPercentHeight())
  99                     && MathUtils.equals(r1.getPrefHeight(), r2.getPrefHeight());
 100         }
 101 
 102         return result;
 103     }
 104 
 105     /*
 106      * ComplexPropertyMetadata
 107      */
 108 
 109     @Override
 110     public FXOMInstance makeFxomInstanceFromValue(RowConstraints value, FXOMDocument fxomDocument) {
 111         final FXOMInstance result = new FXOMInstance(fxomDocument, getValueClass());
 112 
 113         fillHeightMetadata.setValue(result, value.isFillHeight());
 114         maxHeightMetadata.setValue(result, value.getMaxHeight());
 115         minHeightMetadata.setValue(result, value.getMinHeight());
 116         percentHeightMetadata.setValue(result, value.getPercentHeight());
 117         prefHeightMetadata.setValue(result, value.getPrefHeight());
 118 
 119         final VPos valignment = value.getValignment();
 120         if (valignment == null) {
 121             valignmentMetadata.setValue(result, valignmentMetadata.getDefaultValue());
 122         } else {
 123             valignmentMetadata.setValue(result, valignment.toString());
 124         }
 125         final Priority vgrow = value.getVgrow();
 126         if (vgrow == null) {
 127             vgrowMetadata.setValue(result, vgrowMetadata.getDefaultValue());
 128         } else {
 129             vgrowMetadata.setValue(result, vgrow.toString());
 130         }
 131 
 132         return result;
 133     }
 134 
 135 }