1 /* 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. 3 * All rights reserved. Use is subject to license terms. 4 * 5 * This file is available and licensed under the following license: 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the distribution. 16 * - Neither the name of Oracle Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package com.oracle.javafx.scenebuilder.kit.editor.panel.content.driver.resizer; 33 34 import com.oracle.javafx.scenebuilder.kit.metadata.util.PropertyName; 35 import com.oracle.javafx.scenebuilder.kit.util.MathUtils; 36 import java.util.ArrayList; 37 import java.util.HashMap; 38 import java.util.List; 39 import java.util.Map; 40 import javafx.geometry.BoundingBox; 41 import javafx.geometry.Bounds; 42 import javafx.scene.SubScene; 43 44 /** 45 * 46 * 47 */ 48 public class SubSceneResizer extends AbstractResizer<SubScene> { 49 50 private final double originalWidth; 51 private final double originalHeight; 52 private final PropertyName widthName = new PropertyName("width"); //NOI18N 53 private final PropertyName heightName = new PropertyName("height"); //NOI18N 54 private final List<PropertyName> propertyNames = new ArrayList<>(); 55 56 public SubSceneResizer(SubScene sceneGraphObject) { 57 super(sceneGraphObject); 58 originalWidth = sceneGraphObject.getWidth(); 59 originalHeight = sceneGraphObject.getHeight(); 60 propertyNames.add(widthName); 61 propertyNames.add(heightName); 62 } 63 64 /* 65 * AbstractResizer 66 */ 67 68 @Override 69 public final Bounds computeBounds(double width, double height) { 70 return new BoundingBox(0, 0, Math.round(width), Math.round(height)); 71 } 72 73 @Override 74 public Feature getFeature() { 75 return Feature.FREE; 76 } 77 78 @Override 79 public void changeWidth(double w) { 80 sceneGraphObject.setWidth(Math.round(w)); 81 } 82 83 @Override 84 public void changeHeight(double h) { 85 sceneGraphObject.setHeight(Math.round(h)); 86 } 87 88 @Override 89 public void revertToOriginalSize() { 90 sceneGraphObject.setWidth(originalWidth); 91 sceneGraphObject.setHeight(originalHeight); 92 } 93 94 @Override 95 public List<PropertyName> getPropertyNames() { 96 return propertyNames; 97 } 98 99 @Override 100 public Object getValue(PropertyName propertyName) { 101 assert propertyName != null; 102 assert propertyNames.contains(propertyName); 103 104 final Object result; 105 if (propertyName.equals(widthName)) { 106 result = sceneGraphObject.getWidth(); 107 } else if (propertyName.equals(heightName)) { 108 result = sceneGraphObject.getHeight(); 109 } else { 110 // Emergency code 111 result = null; 112 } 113 114 return result; 115 } 116 117 @Override 118 public Map<PropertyName, Object> getChangeMap() { 119 final Map<PropertyName, Object> result = new HashMap<>(); 120 if (MathUtils.equals(sceneGraphObject.getWidth(), originalWidth) == false) { 121 result.put(widthName, sceneGraphObject.getWidth()); 122 } 123 if (MathUtils.equals(sceneGraphObject.getHeight(), originalHeight) == false) { 124 result.put(heightName, sceneGraphObject.getHeight()); 125 } 126 return result; 127 } 128 129 }