001: /**
002: * Line.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 Line {
031:
032: private double x1 = 0.0;
033: private double y1 = 0.0;
034: private double x2 = 0.0;
035: private double y2 = 0.0;
036:
037: private double box_x = 0.0;
038: private double box_y = 0.0;
039:
040: private double[] color = { 0.0, 0.0, 0.0 };
041: private double width = 0.3;
042: private String pattern = "[] 0";
043:
044: public Line() {
045: }
046:
047: public Line(double x1, double y1, double x2, double y2) {
048: this .x1 = x1;
049: this .y1 = y1;
050: this .x2 = x2;
051: this .y2 = y2;
052: }
053:
054: public void setPattern(String pattern) {
055: this .pattern = pattern;
056: }
057:
058: public void setStartPoint(double x, double y) {
059: this .x1 = x;
060: this .y1 = y;
061: }
062:
063: public void setEndPoint(double x, double y) {
064: this .x2 = x;
065: this .y2 = y;
066: }
067:
068: public Point getStartPoint() {
069: return new Point(x1, y1);
070: }
071:
072: public Point getEndPoint() {
073: return new Point(x2, y2);
074: }
075:
076: public void setWidth(double width) {
077: this .width = width;
078: }
079:
080: public void setColor(double[] color) {
081: this .color = color;
082: }
083:
084: public void placeIn(Box box) throws Exception {
085: placeIn(box, 0.0, 0.0);
086: }
087:
088: public void placeIn(Box box, double x_offset, double y_offset)
089: throws Exception {
090: box_x = box.x + x_offset;
091: box_y = box.y + y_offset;
092: }
093:
094: public void scaleBy(double factor) throws Exception {
095: this .x1 *= factor;
096: this .x2 *= factor;
097: this .y1 *= factor;
098: this .y2 *= factor;
099: }
100:
101: public void drawOn(Page page) throws Exception {
102: page.setPenColor(color[0], color[1], color[2]);
103: page.setPenWidth(width);
104: page.setLinePattern(pattern);
105: page.drawLine(x1 + box_x, y1 + box_y, x2 + box_x, y2 + box_y);
106: }
107:
108: } // End of Line.java
109: //>>>>}
|