1 /* 2 * HomeMaterial.java 19 oct. 2012 3 * 4 * Sweet Home 3D, Copyright (c) 2012 Emmanuel PUYBARET / eTeks <info@eteks.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 package com.eteks.sweethome3d.model; 21 22 import java.io.Serializable; 23 24 /** 25 * The color and other properties of a material. 26 * @since 4.0 27 * @author Emmanuel Puybaret 28 */ 29 public class HomeMaterial implements Serializable { 30 private static final long serialVersionUID = 1L; 31 32 private final String name; 33 private final String key; 34 private final Integer color; 35 private final HomeTexture texture; 36 private final Float shininess; 37 38 /** 39 * Creates a material instance from parameters. 40 * @since 4.0 41 */ HomeMaterial(String name, Integer color, HomeTexture texture, Float shininess)42 public HomeMaterial(String name, Integer color, HomeTexture texture, Float shininess) { 43 this(name, null, color, texture, shininess); 44 } 45 46 /** 47 * Creates a material instance from parameters. 48 * @since 5.3 49 */ HomeMaterial(String name, String key, Integer color, HomeTexture texture, Float shininess)50 public HomeMaterial(String name, String key, Integer color, HomeTexture texture, Float shininess) { 51 this.name = name; 52 this.key = key; 53 this.color = color; 54 this.texture = texture; 55 this.shininess = shininess; 56 } 57 58 /** 59 * Returns the name of this material. 60 * @return the name of the material or <code>null</code> if material has no name. 61 * @since 4.0 62 */ getName()63 public String getName() { 64 return this.name; 65 } 66 67 /** 68 * Returns the key of this material. If not <code>null</code>, this key should be used 69 * as the unique identifier to find this material among the ones available on a model, 70 * rather than the name of this material. 71 * @return the key of the material or <code>null</code> if material has no key. 72 * @since 5.3 73 */ getKey()74 public String getKey() { 75 return this.key; 76 } 77 78 /** 79 * Returns the color of this material. 80 * @return the color of the material as RGB code or <code>null</code> if material color is unchanged. 81 * @since 4.0 82 */ getColor()83 public Integer getColor() { 84 return this.color; 85 } 86 87 /** 88 * Returns the texture of this material. 89 * @return the texture of the material or <code>null</code> if material texture is unchanged. 90 * @since 4.0 91 */ getTexture()92 public HomeTexture getTexture() { 93 return this.texture; 94 } 95 96 /** 97 * Returns the shininess of this material. 98 * @return a value between 0 (matt) and 1 (very shiny) or <code>null</code> if material shininess is unchanged. 99 * @since 4.0 100 */ getShininess()101 public Float getShininess() { 102 return this.shininess; 103 } 104 105 /** 106 * Returns <code>true</code> if this material is equal to <code>object</code>. 107 * @since 6.0 108 */ 109 @Override equals(Object object)110 public boolean equals(Object object) { 111 if (object instanceof HomeMaterial) { 112 HomeMaterial material = (HomeMaterial)object; 113 return (material.name == this.name 114 || (material.name != null && material.name.equals(this.name))) 115 && (material.key == this.key 116 || (material.key != null && material.key.equals(this.name))) 117 && (material.color == this.color 118 || (material.color != null && material.color.equals(this.color))) 119 && (material.texture == this.texture 120 || (material.texture != null && material.texture.equals(this.texture))) 121 && (material.shininess == this.shininess 122 || (material.shininess != null && material.shininess.equals(this.shininess))); 123 } 124 return false; 125 } 126 127 /** 128 * Returns a hash code for this material. 129 * @since 6.0 130 */ 131 @Override hashCode()132 public int hashCode() { 133 int hashCode = 0; 134 if (this.name != null) { 135 hashCode += this.name.hashCode(); 136 } 137 if (this.key != null) { 138 hashCode += this.key.hashCode(); 139 } 140 if (this.color != null) { 141 hashCode += this.color.hashCode(); 142 } 143 if (this.texture != null) { 144 hashCode += this.texture.hashCode(); 145 } 146 if (this.shininess != null) { 147 hashCode += this.shininess.hashCode(); 148 } 149 return hashCode; 150 } 151 } 152