1 30 31 package com.jgoodies.forms.layout; 32 33 import java.awt.Container ; 34 import java.util.List ; 35 36 46 47 final class BoundedSize implements Size { 48 49 52 private final Size basis; 53 54 57 private Size lowerBound; 58 59 62 private Size upperBound; 63 64 65 67 76 BoundedSize(Size basis, Size lowerBound, Size upperBound) { 77 if (basis == null) 78 throw new NullPointerException ("The basis of a bounded size must not be null."); 79 this.basis = basis; 80 this.lowerBound = lowerBound; 81 this.upperBound = upperBound; 82 } 83 84 91 BoundedSize(Size basis) { 92 this(basis, null, null); 93 } 94 95 96 98 103 void setLowerBound(Size lowerBound) { 104 this.lowerBound = lowerBound; 105 } 106 107 112 void setUpperBound(Size upperBound) { 113 this.upperBound = upperBound; 114 } 115 116 118 127 public int maximumSize(Container container, 128 List components, 129 FormLayout.Measure minMeasure, 130 FormLayout.Measure prefMeasure, 131 FormLayout.Measure defaultMeasure) { 132 int size = basis.maximumSize(container, 133 components, 134 minMeasure, 135 prefMeasure, 136 defaultMeasure); 137 if (lowerBound != null) { 138 size = Math.max(size, lowerBound.maximumSize( 139 container, 140 components, 141 minMeasure, 142 prefMeasure, 143 defaultMeasure)); 144 } 145 if (upperBound != null) { 146 size = Math.min(size, upperBound.maximumSize( 147 container, 148 components, 149 minMeasure, 150 prefMeasure, 151 defaultMeasure)); 152 } 153 return size; 154 } 155 156 157 159 168 public boolean equals(Object o) { 169 if (!(o instanceof BoundedSize)) 170 return false; 171 BoundedSize size = (BoundedSize) o; 172 return basis.equals(size.basis) 173 && ( (lowerBound == null && size.lowerBound == null) 174 || (lowerBound != null && lowerBound.equals(size.lowerBound))) 175 && ( (upperBound == null && size.upperBound == null) 176 || (upperBound != null && upperBound.equals(size.upperBound))); 177 } 178 179 188 public int hashCode() { 189 int hashValue = basis.hashCode(); 190 if (lowerBound != null) { 191 hashValue = hashValue * 37 + lowerBound.hashCode(); 192 } 193 if (upperBound != null) { 194 hashValue = hashValue * 37 + upperBound.hashCode(); 195 } 196 return hashValue; 197 } 198 199 204 public String toString() { 205 if (lowerBound != null) { 206 if (upperBound == null) { 207 return "max(" + basis + ';' + lowerBound + ')'; 208 } else { 209 return "max(" + basis + ';' 210 + "min(" + lowerBound + ';' + upperBound + "))"; 211 } 212 } else if (upperBound != null) { 213 return "min(" + basis + ';' + upperBound + ')'; 214 } else { 215 return "bounded(" + basis + ')'; 216 } 217 } 218 219 220 } | Popular Tags |