001/* 002 * $Id: RectangleReadOnly.java 4847 2011-05-05 19:46:13Z redlab_b $ 003 * 004 * This file is part of the iText (R) project. 005 * Copyright (c) 1998-2011 1T3XT BVBA 006 * Authors: Bruno Lowagie, Paulo Soares, et al. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Affero General Public License version 3 010 * as published by the Free Software Foundation with the addition of the 011 * following permission added to Section 15 as permitted in Section 7(a): 012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT, 013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 014 * 015 * This program is distributed in the hope that it will be useful, but 016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 017 * or FITNESS FOR A PARTICULAR PURPOSE. 018 * See the GNU Affero General Public License for more details. 019 * You should have received a copy of the GNU Affero General Public License 020 * along with this program; if not, see http://www.gnu.org/licenses or write to 021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 022 * Boston, MA, 02110-1301 USA, or download the license from the following URL: 023 * http://itextpdf.com/terms-of-use/ 024 * 025 * The interactive user interfaces in modified source and object code versions 026 * of this program must display Appropriate Legal Notices, as required under 027 * Section 5 of the GNU Affero General Public License. 028 * 029 * In accordance with Section 7(b) of the GNU Affero General Public License, 030 * a covered work must retain the producer line in every PDF that is created 031 * or manipulated using iText. 032 * 033 * You can be released from the requirements of the license by purchasing 034 * a commercial license. Buying such a license is mandatory as soon as you 035 * develop commercial activities involving the iText software without 036 * disclosing the source code of your own applications. 037 * These activities include: offering paid services to customers as an ASP, 038 * serving PDFs on the fly in a web application, shipping iText with a closed 039 * source product. 040 * 041 * For more information, please contact iText Software Corp. at this 042 * address: sales@itextpdf.com 043 */ 044package com.itextpdf.text; 045 046import com.itextpdf.text.error_messages.MessageLocalization; 047import com.itextpdf.text.BaseColor; 048 049/** 050 * A <CODE>RectangleReadOnly</CODE> is the representation of a geometric figure. 051 * It's the same as a <CODE>Rectangle</CODE> but immutable. 052 * Rectangles support constant width borders using 053 * {@link #setBorderWidth(float)}and {@link #setBorder(int)}. 054 * They also support borders that vary in width/color on each side using 055 * methods like {@link #setBorderWidthLeft(float)}or 056 * {@link #setBorderColorLeft(BaseColor)}. 057 * 058 * @see Element 059 * @since 2.1.2 060 */ 061 062public class RectangleReadOnly extends Rectangle { 063 064 // CONSTRUCTORS 065 066 /** 067 * Constructs a <CODE>RectangleReadOnly</CODE> -object. 068 * 069 * @param llx lower left x 070 * @param lly lower left y 071 * @param urx upper right x 072 * @param ury upper right y 073 */ 074 public RectangleReadOnly(final float llx, final float lly, final float urx, final float ury) { 075 super(llx, lly, urx, ury); 076 } 077 078 /** 079 * Constructs a <CODE>RectangleReadOnly</CODE> -object. 080 * 081 * @param llx lower left x 082 * @param lly lower left y 083 * @param urx upper right x 084 * @param ury upper right y 085 * @param rotation the rotation of the Rectangle (0, 90, 180, 270) 086 * @since iText 5.0.6 087 */ 088 public RectangleReadOnly(final float llx, final float lly, final float urx, final float ury, final int rotation) { 089 super(llx, lly, urx, ury); 090 super.setRotation(rotation); 091 } 092 093 /** 094 * Constructs a <CODE>RectangleReadOnly</CODE>-object starting from the origin 095 * (0, 0). 096 * 097 * @param urx upper right x 098 * @param ury upper right y 099 */ 100 public RectangleReadOnly(final float urx, final float ury) { 101 super(0, 0, urx, ury); 102 } 103 104 /** 105 * Constructs a <CODE>RectangleReadOnly</CODE>-object starting from the origin 106 * (0, 0) and with a specific rotation (valid values are 0, 90, 180, 270). 107 * 108 * @param urx upper right x 109 * @param ury upper right y 110 * @param rotation the rotation 111 * @since iText 5.0.6 112 */ 113 public RectangleReadOnly(final float urx, final float ury, final int rotation) { 114 super(0, 0, urx, ury); 115 super.setRotation(rotation); 116 } 117 118 /** 119 * Constructs a <CODE>RectangleReadOnly</CODE> -object. 120 * 121 * @param rect another <CODE>Rectangle</CODE> 122 */ 123 public RectangleReadOnly(final Rectangle rect) { 124 super(rect.llx, rect.lly, rect.urx, rect.ury); 125 super.cloneNonPositionParameters(rect); 126 } 127 128 /** 129 * Throws an error because of the read only nature of this object. 130 */ 131 private void throwReadOnlyError() { 132 throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("rectanglereadonly.this.rectangle.is.read.only")); 133 } 134 135 /** 136 * Sets the rotation of the rectangle. Valid values are 0, 90, 180, and 270. 137 * @param rotation the new rotation value 138 * @since iText 5.0.6 139 */ 140 @Override 141 public void setRotation(final int rotation) { 142 throwReadOnlyError(); 143 } 144 145 // OVERWRITE METHODS SETTING THE DIMENSIONS: 146 147 /** 148 * Sets the lower left x-coordinate. 149 * 150 * @param llx the new value 151 */ 152 @Override 153 public void setLeft(final float llx) { 154 throwReadOnlyError(); 155 } 156 157 /** 158 * Sets the upper right x-coordinate. 159 * 160 * @param urx the new value 161 */ 162 163 @Override 164 public void setRight(final float urx) { 165 throwReadOnlyError(); 166 } 167 168 /** 169 * Sets the upper right y-coordinate. 170 * 171 * @param ury the new value 172 */ 173 @Override 174 public void setTop(final float ury) { 175 throwReadOnlyError(); 176 } 177 178 /** 179 * Sets the lower left y-coordinate. 180 * 181 * @param lly the new value 182 */ 183 @Override 184 public void setBottom(final float lly) { 185 throwReadOnlyError(); 186 } 187 188 /** 189 * Normalizes the rectangle. 190 * Switches lower left with upper right if necessary. 191 */ 192 @Override 193 public void normalize() { 194 throwReadOnlyError(); 195 } 196 197 // OVERWRITE METHODS SETTING THE BACKGROUND COLOR: 198 199 /** 200 * Sets the backgroundcolor of the rectangle. 201 * 202 * @param value the new value 203 */ 204 @Override 205 public void setBackgroundColor(final BaseColor value) { 206 throwReadOnlyError(); 207 } 208 209 /** 210 * Sets the grayscale of the rectangle. 211 * 212 * @param value the new value 213 */ 214 @Override 215 public void setGrayFill(final float value) { 216 throwReadOnlyError(); 217 } 218 219 // OVERWRITE METHODS SETTING THE BORDER: 220 221 /** 222 * Enables/Disables the border on the specified sides. 223 * The border is specified as an integer bitwise combination of 224 * the constants: <CODE>LEFT, RIGHT, TOP, BOTTOM</CODE>. 225 * 226 * @see #enableBorderSide(int) 227 * @see #disableBorderSide(int) 228 * @param border the new value 229 */ 230 @Override 231 public void setBorder(final int border) { 232 throwReadOnlyError(); 233 } 234 235 /** 236 * Sets a parameter indicating if the rectangle has variable borders 237 * 238 * @param useVariableBorders indication if the rectangle has variable borders 239 */ 240 @Override 241 public void setUseVariableBorders(final boolean useVariableBorders) { 242 throwReadOnlyError(); 243 } 244 245 /** 246 * Enables the border on the specified side. 247 * 248 * @param side the side to enable. 249 * One of <CODE>LEFT, RIGHT, TOP, BOTTOM</CODE> 250 */ 251 @Override 252 public void enableBorderSide(final int side) { 253 throwReadOnlyError(); 254 } 255 256 /** 257 * Disables the border on the specified side. 258 * 259 * @param side the side to disable. 260 * One of <CODE>LEFT, RIGHT, TOP, BOTTOM</CODE> 261 */ 262 @Override 263 public void disableBorderSide(final int side) { 264 throwReadOnlyError(); 265 } 266 267 // OVERWRITE METHODS SETTING THE BORDER WIDTH: 268 269 /** 270 * Sets the borderwidth of the table. 271 * 272 * @param borderWidth the new value 273 */ 274 275 @Override 276 public void setBorderWidth(final float borderWidth) { 277 throwReadOnlyError(); 278 } 279 280 /** 281 * Sets the width of the left border 282 * 283 * @param borderWidthLeft a width 284 */ 285 @Override 286 public void setBorderWidthLeft(final float borderWidthLeft) { 287 throwReadOnlyError(); 288 } 289 290 /** 291 * Sets the width of the right border 292 * 293 * @param borderWidthRight a width 294 */ 295 @Override 296 public void setBorderWidthRight(final float borderWidthRight) { 297 throwReadOnlyError(); 298 } 299 300 /** 301 * Sets the width of the top border 302 * 303 * @param borderWidthTop a width 304 */ 305 @Override 306 public void setBorderWidthTop(final float borderWidthTop) { 307 throwReadOnlyError(); 308 } 309 310 /** 311 * Sets the width of the bottom border 312 * 313 * @param borderWidthBottom a width 314 */ 315 @Override 316 public void setBorderWidthBottom(final float borderWidthBottom) { 317 throwReadOnlyError(); 318 } 319 320 // METHODS TO GET/SET THE BORDER COLOR: 321 322 /** 323 * Sets the color of the border. 324 * 325 * @param borderColor a <CODE>BaseColor</CODE> 326 */ 327 328 @Override 329 public void setBorderColor(final BaseColor borderColor) { 330 throwReadOnlyError(); 331 } 332 333 /** 334 * Sets the color of the left border. 335 * 336 * @param borderColorLeft a <CODE>BaseColor</CODE> 337 */ 338 @Override 339 public void setBorderColorLeft(final BaseColor borderColorLeft) { 340 throwReadOnlyError(); 341 } 342 343 /** 344 * Sets the color of the right border 345 * 346 * @param borderColorRight a <CODE>BaseColor</CODE> 347 */ 348 @Override 349 public void setBorderColorRight(final BaseColor borderColorRight) { 350 throwReadOnlyError(); 351 } 352 353 /** 354 * Sets the color of the top border. 355 * 356 * @param borderColorTop a <CODE>BaseColor</CODE> 357 */ 358 @Override 359 public void setBorderColorTop(final BaseColor borderColorTop) { 360 throwReadOnlyError(); 361 } 362 363 /** 364 * Sets the color of the bottom border. 365 * 366 * @param borderColorBottom a <CODE>BaseColor</CODE> 367 */ 368 @Override 369 public void setBorderColorBottom(final BaseColor borderColorBottom) { 370 throwReadOnlyError(); 371 } 372 373 // SPECIAL METHODS: 374 375 /** 376 * Copies each of the parameters, except the position, from a 377 * <CODE>Rectangle</CODE> object 378 * 379 * @param rect <CODE>Rectangle</CODE> to copy from 380 */ 381 @Override 382 public void cloneNonPositionParameters(final Rectangle rect) { 383 throwReadOnlyError(); 384 } 385 386 /** 387 * Copies each of the parameters, except the position, from a 388 * <CODE>Rectangle</CODE> object if the value is set there. 389 * 390 * @param rect <CODE>Rectangle</CODE> to copy from 391 */ 392 @Override 393 public void softCloneNonPositionParameters(final Rectangle rect) { 394 throwReadOnlyError(); 395 } 396 397 /** 398 * @return String version of the most important rectangle properties 399 * @see java.lang.Object#toString() 400 */ 401 @Override 402 public String toString() { 403 StringBuffer buf = new StringBuffer("RectangleReadOnly: "); 404 buf.append(getWidth()); 405 buf.append('x'); 406 buf.append(getHeight()); 407 buf.append(" (rot: "); 408 buf.append(rotation); 409 buf.append(" degrees)"); 410 return buf.toString(); 411 } 412}