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.hierarchy; 33 34 import com.oracle.javafx.scenebuilder.kit.editor.i18n.I18N; 35 import com.oracle.javafx.scenebuilder.kit.editor.images.ImageUtils; 36 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject; 37 import com.oracle.javafx.scenebuilder.kit.metadata.util.DesignHierarchyMask; 38 import com.oracle.javafx.scenebuilder.kit.metadata.util.DesignHierarchyMask.Accessory; 39 import java.net.URL; 40 import java.util.Locale; 41 import java.util.Objects; 42 import javafx.scene.image.Image; 43 44 /** 45 * Object representing the data contained within the hierarchy TreeItems for the 46 * BorderPane top/right/bottom/left/center properties. 47 * 48 * @treatAsPrivate 49 */ 50 public class HierarchyItemBorderPane extends HierarchyItem { 51 52 private final Accessory position; 53 // The accessory owner. Used for the equals method. 54 private final DesignHierarchyMask owner; 55 56 /** 57 * Creates a hierarchy item. 58 * 59 * @param owner The accessory owner 60 * @param fxomObject The FX object represented by this item 61 * @param position The position of the FX object within the BorderPane 62 */ 63 public HierarchyItemBorderPane( 64 final DesignHierarchyMask owner, 65 final FXOMObject fxomObject, 66 final Accessory position) { 67 assert owner != null; 68 this.owner = owner; 69 // fxomObject can be null for place holder items 70 this.mask = fxomObject == null ? null : new DesignHierarchyMask(fxomObject); 71 this.position = position; 72 } 73 74 @Override 75 public boolean equals(Object obj) { 76 if (obj == null) { 77 return false; 78 } 79 if (getClass() != obj.getClass()) { 80 return false; 81 } 82 final HierarchyItemBorderPane item = (HierarchyItemBorderPane) obj; 83 if (!isEmpty()) { 84 // If the place holder is not empty, we compare the fxom object 85 assert getFxomObject() != null; 86 return getFxomObject().equals(item.getFxomObject()); 87 } else { 88 // If the place holder is empty, we compare the position + owner 89 return getOwner().equals(item.getOwner()) 90 && getPosition().equals(item.getPosition()); 91 } 92 } 93 94 @Override 95 public int hashCode() { 96 int hash = 7; 97 hash = 37 * hash + Objects.hashCode(this.mask); 98 hash = 37 * hash + Objects.hashCode(this.owner); 99 hash = 37 * hash + Objects.hashCode(this.position); 100 return hash; 101 } 102 103 @Override 104 public boolean isPlaceHolder() { 105 return true; 106 } 107 108 @Override 109 public boolean isEmpty() { 110 return mask == null; 111 } 112 113 /** 114 * Returns the DesignHierarchyMask owner of this accessory. Cannot be null. 115 * 116 * @return the DesignHierarchyMask owner 117 */ 118 public DesignHierarchyMask getOwner() { 119 return owner; 120 } 121 122 /** 123 * Returns the BorderPane position represented by this item. 124 * 125 * @return the BorderPane position represented by this item. 126 */ 127 public Accessory getPosition() { 128 return this.position; 129 } 130 131 @Override 132 public Image getPlaceHolderImage() { 133 return ImageUtils.getNodeIcon("BorderPane-" + position.name().toLowerCase(Locale.ROOT) + ".png"); //NOI18N 134 } 135 136 @Override 137 public String getPlaceHolderInfo() { 138 return (mask != null ? null : I18N.getString("hierarchy.placeholder.insert") + position.name().toUpperCase(Locale.getDefault())); 139 } 140 141 @Override 142 public Image getClassNameIcon() { 143 return (mask == null ? null : mask.getClassNameIcon()); 144 } 145 146 @Override 147 public URL getClassNameIconURL() { 148 return (mask == null ? null : mask.getClassNameIconURL()); 149 } 150 151 @Override 152 public String getClassNameInfo() { 153 return (mask == null ? null : mask.getClassNameInfo()); 154 } 155 }