01: package com.etymon.pj.object;
02:
03: import java.util.*;
04:
05: /**
06: A representation of the PDF Rectangle type.
07: @author Nassib Nassar
08: */
09: public class PjRectangle extends PjArray {
10:
11: /**
12: Creates a Rectangle object.
13: */
14: public PjRectangle() {
15: super ();
16: _v.setSize(4);
17: }
18:
19: /**
20: Creates a Rectangle as a wrapper around a Vector.
21: @param v the Vector to use for this Rectangle.
22: */
23: public PjRectangle(Vector v) {
24: super (v);
25: if (_v.size() < 4) {
26: _v.setSize(4);
27: }
28: }
29:
30: public void setLowerLeftX(PjNumber number) {
31: _v.setElementAt(number, 0);
32: }
33:
34: public PjNumber getLowerLeftX() {
35: return (PjNumber) (_v.elementAt(0));
36: }
37:
38: public void setLowerLeftY(PjNumber number) {
39: _v.setElementAt(number, 1);
40: }
41:
42: public PjNumber getLowerLeftY() {
43: return (PjNumber) (_v.elementAt(1));
44: }
45:
46: public void setUpperRightX(PjNumber number) {
47: _v.setElementAt(number, 2);
48: }
49:
50: public PjNumber getUpperRightX() {
51: return (PjNumber) (_v.elementAt(2));
52: }
53:
54: public void setUpperRightY(PjNumber number) {
55: _v.setElementAt(number, 3);
56: }
57:
58: public PjNumber getUpperRightY() {
59: return (PjNumber) (_v.elementAt(3));
60: }
61:
62: /**
63: Examines an array to see if it is a PDF Rectangle object.
64: @param array the array to examine.
65: @return true if the array could be interpreted as a
66: valid PjRectangle object.
67: */
68: public static boolean isLike(PjArray array) {
69: if (array._v.size() != 4) {
70: return false;
71: }
72: // see if all the elements are PjNumbers
73: Enumeration m = array._v.elements();
74: while (m.hasMoreElements()) {
75: if (!(m.nextElement() instanceof PjNumber)) {
76: return false;
77: }
78: }
79: return true;
80: }
81:
82: /**
83: Returns a deep copy of this object.
84: @return a deep copy of this object.
85: @exception CloneNotSupportedException if the instance can not be cloned.
86: */
87: public Object clone() throws CloneNotSupportedException {
88: return new PjRectangle(cloneVector());
89: }
90:
91: }
|