Source Code Cross Referenced for Rectangle.java in  » PDF » pdf-itext » com » lowagie » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » pdf itext » com.lowagie.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $Id: Rectangle.java 2752 2007-05-15 14:58:33Z blowagie $
0003:         * $Name$
0004:         *
0005:         * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
0006:         *
0007:         * The contents of this file are subject to the Mozilla Public License Version 1.1
0008:         * (the "License"); you may not use this file except in compliance with the License.
0009:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
0010:         *
0011:         * Software distributed under the License is distributed on an "AS IS" basis,
0012:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0013:         * for the specific language governing rights and limitations under the License.
0014:         *
0015:         * The Original Code is 'iText, a free JAVA-PDF library'.
0016:         *
0017:         * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
0018:         * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
0019:         * All Rights Reserved.
0020:         * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
0021:         * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
0022:         *
0023:         * Contributor(s): all the names of the contributors are added in the source code
0024:         * where applicable.
0025:         *
0026:         * Alternatively, the contents of this file may be used under the terms of the
0027:         * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
0028:         * provisions of LGPL are applicable instead of those above.  If you wish to
0029:         * allow use of your version of this file only under the terms of the LGPL
0030:         * License and not to allow others to use your version of this file under
0031:         * the MPL, indicate your decision by deleting the provisions above and
0032:         * replace them with the notice and other provisions required by the LGPL.
0033:         * If you do not delete the provisions above, a recipient may use your version
0034:         * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
0035:         *
0036:         * This library is free software; you can redistribute it and/or modify it
0037:         * under the terms of the MPL as stated above or under the terms of the GNU
0038:         * Library General Public License as published by the Free Software Foundation;
0039:         * either version 2 of the License, or any later version.
0040:         *
0041:         * This library is distributed in the hope that it will be useful, but WITHOUT
0042:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
0043:         * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
0044:         * details.
0045:         *
0046:         * If you didn't download this code from the following link, you should check if
0047:         * you aren't using an obsolete version:
0048:         * http://www.lowagie.com/iText/
0049:         */
0050:
0051:        package com.lowagie.text;
0052:
0053:        import java.awt.Color;
0054:        import java.util.ArrayList;
0055:
0056:        import com.lowagie.text.pdf.GrayColor;
0057:
0058:        /**
0059:         * A <CODE>Rectangle</CODE> is the representation of a geometric figure.
0060:         * 
0061:         * Rectangles support constant width borders using
0062:         * {@link #setBorderWidth(float)}and {@link #setBorder(int)}. They also
0063:         * support borders that vary in width/color on each side using methods like
0064:         * {@link #setBorderWidthLeft(float)}or
0065:         * {@link #setBorderColorLeft(java.awt.Color)}.
0066:         * 
0067:         * @see Element
0068:         * @see Table
0069:         * @see Cell
0070:         * @see HeaderFooter
0071:         */
0072:
0073:        public class Rectangle implements  Element {
0074:
0075:            // static final membervariables (concerning the presence of borders)
0076:
0077:            /** This is the value that will be used as <VAR>undefined </VAR>. */
0078:            public static final int UNDEFINED = -1;
0079:
0080:            /** This represents one side of the border of the <CODE>Rectangle</CODE>. */
0081:            public static final int TOP = 1;
0082:
0083:            /** This represents one side of the border of the <CODE>Rectangle</CODE>. */
0084:            public static final int BOTTOM = 2;
0085:
0086:            /** This represents one side of the border of the <CODE>Rectangle</CODE>. */
0087:            public static final int LEFT = 4;
0088:
0089:            /** This represents one side of the border of the <CODE>Rectangle</CODE>. */
0090:            public static final int RIGHT = 8;
0091:
0092:            /** This represents a rectangle without borders. */
0093:            public static final int NO_BORDER = 0;
0094:
0095:            /** This represents a type of border. */
0096:            public static final int BOX = TOP + BOTTOM + LEFT + RIGHT;
0097:
0098:            // membervariables
0099:
0100:            /** the lower left x-coordinate. */
0101:            protected float llx;
0102:
0103:            /** the lower left y-coordinate. */
0104:            protected float lly;
0105:
0106:            /** the upper right x-coordinate. */
0107:            protected float urx;
0108:
0109:            /** the upper right y-coordinate. */
0110:            protected float ury;
0111:
0112:            /** The rotation of the Rectangle */
0113:            protected int rotation = 0;
0114:
0115:            /** This represents the status of the 4 sides of the rectangle. */
0116:            protected int border = UNDEFINED;
0117:
0118:            /** This is the width of the border around this rectangle. */
0119:            protected float borderWidth = UNDEFINED;
0120:
0121:            /** The color of the border of this rectangle. */
0122:            protected Color borderColor = null;
0123:
0124:            /** This is the color of the background of this rectangle. */
0125:            protected Color backgroundColor = null;
0126:
0127:            /** Whether variable width/color borders are used. */
0128:            protected boolean useVariableBorders = false;
0129:
0130:            /** The width of the left border of this rectangle. */
0131:            protected float borderWidthLeft = UNDEFINED;
0132:
0133:            /** The width of the right border of this rectangle. */
0134:            protected float borderWidthRight = UNDEFINED;
0135:
0136:            /** The width of the top border of this rectangle. */
0137:            protected float borderWidthTop = UNDEFINED;
0138:
0139:            /** The width of the bottom border of this rectangle. */
0140:            protected float borderWidthBottom = UNDEFINED;
0141:
0142:            /** The color of the left border of this rectangle. */
0143:            protected Color borderColorLeft = null;
0144:
0145:            /** The color of the right border of this rectangle. */
0146:            protected Color borderColorRight = null;
0147:
0148:            /** The color of the top border of this rectangle. */
0149:            protected Color borderColorTop = null;
0150:
0151:            /** The color of the bottom border of this rectangle. */
0152:            protected Color borderColorBottom = null;
0153:
0154:            // constructors
0155:
0156:            /**
0157:             * Constructs a <CODE>Rectangle</CODE> -object.
0158:             * 
0159:             * @param llx
0160:             *            lower left x
0161:             * @param lly
0162:             *            lower left y
0163:             * @param urx
0164:             *            upper right x
0165:             * @param ury
0166:             *            upper right y
0167:             */
0168:            public Rectangle(float llx, float lly, float urx, float ury) {
0169:                this .llx = llx;
0170:                this .lly = lly;
0171:                this .urx = urx;
0172:                this .ury = ury;
0173:            }
0174:
0175:            /**
0176:             * Constructs a <CODE>Rectangle</CODE> -object starting from the origin
0177:             * (0, 0).
0178:             * 
0179:             * @param urx
0180:             *            upper right x
0181:             * @param ury
0182:             *            upper right y
0183:             */
0184:            public Rectangle(float urx, float ury) {
0185:                this (0, 0, urx, ury);
0186:            }
0187:
0188:            /**
0189:             * Constructs a <CODE>Rectangle</CODE> -object.
0190:             * 
0191:             * @param rect
0192:             *            another <CODE>Rectangle</CODE>
0193:             */
0194:            public Rectangle(Rectangle rect) {
0195:                this (rect.llx, rect.lly, rect.urx, rect.ury);
0196:                cloneNonPositionParameters(rect);
0197:            }
0198:
0199:            // implementation of the Element interface
0200:
0201:            /**
0202:             * Processes the element by adding it (or the different parts) to an <CODE>
0203:             * ElementListener</CODE>.
0204:             * 
0205:             * @param listener
0206:             *            an <CODE>ElementListener</CODE>
0207:             * @return <CODE>true</CODE> if the element was processed successfully
0208:             */
0209:            public boolean process(ElementListener listener) {
0210:                try {
0211:                    return listener.add(this );
0212:                } catch (DocumentException de) {
0213:                    return false;
0214:                }
0215:            }
0216:
0217:            /**
0218:             * Gets the type of the text element.
0219:             * 
0220:             * @return a type
0221:             */
0222:            public int type() {
0223:                return Element.RECTANGLE;
0224:            }
0225:
0226:            /**
0227:             * Gets all the chunks in this element.
0228:             * 
0229:             * @return an <CODE>ArrayList</CODE>
0230:             */
0231:            public ArrayList getChunks() {
0232:                return new ArrayList();
0233:            }
0234:
0235:            // methods to get/set the dimensions
0236:
0237:            /**
0238:             * Sets the lower left x-coordinate.
0239:             * 
0240:             * @param value
0241:             *            the new value
0242:             */
0243:            public void setLeft(float value) {
0244:                llx = value;
0245:            }
0246:
0247:            /**
0248:             * Returns the lower left x-coordinate.
0249:             * 
0250:             * @return the lower left x-coordinate
0251:             */
0252:            public float getLeft() {
0253:                return llx;
0254:            }
0255:
0256:            /**
0257:             * Returns the lower left x-coordinate, considering a given margin.
0258:             * 
0259:             * @param margin
0260:             *            a margin
0261:             * @return the lower left x-coordinate
0262:             */
0263:            public float getLeft(float margin) {
0264:                return llx + margin;
0265:            }
0266:
0267:            /**
0268:             * Sets the upper right x-coordinate.
0269:             * 
0270:             * @param value
0271:             *            the new value
0272:             */
0273:
0274:            public void setRight(float value) {
0275:                urx = value;
0276:            }
0277:
0278:            /**
0279:             * Returns the upper right x-coordinate.
0280:             * 
0281:             * @return the upper right x-coordinate
0282:             */
0283:            public float getRight() {
0284:                return urx;
0285:            }
0286:
0287:            /**
0288:             * Returns the upper right x-coordinate, considering a given margin.
0289:             * 
0290:             * @param margin
0291:             *            a margin
0292:             * @return the upper right x-coordinate
0293:             */
0294:            public float getRight(float margin) {
0295:                return urx - margin;
0296:            }
0297:
0298:            /**
0299:             * Returns the width of the rectangle.
0300:             * 
0301:             * @return a width
0302:             */
0303:            public float getWidth() {
0304:                return urx - llx;
0305:            }
0306:
0307:            /**
0308:             * Sets the upper right y-coordinate.
0309:             * 
0310:             * @param value
0311:             *            the new value
0312:             */
0313:            public void setTop(float value) {
0314:                ury = value;
0315:            }
0316:
0317:            /**
0318:             * Returns the upper right y-coordinate.
0319:             * 
0320:             * @return the upper right y-coordinate
0321:             */
0322:            public float getTop() {
0323:                return ury;
0324:            }
0325:
0326:            /**
0327:             * Returns the upper right y-coordinate, considering a given margin.
0328:             * 
0329:             * @param margin
0330:             *            a margin
0331:             * @return the upper right y-coordinate
0332:             */
0333:            public float getTop(float margin) {
0334:                return ury - margin;
0335:            }
0336:
0337:            /**
0338:             * Sets the lower left y-coordinate.
0339:             * 
0340:             * @param value
0341:             *            the new value
0342:             */
0343:            public void setBottom(float value) {
0344:                lly = value;
0345:            }
0346:
0347:            /**
0348:             * Returns the lower left y-coordinate.
0349:             * 
0350:             * @return the lower left y-coordinate
0351:             */
0352:            public float getBottom() {
0353:                return lly;
0354:            }
0355:
0356:            /**
0357:             * Returns the lower left y-coordinate, considering a given margin.
0358:             * 
0359:             * @param margin
0360:             *            a margin
0361:             * @return the lower left y-coordinate
0362:             */
0363:            public float getBottom(float margin) {
0364:                return lly + margin;
0365:            }
0366:
0367:            /**
0368:             * Returns the height of the rectangle.
0369:             * 
0370:             * @return a height
0371:             */
0372:            public float getHeight() {
0373:                return ury - lly;
0374:            }
0375:
0376:            /**
0377:             * Switches lowerleft with upperright
0378:             */
0379:            public void normalize() {
0380:                if (llx > urx) {
0381:                    float a = llx;
0382:                    llx = urx;
0383:                    urx = a;
0384:                }
0385:                if (lly > ury) {
0386:                    float a = lly;
0387:                    lly = ury;
0388:                    ury = a;
0389:                }
0390:            }
0391:
0392:            // methods to get/set the rotation
0393:
0394:            /**
0395:             * Gets the rotation of the rectangle
0396:             * 
0397:             * @return a rotation value
0398:             */
0399:            public int getRotation() {
0400:                return rotation;
0401:            }
0402:
0403:            /**
0404:             * Swaps the values of urx and ury and of lly and llx in order to rotate the
0405:             * rectangle.
0406:             * 
0407:             * @return a <CODE>Rectangle</CODE>
0408:             */
0409:            public Rectangle rotate() {
0410:                Rectangle rect = new Rectangle(lly, llx, ury, urx);
0411:                rect.rotation = rotation + 90;
0412:                rect.rotation %= 360;
0413:                return rect;
0414:            }
0415:
0416:            // border
0417:
0418:            /**
0419:             * Returns the exact type of the border.
0420:             * 
0421:             * @return a value
0422:             */
0423:            public int getBorder() {
0424:                return border;
0425:            }
0426:
0427:            /**
0428:             * Indicates if the table has borders.
0429:             * 
0430:             * @return a boolean
0431:             */
0432:            public boolean hasBorders() {
0433:                return (border > 0)
0434:                        && ((borderWidth > 0) || (borderWidthLeft > 0)
0435:                                || (borderWidthRight > 0)
0436:                                || (borderWidthTop > 0) || (borderWidthBottom > 0));
0437:            }
0438:
0439:            /**
0440:             * Indicates if the table has a some type of border.
0441:             * 
0442:             * @param type
0443:             *            the type of border
0444:             * @return a boolean
0445:             */
0446:            public boolean hasBorder(int type) {
0447:                return border != UNDEFINED && (border & type) == type;
0448:            }
0449:
0450:            /**
0451:             * Enables/Disables the border on the specified sides. The border is
0452:             * specified as an integer bitwise combination of the constants: <CODE>
0453:             * LEFT, RIGHT, TOP, BOTTOM</CODE>.
0454:             * 
0455:             * @see #enableBorderSide(int)
0456:             * @see #disableBorderSide(int)
0457:             * @param value
0458:             *            the new value
0459:             */
0460:            public void setBorder(int value) {
0461:                border = value;
0462:            }
0463:
0464:            /**
0465:             * Enables the border on the specified side.
0466:             * 
0467:             * @param side
0468:             *            the side to enable. One of <CODE>LEFT, RIGHT, TOP, BOTTOM
0469:             *            </CODE>
0470:             */
0471:            public void enableBorderSide(int side) {
0472:                if (border == UNDEFINED) {
0473:                    border = 0;
0474:                }
0475:                border |= side;
0476:            }
0477:
0478:            /**
0479:             * Disables the border on the specified side.
0480:             * 
0481:             * @param side
0482:             *            the side to disable. One of <CODE>LEFT, RIGHT, TOP, BOTTOM
0483:             *            </CODE>
0484:             */
0485:            public void disableBorderSide(int side) {
0486:                if (border == UNDEFINED) {
0487:                    border = 0;
0488:                }
0489:                border &= ~side;
0490:            }
0491:
0492:            // borderwidth
0493:
0494:            /**
0495:             * Gets the borderwidth.
0496:             * 
0497:             * @return a value
0498:             */
0499:            public float getBorderWidth() {
0500:                return borderWidth;
0501:            }
0502:
0503:            /**
0504:             * Sets the borderwidth of the table.
0505:             * 
0506:             * @param value
0507:             *            the new value
0508:             */
0509:
0510:            public void setBorderWidth(float value) {
0511:                borderWidth = value;
0512:            }
0513:
0514:            // bordercolor
0515:
0516:            /**
0517:             * Gets the color of the border.
0518:             * 
0519:             * @return a value
0520:             */
0521:
0522:            public Color getBorderColor() {
0523:                return borderColor;
0524:            }
0525:
0526:            /**
0527:             * Sets the color of the border.
0528:             * 
0529:             * @param value
0530:             *            the new value
0531:             */
0532:
0533:            public void setBorderColor(Color value) {
0534:                borderColor = value;
0535:            }
0536:
0537:            // backgroundcolor
0538:
0539:            /**
0540:             * Gets the backgroundcolor.
0541:             * 
0542:             * @return a value
0543:             */
0544:            public Color getBackgroundColor() {
0545:                return backgroundColor;
0546:            }
0547:
0548:            /**
0549:             * Sets the backgroundcolor of the rectangle.
0550:             * 
0551:             * @param value
0552:             *            the new value
0553:             */
0554:
0555:            public void setBackgroundColor(Color value) {
0556:                backgroundColor = value;
0557:            }
0558:
0559:            /**
0560:             * Gets the grayscale.
0561:             * 
0562:             * @return a value
0563:             */
0564:
0565:            public float getGrayFill() {
0566:                if (backgroundColor instanceof  GrayColor)
0567:                    return ((GrayColor) backgroundColor).getGray();
0568:                else
0569:                    return 0;
0570:            }
0571:
0572:            /**
0573:             * Sets the grayscale of the rectangle.
0574:             * 
0575:             * @param value
0576:             *            the new value
0577:             */
0578:            public void setGrayFill(float value) {
0579:                backgroundColor = new GrayColor(value);
0580:            }
0581:
0582:            // variable borders
0583:
0584:            /**
0585:             * Indicates whether variable width borders are being used. Returns true if
0586:             * <CODE>setBorderWidthLeft, setBorderWidthRight, setBorderWidthTop, or
0587:             * setBorderWidthBottom</CODE> has been called.
0588:             * 
0589:             * @return true if variable width borders are in use
0590:             *  
0591:             */
0592:            public boolean isUseVariableBorders() {
0593:                return useVariableBorders;
0594:            }
0595:
0596:            /**
0597:             * Sets a parameter indicating if the rectangle has variable borders
0598:             * 
0599:             * @param useVariableBorders
0600:             *            indication if the rectangle has variable borders
0601:             */
0602:            public void setUseVariableBorders(boolean useVariableBorders) {
0603:                this .useVariableBorders = useVariableBorders;
0604:            }
0605:
0606:            // variable border width
0607:
0608:            /** Gives the border width of a specific side. */
0609:            private float getVariableBorderWidth(float variableWidthValue,
0610:                    int side) {
0611:                if ((border & side) != 0) {
0612:                    return variableWidthValue != UNDEFINED ? variableWidthValue
0613:                            : borderWidth;
0614:                } else {
0615:                    return 0;
0616:                }
0617:            }
0618:
0619:            /**
0620:             * Updates the border flag for a side based on the specified width. A width
0621:             * of 0 will disable the border on that side. Any other width enables it.
0622:             * 
0623:             * @param width
0624:             *            width of border
0625:             * @param side
0626:             *            border side constant
0627:             */
0628:            private void updateBorderBasedOnWidth(float width, int side) {
0629:                useVariableBorders = true;
0630:                if (width > 0) {
0631:                    enableBorderSide(side);
0632:                } else {
0633:                    disableBorderSide(side);
0634:                }
0635:            }
0636:
0637:            /**
0638:             * Gets the width of a border.
0639:             * 
0640:             * @return a width
0641:             */
0642:            public float getBorderWidthLeft() {
0643:                return getVariableBorderWidth(borderWidthLeft, LEFT);
0644:            }
0645:
0646:            /**
0647:             * Sets the width of a border
0648:             * 
0649:             * @param borderWidthLeft
0650:             *            a width
0651:             */
0652:            public void setBorderWidthLeft(float borderWidthLeft) {
0653:                this .borderWidthLeft = borderWidthLeft;
0654:                updateBorderBasedOnWidth(borderWidthLeft, LEFT);
0655:            }
0656:
0657:            /**
0658:             * Gets the width of a border.
0659:             * 
0660:             * @return a width
0661:             */
0662:            public float getBorderWidthRight() {
0663:                return getVariableBorderWidth(borderWidthRight, RIGHT);
0664:            }
0665:
0666:            /**
0667:             * Sets the width of a border
0668:             * 
0669:             * @param borderWidthRight
0670:             *            a width
0671:             */
0672:            public void setBorderWidthRight(float borderWidthRight) {
0673:                this .borderWidthRight = borderWidthRight;
0674:                updateBorderBasedOnWidth(borderWidthRight, RIGHT);
0675:            }
0676:
0677:            /**
0678:             * Gets the width of a border.
0679:             * 
0680:             * @return a width
0681:             */
0682:            public float getBorderWidthTop() {
0683:                return getVariableBorderWidth(borderWidthTop, TOP);
0684:            }
0685:
0686:            /**
0687:             * Sets the width of a border
0688:             * 
0689:             * @param borderWidthTop
0690:             *            a width
0691:             */
0692:            public void setBorderWidthTop(float borderWidthTop) {
0693:                this .borderWidthTop = borderWidthTop;
0694:                updateBorderBasedOnWidth(borderWidthTop, TOP);
0695:            }
0696:
0697:            /**
0698:             * Gets the width of a border.
0699:             * 
0700:             * @return a width
0701:             */
0702:            public float getBorderWidthBottom() {
0703:                return getVariableBorderWidth(borderWidthBottom, BOTTOM);
0704:            }
0705:
0706:            /**
0707:             * Sets the width of a border
0708:             * 
0709:             * @param borderWidthBottom
0710:             *            a width
0711:             */
0712:            public void setBorderWidthBottom(float borderWidthBottom) {
0713:                this .borderWidthBottom = borderWidthBottom;
0714:                updateBorderBasedOnWidth(borderWidthBottom, BOTTOM);
0715:            }
0716:
0717:            // variable border color
0718:
0719:            /**
0720:             * Gets the color of a border.
0721:             * 
0722:             * @return a color value
0723:             */
0724:            public Color getBorderColorLeft() {
0725:                if (borderColorLeft == null)
0726:                    return borderColor;
0727:                return borderColorLeft;
0728:            }
0729:
0730:            /**
0731:             * Sets the value of the border color
0732:             * 
0733:             * @param value
0734:             *            a color value
0735:             */
0736:            public void setBorderColorLeft(Color value) {
0737:                borderColorLeft = value;
0738:            }
0739:
0740:            /**
0741:             * Gets the color of a border.
0742:             * 
0743:             * @return a color value
0744:             */
0745:            public Color getBorderColorRight() {
0746:                if (borderColorRight == null)
0747:                    return borderColor;
0748:                return borderColorRight;
0749:            }
0750:
0751:            /**
0752:             * Sets the value of the border color
0753:             * 
0754:             * @param value
0755:             *            a color value
0756:             */
0757:            public void setBorderColorRight(Color value) {
0758:                borderColorRight = value;
0759:            }
0760:
0761:            /**
0762:             * Gets the color of a border.
0763:             * 
0764:             * @return a color value
0765:             */
0766:            public Color getBorderColorTop() {
0767:                if (borderColorTop == null)
0768:                    return borderColor;
0769:                return borderColorTop;
0770:            }
0771:
0772:            /**
0773:             * Sets the value of the border color
0774:             * 
0775:             * @param value
0776:             *            a color value
0777:             */
0778:            public void setBorderColorTop(Color value) {
0779:                borderColorTop = value;
0780:            }
0781:
0782:            /**
0783:             * Gets the color of a border.
0784:             * 
0785:             * @return a color value
0786:             */
0787:            public Color getBorderColorBottom() {
0788:                if (borderColorBottom == null)
0789:                    return borderColor;
0790:                return borderColorBottom;
0791:            }
0792:
0793:            /**
0794:             * Sets the value of the border color
0795:             * 
0796:             * @param value
0797:             *            a color value
0798:             */
0799:            public void setBorderColorBottom(Color value) {
0800:                borderColorBottom = value;
0801:            }
0802:
0803:            // special methods
0804:
0805:            /**
0806:             * Gets a Rectangle that is altered to fit on the page.
0807:             * 
0808:             * @param top
0809:             *            the top position
0810:             * @param bottom
0811:             *            the bottom position
0812:             * @return a <CODE>Rectangle</CODE>
0813:             */
0814:            public Rectangle rectangle(float top, float bottom) {
0815:                Rectangle tmp = new Rectangle(this );
0816:                if (getTop() > top) {
0817:                    tmp.setTop(top);
0818:                    tmp.disableBorderSide(TOP);
0819:                }
0820:                if (getBottom() < bottom) {
0821:                    tmp.setBottom(bottom);
0822:                    tmp.disableBorderSide(BOTTOM);
0823:                }
0824:                return tmp;
0825:            }
0826:
0827:            /**
0828:             * Copies all of the parameters from a <CODE>Rectangle</CODE> object
0829:             * except the position.
0830:             * 
0831:             * @param rect
0832:             *            <CODE>Rectangle</CODE> to copy from
0833:             */
0834:            public void cloneNonPositionParameters(Rectangle rect) {
0835:                this .rotation = rect.rotation;
0836:                this .border = rect.border;
0837:                this .borderWidth = rect.borderWidth;
0838:                this .borderColor = rect.borderColor;
0839:                this .backgroundColor = rect.backgroundColor;
0840:                this .useVariableBorders = rect.useVariableBorders;
0841:                this .borderWidthLeft = rect.borderWidthLeft;
0842:                this .borderWidthRight = rect.borderWidthRight;
0843:                this .borderWidthTop = rect.borderWidthTop;
0844:                this .borderWidthBottom = rect.borderWidthBottom;
0845:                this .borderColorLeft = rect.borderColorLeft;
0846:                this .borderColorRight = rect.borderColorRight;
0847:                this .borderColorTop = rect.borderColorTop;
0848:                this .borderColorBottom = rect.borderColorBottom;
0849:            }
0850:
0851:            /**
0852:             * Copies all of the parameters from a <CODE>Rectangle</CODE> object
0853:             * except the position.
0854:             * 
0855:             * @param rect
0856:             *            <CODE>Rectangle</CODE> to copy from
0857:             */
0858:            public void softCloneNonPositionParameters(Rectangle rect) {
0859:                if (rect.rotation != 0)
0860:                    this .rotation = rect.rotation;
0861:                if (rect.border != UNDEFINED)
0862:                    this .border = rect.border;
0863:                if (rect.borderWidth != UNDEFINED)
0864:                    this .borderWidth = rect.borderWidth;
0865:                if (rect.borderColor != null)
0866:                    this .borderColor = rect.borderColor;
0867:                if (rect.backgroundColor != null)
0868:                    this .backgroundColor = rect.backgroundColor;
0869:                if (useVariableBorders)
0870:                    this .useVariableBorders = rect.useVariableBorders;
0871:                if (rect.borderWidthLeft != UNDEFINED)
0872:                    this .borderWidthLeft = rect.borderWidthLeft;
0873:                if (rect.borderWidthRight != UNDEFINED)
0874:                    this .borderWidthRight = rect.borderWidthRight;
0875:                if (rect.borderWidthTop != UNDEFINED)
0876:                    this .borderWidthTop = rect.borderWidthTop;
0877:                if (rect.borderWidthBottom != UNDEFINED)
0878:                    this .borderWidthBottom = rect.borderWidthBottom;
0879:                if (rect.borderColorLeft != null)
0880:                    this .borderColorLeft = rect.borderColorLeft;
0881:                if (rect.borderColorRight != null)
0882:                    this .borderColorRight = rect.borderColorRight;
0883:                if (rect.borderColorTop != null)
0884:                    this .borderColorTop = rect.borderColorTop;
0885:                if (rect.borderColorBottom != null)
0886:                    this .borderColorBottom = rect.borderColorBottom;
0887:            }
0888:
0889:            /**
0890:             * @see java.lang.Object#toString()
0891:             */
0892:            public String toString() {
0893:                StringBuffer buf = new StringBuffer("Rectangle: ");
0894:                buf.append(getWidth());
0895:                buf.append('x');
0896:                buf.append(getHeight());
0897:                buf.append(" (rot: ");
0898:                buf.append(rotation);
0899:                buf.append(" degrees)");
0900:                return buf.toString();
0901:            }
0902:
0903:            // deprecated stuff
0904:
0905:            /**
0906:             * Returns the lower left x-coordinate.
0907:             * 
0908:             * @return the lower left x-coordinate
0909:             * @deprecated Use {@link #getLeft()} instead
0910:             */
0911:            public float left() {
0912:                return getLeft();
0913:            }
0914:
0915:            /**
0916:             * Returns the upper right x-coordinate.
0917:             * 
0918:             * @return the upper right x-coordinate
0919:             * @deprecated Use {@link #getRight()} instead
0920:             */
0921:            public float right() {
0922:                return getRight();
0923:            }
0924:
0925:            /**
0926:             * Returns the upper right y-coordinate.
0927:             * 
0928:             * @return the upper right y-coordinate
0929:             * @deprecated Use {@link #getTop()} instead
0930:             */
0931:            public float top() {
0932:                return getTop();
0933:            }
0934:
0935:            /**
0936:             * Returns the lower left y-coordinate.
0937:             * 
0938:             * @return the lower left y-coordinate
0939:             * @deprecated Use {@link #getBottom()} instead
0940:             */
0941:            public float bottom() {
0942:                return getBottom();
0943:            }
0944:
0945:            /**
0946:             * Returns the lower left x-coordinate, considering a given margin.
0947:             * 
0948:             * @param margin
0949:             *            a margin
0950:             * @return the lower left x-coordinate
0951:             * @deprecated Use {@link #getLeft(float)} instead
0952:             */
0953:            public float left(float margin) {
0954:                return getLeft(margin);
0955:            }
0956:
0957:            /**
0958:             * Returns the upper right x-coordinate, considering a given margin.
0959:             * 
0960:             * @param margin
0961:             *            a margin
0962:             * @return the upper right x-coordinate
0963:             * @deprecated Use {@link #getRight(float)} instead
0964:             */
0965:            public float right(float margin) {
0966:                return getRight(margin);
0967:            }
0968:
0969:            /**
0970:             * Returns the width of the rectangle.
0971:             * 
0972:             * @return a width
0973:             * @deprecated Use {@link #getWidth()} instead
0974:             */
0975:            public float width() {
0976:                return getWidth();
0977:            }
0978:
0979:            /**
0980:             * Returns the upper right y-coordinate, considering a given margin.
0981:             * 
0982:             * @param margin
0983:             *            a margin
0984:             * @return the upper right y-coordinate
0985:             * @deprecated Use {@link #getTop(float)} instead
0986:             */
0987:            public float top(float margin) {
0988:                return getTop(margin);
0989:            }
0990:
0991:            /**
0992:             * Returns the lower left y-coordinate, considering a given margin.
0993:             * 
0994:             * @param margin
0995:             *            a margin
0996:             * @return the lower left y-coordinate
0997:             * @deprecated Use {@link #getBottom(float)} instead
0998:             */
0999:            public float bottom(float margin) {
1000:                return getBottom(margin);
1001:            }
1002:
1003:            /**
1004:             * Returns the height of the rectangle.
1005:             * 
1006:             * @return a height
1007:             * @deprecated Use {@link #getHeight()} instead
1008:             */
1009:            public float height() {
1010:                return getHeight();
1011:            }
1012:
1013:            /**
1014:             * Returns the exact type of the border.
1015:             * 
1016:             * @return a value
1017:             * @deprecated Use {@link #getBorder()} instead
1018:             */
1019:            public int border() {
1020:                return getBorder();
1021:            }
1022:
1023:            /**
1024:             * Gets the borderwidth.
1025:             * 
1026:             * @return a value
1027:             * @deprecated Use {@link #getBorderWidth()} instead
1028:             */
1029:            public float borderWidth() {
1030:                return getBorderWidth();
1031:            }
1032:
1033:            /**
1034:             * Gets the color of the border.
1035:             * 
1036:             * @return a value
1037:             * @deprecated Use {@link #getBorderColor()} instead
1038:             */
1039:
1040:            public Color borderColor() {
1041:                return getBorderColor();
1042:            }
1043:
1044:            /**
1045:             * Gets the backgroundcolor.
1046:             * 
1047:             * @return a value
1048:             * @deprecated Use {@link #getBackgroundColor()} instead
1049:             */
1050:            public Color backgroundColor() {
1051:                return getBackgroundColor();
1052:            }
1053:
1054:            /**
1055:             * Gets the grayscale.
1056:             * 
1057:             * @return a value
1058:             * @deprecated Use {@link #getGrayFill()} instead
1059:             */
1060:
1061:            public float grayFill() {
1062:                return getGrayFill();
1063:            }
1064:
1065:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.