1 /*
   2  * Copyright (c) 2011, 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 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     }
 110 }