1 /*
   2  * Copyright (c) 2016, 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.scenario.effect;
  27 
  28 import com.sun.javafx.geom.BaseBounds;
  29 import com.sun.javafx.geom.transform.BaseTransform;
  30 import com.sun.javafx.scene.BoundsAccessor;
  31 import javafx.beans.property.IntegerProperty;
  32 import javafx.scene.Node;
  33 import javafx.scene.effect.Blend;
  34 import javafx.scene.effect.BlendMode;
  35 
  36 /**
  37  * Used to access internal methods of javafx.scene.effect.Effect.
  38  */
  39 public class EffectHelper {
  40 
  41     private static EffectAccessor effectAccessor;
  42 
  43     static {
  44         forceInit(javafx.scene.effect.Effect.class);
  45     }
  46 
  47     private EffectHelper() {
  48     }
  49 
  50     public static Effect getPeer(javafx.scene.effect.Effect effect) {
  51         return effectAccessor.getPeer(effect);
  52     }
  53 
  54     public static void sync(javafx.scene.effect.Effect effect) {
  55         effectAccessor.sync(effect);
  56     }
  57 
  58     public static IntegerProperty effectDirtyProperty(javafx.scene.effect.Effect effect) {
  59         return effectAccessor.effectDirtyProperty(effect);
  60     }
  61 
  62     public static boolean isEffectDirty(javafx.scene.effect.Effect effect) {
  63         return effectAccessor.isEffectDirty(effect);
  64     }
  65 
  66     public static BaseBounds getBounds(javafx.scene.effect.Effect effect,
  67             BaseBounds bounds, BaseTransform tx, Node node, BoundsAccessor boundsAccessor) {
  68         return effectAccessor.getBounds(effect, bounds, tx, node, boundsAccessor);
  69     }
  70 
  71     public static javafx.scene.effect.Effect copy(javafx.scene.effect.Effect effect) {
  72         return effectAccessor.copy(effect);
  73     }
  74 
  75     public static com.sun.scenario.effect.Blend.Mode getToolkitBlendMode(BlendMode mode) {
  76         return effectAccessor.getToolkitBlendMode(mode);
  77     }
  78 
  79     public static void setEffectAccessor(final EffectAccessor newAccessor) {
  80         if (effectAccessor != null) {
  81             throw new IllegalStateException();
  82         }
  83 
  84         effectAccessor = newAccessor;
  85     }
  86 
  87     public interface EffectAccessor {
  88         Effect getPeer(javafx.scene.effect.Effect effect);
  89         void sync(javafx.scene.effect.Effect effect);
  90         IntegerProperty effectDirtyProperty(javafx.scene.effect.Effect effect);
  91         boolean isEffectDirty(javafx.scene.effect.Effect effect);
  92         BaseBounds getBounds(javafx.scene.effect.Effect effect, BaseBounds bounds,
  93                 BaseTransform tx, Node node, BoundsAccessor boundsAccessor);
  94         javafx.scene.effect.Effect copy(javafx.scene.effect.Effect effect);
  95         com.sun.scenario.effect.Blend.Mode getToolkitBlendMode(javafx.scene.effect.BlendMode mode);
  96     }
  97 
  98     private static void forceInit(final Class<?> classToInit) {
  99         try {
 100             Class.forName(classToInit.getName(), true,
 101                     classToInit.getClassLoader());
 102         } catch (final ClassNotFoundException e) {
 103             throw new AssertionError(e);  // Can't happen
 104         }
 105     }
 106 
 107 }