< prev index next >

modules/graphics/src/test/java/test/javafx/scene/layout/MockResizable.java

Print this page




  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 test.javafx.scene.layout;
  27 
  28 import javafx.geometry.BoundingBox;
  29 import javafx.geometry.Bounds;
  30 import javafx.scene.Parent;
  31 
  32 import com.sun.javafx.scene.DirtyBits;
  33 import com.sun.javafx.scene.NodeHelper;


  34 
  35 
  36 public class MockResizable extends Parent {















  37     private double minWidth = 0;
  38     private double minHeight = 0;
  39     private double prefWidth;
  40     private double prefHeight;
  41     private double maxWidth = 5000;
  42     private double maxHeight = 5000;
  43     private double width;
  44     private double height;
  45 




  46     public MockResizable(double prefWidth, double prefHeight) {
  47         this.prefWidth = prefWidth;
  48         this.prefHeight = prefHeight;
  49     }
  50     public MockResizable(double minWidth, double minHeight, double prefWidth, double prefHeight, double maxWidth, double maxHeight) {
  51         this.minWidth = minWidth;
  52         this.minHeight = minHeight;
  53         this.prefWidth = prefWidth;
  54         this.prefHeight = prefHeight;
  55         this.maxWidth = maxWidth;
  56         this.maxHeight = maxHeight;
  57     }
  58     @Override public boolean isResizable() {
  59         return true;
  60     }
  61     public double getWidth() {
  62         return width;
  63     }
  64     public double getHeight() {
  65         return height;
  66     }
  67     @Override public void resize(double width, double height) {
  68         this.width = width;
  69         this.height = height;
  70         impl_layoutBoundsChanged();
  71         impl_geomChanged();
  72         NodeHelper.markDirty(this, DirtyBits.NODE_GEOMETRY);
  73         requestLayout();
  74     }
  75     @Override public double getBaselineOffset() {
  76         return Math.max(0, prefHeight - 10);
  77     }
  78     /**
  79      * The layout bounds of this region: {@code 0, 0  width x height}
  80      */
  81     @Override protected Bounds impl_computeLayoutBounds() {
  82         return new BoundingBox(0, 0, 0, width, height, 0);
  83     }
  84     /**
  85      * @treatAsPrivate implementation detail
  86      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
  87      */
  88     @Deprecated
  89     @Override protected void impl_notifyLayoutBoundsChanged() {
  90         // change in geometric bounds does not necessarily change layoutBounds
  91     }
  92     @Override public double minWidth(double height) {
  93         return minWidth;
  94     }
  95     @Override public double minHeight(double width) {
  96         return minHeight;
  97     }
  98     @Override public double prefWidth(double height) {
  99         return prefWidth;
 100     }
 101     @Override public double prefHeight(double width) {
 102         return prefHeight;
 103     }
 104     @Override public double maxWidth(double height) {
 105         return maxWidth;
 106     }
 107     @Override public double maxHeight(double width) {
 108         return maxHeight;
 109     }


  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 test.javafx.scene.layout;
  27 
  28 import javafx.geometry.BoundingBox;
  29 import javafx.geometry.Bounds;
  30 import javafx.scene.Parent;
  31 
  32 import com.sun.javafx.scene.DirtyBits;
  33 import com.sun.javafx.scene.NodeHelper;
  34 import javafx.scene.Node;
  35 import test.com.sun.javafx.scene.layout.MockResizableHelper;
  36 
  37 
  38 public class MockResizable extends Parent {
  39     static {
  40          // This is used by classes in different packages to get access to
  41          // private and package private methods.
  42         MockResizableHelper.setMockResizableAccessor(new MockResizableHelper.MockResizableAccessor() {
  43             @Override
  44             public Bounds doComputeLayoutBounds(Node node) {
  45                 return ((MockResizable) node).doComputeLayoutBounds();
  46             }
  47             @Override
  48             public void doNotifyLayoutBoundsChanged(Node node) {
  49                 ((MockResizable) node).doNotifyLayoutBoundsChanged();
  50             }
  51         });
  52     }
  53 
  54     private double minWidth = 0;
  55     private double minHeight = 0;
  56     private double prefWidth;
  57     private double prefHeight;
  58     private double maxWidth = 5000;
  59     private double maxHeight = 5000;
  60     private double width;
  61     private double height;
  62 
  63     {
  64         // To initialize the class helper at the begining each constructor of this class
  65         MockResizableHelper.initHelper(this);
  66     }
  67     public MockResizable(double prefWidth, double prefHeight) {
  68         this.prefWidth = prefWidth;
  69         this.prefHeight = prefHeight;
  70     }
  71     public MockResizable(double minWidth, double minHeight, double prefWidth, double prefHeight, double maxWidth, double maxHeight) {
  72         this.minWidth = minWidth;
  73         this.minHeight = minHeight;
  74         this.prefWidth = prefWidth;
  75         this.prefHeight = prefHeight;
  76         this.maxWidth = maxWidth;
  77         this.maxHeight = maxHeight;
  78     }
  79     @Override public boolean isResizable() {
  80         return true;
  81     }
  82     public double getWidth() {
  83         return width;
  84     }
  85     public double getHeight() {
  86         return height;
  87     }
  88     @Override public void resize(double width, double height) {
  89         this.width = width;
  90         this.height = height;
  91         NodeHelper.layoutBoundsChanged(this);
  92         NodeHelper.geomChanged(this);
  93         NodeHelper.markDirty(this, DirtyBits.NODE_GEOMETRY);
  94         requestLayout();
  95     }
  96     @Override public double getBaselineOffset() {
  97         return Math.max(0, prefHeight - 10);
  98     }
  99 
 100     private Bounds doComputeLayoutBounds() {


 101         return new BoundingBox(0, 0, 0, width, height, 0);
 102     }
 103 
 104     private void doNotifyLayoutBoundsChanged() {




 105         // change in geometric bounds does not necessarily change layoutBounds
 106     }
 107     @Override public double minWidth(double height) {
 108         return minWidth;
 109     }
 110     @Override public double minHeight(double width) {
 111         return minHeight;
 112     }
 113     @Override public double prefWidth(double height) {
 114         return prefWidth;
 115     }
 116     @Override public double prefHeight(double width) {
 117         return prefHeight;
 118     }
 119     @Override public double maxWidth(double height) {
 120         return maxWidth;
 121     }
 122     @Override public double maxHeight(double width) {
 123         return maxHeight;
 124     }
< prev index next >