001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.undation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: package org.columba.core.print;
017:
018: import java.awt.Color;
019: import java.awt.Graphics2D;
020:
021: public abstract class cPrintObject {
022: public static final int SOUTHWEST = 1;
023:
024: public static final int SOUTH = 2;
025:
026: public static final int SOUTHEAST = 3;
027:
028: public static final int WEST = 4;
029:
030: public static final int CENTER = 5;
031:
032: public static final int EAST = 6;
033:
034: public static final int NORTHWEST = 7;
035:
036: public static final int NORTH = 8;
037:
038: public static final int NORTHEAST = 9;
039:
040: public static final int NONE = 0;
041:
042: public static final int HORIZONTAL = 1;
043:
044: public static final int VERTICAL = 2;
045:
046: public static final int BOTH = 3;
047:
048: public static final int NORMAL = 1;
049:
050: public static final int HEADER = 2;
051:
052: public static final int FOOTER = 3;
053:
054: public static final int GROUPMEMBER = 4;
055:
056: private int orientation;
057:
058: private int sizePolicy;
059:
060: private int type;
061:
062: private cPoint location;
063:
064: private cSize size;
065:
066: protected cUnit leftMargin;
067:
068: protected cUnit rightMargin;
069:
070: protected cUnit topMargin;
071:
072: protected cUnit bottomMargin;
073:
074: private cPoint drawingOrigin;
075:
076: private cSize drawingSize;
077:
078: protected Color color;
079:
080: protected cPage page;
081:
082: public cPrintObject() {
083:
084: leftMargin = new cCmUnit();
085: rightMargin = new cCmUnit();
086: topMargin = new cCmUnit();
087: bottomMargin = new cCmUnit();
088:
089: drawingOrigin = new cPoint(new cCmUnit(), new cCmUnit());
090: drawingSize = new cSize(new cCmUnit(), new cCmUnit());
091:
092: location = new cPoint(new cCmUnit(), new cCmUnit());
093: size = new cSize(new cCmUnit(), new cCmUnit());
094:
095: orientation = NORTHWEST;
096: sizePolicy = HORIZONTAL;
097: type = NORMAL;
098:
099: color = Color.black;
100: }
101:
102: public void setPage(cPage p) {
103: page = p;
104: }
105:
106: /**
107: * Returns the page, that this print object belongs to. *20030604,
108: * karlpeder* Added
109: */
110: public cPage getPage() {
111: return page;
112: }
113:
114: public abstract void print(Graphics2D g);
115:
116: public void setLocation(cPoint l) {
117: location = l;
118: }
119:
120: public cPoint getLocation() {
121: return location;
122: }
123:
124: public void setSize(cSize s) {
125: size = s;
126: }
127:
128: public void setOrientation(int o) {
129: orientation = o;
130: }
131:
132: public void setSizePolicy(int sp) {
133: sizePolicy = sp;
134: }
135:
136: public void setLeftMargin(cUnit m) {
137: leftMargin = m;
138: }
139:
140: public void setRightMargin(cUnit m) {
141: rightMargin = m;
142: }
143:
144: public void setTopMargin(cUnit m) {
145: topMargin = m;
146: }
147:
148: public void setBottomMargin(cUnit m) {
149: bottomMargin = m;
150: }
151:
152: public cPoint getDrawingOrigin() {
153: return drawingOrigin;
154: }
155:
156: public cSize getDrawingSize() {
157: return drawingSize;
158: }
159:
160: public cSize getSize() {
161: return size;
162: }
163:
164: public void setColor(Color c) {
165: color = c;
166: }
167:
168: public Color getColor() {
169: return color;
170: }
171:
172: public void computePositionAndSize() {
173: cPoint parentLocation;
174: cSize parentSize;
175:
176: parentLocation = page.getPrintableAreaOrigin();
177: parentSize = page.getPrintableAreaSize();
178:
179: switch (type) {
180: case NORMAL: {
181: drawingOrigin = location.add(parentLocation);
182:
183: break;
184: }
185:
186: case HEADER: {
187: drawingOrigin = parentLocation.subHeight(getSize(
188: parentSize.getWidth()).getHeight());
189:
190: break;
191: }
192:
193: case FOOTER: {
194: drawingOrigin = parentLocation.addHeight(parentSize
195: .getHeight());
196:
197: break;
198: }
199:
200: case GROUPMEMBER: {
201: drawingOrigin = location;
202:
203: break;
204: }
205: }
206:
207: // SizePolicy
208: if ((sizePolicy == HORIZONTAL) || (sizePolicy == BOTH)) {
209: drawingSize = new cSize(parentSize.getWidth(), drawingSize
210: .getHeight());
211: }
212:
213: if ((sizePolicy == VERTICAL) || (sizePolicy == BOTH)) {
214: drawingSize = new cSize(drawingSize.getWidth(), parentSize
215: .getHeight());
216: }
217:
218: // Margins
219: drawingOrigin.setX(drawingOrigin.getX().add(leftMargin));
220: drawingOrigin.setY(drawingOrigin.getY().add(topMargin));
221: drawingSize.setWidth(drawingSize.getWidth().sub(leftMargin)
222: .sub(rightMargin));
223: drawingSize.setHeight(drawingSize.getHeight().sub(topMargin)
224: .sub(bottomMargin));
225:
226: // Orientation
227: if ((orientation == SOUTHWEST) || (orientation == WEST)
228: || (orientation == NORTHWEST)) {
229: drawingOrigin = new cPoint(drawingOrigin.getX(),
230: drawingOrigin.getY());
231: }
232:
233: if ((orientation == SOUTHEAST) || (orientation == EAST)
234: || (orientation == NORTHEAST)) {
235: cUnit objectPosition = parentSize.getWidth().sub(
236: this .getSize().getWidth());
237: drawingOrigin = new cPoint(drawingOrigin.getX().add(
238: objectPosition), drawingOrigin.getY());
239: }
240:
241: if ((orientation == NORTH) || (orientation == CENTER)
242: || (orientation == SOUTH)) {
243: cUnit parentCenter = parentSize.getWidth().div(2.0);
244: cUnit childCenter = getSize().getWidth().div(2.0);
245: cUnit objectPosition = parentCenter.sub(childCenter);
246: drawingOrigin = new cPoint(drawingOrigin.getX().add(
247: objectPosition), drawingOrigin.getY());
248: }
249:
250: if ((orientation == SOUTHWEST) || (orientation == SOUTH)
251: || (orientation == SOUTHEAST)) {
252: cUnit objectPosition = parentSize.getHeight().sub(
253: getSize().getHeight());
254:
255: drawingOrigin = new cPoint(drawingOrigin.getX(),
256: objectPosition.add(drawingOrigin.getY()));
257: }
258:
259: if ((orientation == WEST) || (orientation == CENTER)
260: || (orientation == EAST)) {
261: cUnit parentCenter = parentSize.getHeight().div(2.0);
262: cUnit childCenter = getSize().getHeight().div(2.0);
263: cUnit objectPosition = parentCenter.sub(childCenter);
264: drawingOrigin = new cPoint(drawingOrigin.getX(),
265: drawingOrigin.getY().add(objectPosition));
266: }
267:
268: if ((orientation == SOUTHWEST) || (orientation == SOUTH)
269: || (orientation == SOUTHEAST)) {
270:
271: drawingOrigin = new cPoint(drawingOrigin.getX(),
272: parentLocation.getY().add(location.getY()).add(
273: size.getHeight()));
274: }
275: }
276:
277: public abstract cSize getSize(cUnit maxWidth);
278:
279: public cPrintObject breakBlock(cUnit w, cUnit maxHeight) {
280: return null;
281: }
282:
283: public int getType() {
284: return type;
285: }
286:
287: public void setType(int type) {
288: this.type = type;
289: }
290: }
|