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 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 } 125 }