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.javafx.scene.transform;
  27 
  28 import com.sun.javafx.geom.transform.Affine3D;
  29 import com.sun.javafx.geom.transform.BaseTransform;
  30 import javafx.scene.Node;
  31 import javafx.scene.transform.Transform;
  32 
  33 /**
  34  * Used to access internal methods of Transform.
  35  */
  36 public class TransformHelper {
  37 
  38     private static TransformAccessor transformAccessor;
  39 
  40     static {
  41         forceInit(Transform.class);
  42     }
  43 
  44     private TransformHelper() {
  45     }
  46 
  47     public static void add(Transform transform, Node node) {
  48         transformAccessor.add(transform, node);
  49     }
  50 
  51     public static void remove(Transform transform, Node node) {
  52         transformAccessor.remove(transform, node);
  53     }
  54 
  55     public static void apply(Transform transform, Affine3D affine3D) {
  56         transformAccessor.apply(transform, affine3D);
  57     }
  58 
  59     public static BaseTransform derive(Transform transform, BaseTransform baseTransform) {
  60         return transformAccessor.derive(transform, baseTransform);
  61     }
  62 
  63     public static Transform createImmutableTransform() {
  64         return transformAccessor.createImmutableTransform();
  65     }
  66 
  67     public static Transform createImmutableTransform(
  68             double mxx, double mxy, double mxz, double tx,
  69             double myx, double myy, double myz, double ty,
  70             double mzx, double mzy, double mzz, double tz) {
  71         return transformAccessor.createImmutableTransform(mxx, mxy, mxz, tx,
  72                 myx, myy, myz, ty, mzx, mzy, mzz, tz);
  73     }
  74 
  75     public static Transform createImmutableTransform(Transform transform,
  76             double mxx, double mxy, double mxz, double tx,
  77             double myx, double myy, double myz, double ty,
  78             double mzx, double mzy, double mzz, double tz) {
  79         return transformAccessor.createImmutableTransform(transform, mxx, mxy, mxz, tx,
  80                 myx, myy, myz, ty, mzx, mzy, mzz, tz);
  81     }
  82 
  83     public static Transform createImmutableTransform(Transform transform,
  84             Transform left, Transform right) {
  85         return transformAccessor.createImmutableTransform(transform, left, right);
  86     }
  87 
  88     public static void setTransformAccessor(final TransformAccessor newAccessor) {
  89         if (transformAccessor != null) {
  90             throw new IllegalStateException();
  91         }
  92 
  93         transformAccessor = newAccessor;
  94     }
  95 
  96     public interface TransformAccessor {
  97 
  98         void add(Transform transform, Node node);
  99 
 100         void remove(Transform transform, Node node);
 101 
 102         void apply(Transform transform, Affine3D affine3D);
 103 
 104         BaseTransform derive(Transform transform, BaseTransform baseTransform);
 105 
 106         Transform createImmutableTransform();
 107 
 108         Transform createImmutableTransform(double mxx, double mxy, double mxz, double tx,
 109                 double myx, double myy, double myz, double ty,
 110                 double mzx, double mzy, double mzz, double tz);
 111 
 112         Transform createImmutableTransform(Transform transform,
 113                 double mxx, double mxy, double mxz, double tx,
 114                 double myx, double myy, double myz, double ty,
 115                 double mzx, double mzy, double mzz, double tz);
 116 
 117         Transform createImmutableTransform(Transform transform,
 118                 Transform left, Transform right);
 119     }
 120 
 121     private static void forceInit(final Class<?> classToInit) {
 122         try {
 123             Class.forName(classToInit.getName(), true,
 124                     classToInit.getClassLoader());
 125         } catch (final ClassNotFoundException e) {
 126             throw new AssertionError(e);  // Can't happen
 127         }
 128     }
 129 
 130 }