001: /**
002: * Box.java
003: *
004: Copyright (c) 2007, Innovatics Inc.
005:
006: All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
009:
010: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
011: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
012:
013: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
014: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
015: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
016: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
017: CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
018: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
019: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
020: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
021: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
022: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
023: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
024: */package com.pdfjet;
025:
026: import java.lang.*;
027: import java.util.*;
028:
029: //>>>>pdfjet {
030: public class Box {
031:
032: protected double x = 0.0;
033: protected double y = 0.0;
034:
035: private double w = 0.0;
036: private double h = 0.0;
037:
038: private double[] color = { 0.0, 0.0, 0.0 };
039: private double width = 0.3;
040: private String pattern = "[] 0";
041: private boolean fill_shape = false;
042:
043: public Box() {
044: }
045:
046: public Box(double x, double y, double w, double h) {
047: this .x = x;
048: this .y = y;
049: this .w = w;
050: this .h = h;
051: }
052:
053: public void setPosition(double x, double y) {
054: this .x = x;
055: this .y = y;
056: }
057:
058: public void setSize(double w, double h) {
059: this .w = w;
060: this .h = h;
061: }
062:
063: public void setColor(double[] color) {
064: this .color = color;
065: }
066:
067: public void setLineWidth(double width) {
068: this .width = width;
069: }
070:
071: public void setPattern(String pattern) {
072: this .pattern = pattern;
073: }
074:
075: public void setFillShape(boolean fill_shape) {
076: this .fill_shape = fill_shape;
077: }
078:
079: public void placeIn(Box box, double x_offset, double y_offset)
080: throws Exception {
081: this .x = box.x + x_offset;
082: this .y = box.y + y_offset;
083: }
084:
085: public void scaleBy(double factor) throws Exception {
086: this .x *= factor;
087: this .y *= factor;
088: }
089:
090: public void drawOn(Page page) throws Exception {
091: page.setPenWidth(width);
092: page.setLinePattern(pattern);
093: page.moveTo(x, y);
094: page.lineTo(x + w, y);
095: page.lineTo(x + w, y + h);
096: page.lineTo(x, y + h);
097: page.closePath();
098: if (fill_shape) {
099: page.setBrushColor(color[0], color[1], color[2]);
100: page.fillPath();
101: } else {
102: page.setPenColor(color[0], color[1], color[2]);
103: page.strokePath();
104: }
105: }
106:
107: } // End of Box.java
108: //>>>>}
|