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

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


   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.scene.layout.region;
  27 
  28 import com.sun.javafx.css.StyleConverterImpl;
  29 import javafx.css.ParsedValue;

  30 import javafx.scene.layout.BackgroundPosition;
  31 import javafx.scene.text.Font;
  32 
  33 /**
  34  * background-position: <bg-position>
  35  * where <bg-position> = [
  36  *   [ [ <size> | left | center | right ] [ <size> | top | center | bottom ]? ]
  37  *   | [ [ center | [ left | right ] <size>? ] || [ center | [ top | bottom ] <size>? ]
  38  * ]
  39  * @see <a href="http://www.w3.org/TR/css3-background/#the-background-position">background-position</a>
  40  */
  41 public final class LayeredBackgroundPositionConverter extends StyleConverterImpl<ParsedValue<ParsedValue[], BackgroundPosition>[], BackgroundPosition[]> {
  42     private static final LayeredBackgroundPositionConverter LAYERED_BACKGROUND_POSITION_CONVERTER =
  43             new LayeredBackgroundPositionConverter();
  44 
  45     public static LayeredBackgroundPositionConverter getInstance() {
  46         return LAYERED_BACKGROUND_POSITION_CONVERTER;
  47     }
  48 
  49     private LayeredBackgroundPositionConverter() {
  50         super();
  51     }
  52 
  53     @Override
  54     public BackgroundPosition[] convert(ParsedValue<ParsedValue<ParsedValue[], BackgroundPosition>[], BackgroundPosition[]> value, Font font) {
  55         ParsedValue<ParsedValue[], BackgroundPosition>[] layers = value.getValue();
  56         BackgroundPosition[] positions = new BackgroundPosition[layers.length];
  57         for (int l = 0; l < layers.length; l++) {
  58             positions[l] = layers[l].convert(font);
  59         }
  60         return positions;
  61     }


   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.scene.layout.region;
  27 

  28 import javafx.css.ParsedValue;
  29 import javafx.css.StyleConverter;
  30 import javafx.scene.layout.BackgroundPosition;
  31 import javafx.scene.text.Font;
  32 
  33 /**
  34  * background-position: <bg-position>
  35  * where <bg-position> = [
  36  *   [ [ <size> | left | center | right ] [ <size> | top | center | bottom ]? ]
  37  *   | [ [ center | [ left | right ] <size>? ] || [ center | [ top | bottom ] <size>? ]
  38  * ]
  39  * @see <a href="http://www.w3.org/TR/css3-background/#the-background-position">background-position</a>
  40  */
  41 public final class LayeredBackgroundPositionConverter extends StyleConverter<ParsedValue<ParsedValue[], BackgroundPosition>[], BackgroundPosition[]> {
  42     private static final LayeredBackgroundPositionConverter LAYERED_BACKGROUND_POSITION_CONVERTER =
  43             new LayeredBackgroundPositionConverter();
  44 
  45     public static LayeredBackgroundPositionConverter getInstance() {
  46         return LAYERED_BACKGROUND_POSITION_CONVERTER;
  47     }
  48 
  49     private LayeredBackgroundPositionConverter() {
  50         super();
  51     }
  52 
  53     @Override
  54     public BackgroundPosition[] convert(ParsedValue<ParsedValue<ParsedValue[], BackgroundPosition>[], BackgroundPosition[]> value, Font font) {
  55         ParsedValue<ParsedValue[], BackgroundPosition>[] layers = value.getValue();
  56         BackgroundPosition[] positions = new BackgroundPosition[layers.length];
  57         for (int l = 0; l < layers.length; l++) {
  58             positions[l] = layers[l].convert(font);
  59         }
  60         return positions;
  61     }