1 package org.columba.core.print; 17 18 import java.awt.Color ; 19 import java.awt.Graphics2D ; 20 21 public abstract class cPrintObject { 22 public static final int SOUTHWEST = 1; 23 24 public static final int SOUTH = 2; 25 26 public static final int SOUTHEAST = 3; 27 28 public static final int WEST = 4; 29 30 public static final int CENTER = 5; 31 32 public static final int EAST = 6; 33 34 public static final int NORTHWEST = 7; 35 36 public static final int NORTH = 8; 37 38 public static final int NORTHEAST = 9; 39 40 public static final int NONE = 0; 41 42 public static final int HORIZONTAL = 1; 43 44 public static final int VERTICAL = 2; 45 46 public static final int BOTH = 3; 47 48 public static final int NORMAL = 1; 49 50 public static final int HEADER = 2; 51 52 public static final int FOOTER = 3; 53 54 public static final int GROUPMEMBER = 4; 55 56 private int orientation; 57 58 private int sizePolicy; 59 60 private int type; 61 62 private cPoint location; 63 64 private cSize size; 65 66 protected cUnit leftMargin; 67 68 protected cUnit rightMargin; 69 70 protected cUnit topMargin; 71 72 protected cUnit bottomMargin; 73 74 private cPoint drawingOrigin; 75 76 private cSize drawingSize; 77 78 protected Color color; 79 80 protected cPage page; 81 82 public cPrintObject() { 83 84 leftMargin = new cCmUnit(); 85 rightMargin = new cCmUnit(); 86 topMargin = new cCmUnit(); 87 bottomMargin = new cCmUnit(); 88 89 drawingOrigin = new cPoint(new cCmUnit(), new cCmUnit()); 90 drawingSize = new cSize(new cCmUnit(), new cCmUnit()); 91 92 location = new cPoint(new cCmUnit(), new cCmUnit()); 93 size = new cSize(new cCmUnit(), new cCmUnit()); 94 95 orientation = NORTHWEST; 96 sizePolicy = HORIZONTAL; 97 type = NORMAL; 98 99 color = Color.black; 100 } 101 102 public void setPage(cPage p) { 103 page = p; 104 } 105 106 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.getHeight()); 195 196 break; 197 } 198 199 case GROUPMEMBER: { 200 drawingOrigin = location; 201 202 break; 203 } 204 } 205 206 if ((sizePolicy == HORIZONTAL) || (sizePolicy == BOTH)) { 208 drawingSize = new cSize(parentSize.getWidth(), drawingSize 209 .getHeight()); 210 } 211 212 if ((sizePolicy == VERTICAL) || (sizePolicy == BOTH)) { 213 drawingSize = new cSize(drawingSize.getWidth(), parentSize 214 .getHeight()); 215 } 216 217 drawingOrigin.setX(drawingOrigin.getX().add(leftMargin)); 219 drawingOrigin.setY(drawingOrigin.getY().add(topMargin)); 220 drawingSize.setWidth(drawingSize.getWidth().sub(leftMargin).sub( 221 rightMargin)); 222 drawingSize.setHeight(drawingSize.getHeight().sub(topMargin).sub( 223 bottomMargin)); 224 225 if ((orientation == SOUTHWEST) || (orientation == WEST) 227 || (orientation == NORTHWEST)) { 228 drawingOrigin = new cPoint(drawingOrigin.getX(), drawingOrigin 229 .getY()); 230 } 231 232 if ((orientation == SOUTHEAST) || (orientation == EAST) 233 || (orientation == NORTHEAST)) { 234 cUnit objectPosition = parentSize.getWidth().sub( 235 this.getSize().getWidth()); 236 drawingOrigin = new cPoint( 237 drawingOrigin.getX().add(objectPosition), drawingOrigin 238 .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( 247 drawingOrigin.getX().add(objectPosition), drawingOrigin 248 .getY()); 249 } 250 251 if ((orientation == SOUTHWEST) || (orientation == SOUTH) 252 || (orientation == SOUTHEAST)) { 253 cUnit objectPosition = parentSize.getHeight().sub( 254 getSize().getHeight()); 255 256 drawingOrigin = new cPoint(drawingOrigin.getX(), objectPosition 257 .add(drawingOrigin.getY())); 258 } 259 260 if ((orientation == WEST) || (orientation == CENTER) 261 || (orientation == EAST)) { 262 cUnit parentCenter = parentSize.getHeight().div(2.0); 263 cUnit childCenter = getSize().getHeight().div(2.0); 264 cUnit objectPosition = parentCenter.sub(childCenter); 265 drawingOrigin = new cPoint(drawingOrigin.getX(), drawingOrigin 266 .getY().add(objectPosition)); 267 } 268 269 if ((orientation == SOUTHWEST) || (orientation == SOUTH) 270 || (orientation == SOUTHEAST)) { 271 272 273 drawingOrigin = new cPoint(drawingOrigin.getX(), parentLocation 274 .getY().add(location.getY()).add(size.getHeight())); 275 } 276 } 277 278 public abstract cSize getSize(cUnit maxWidth); 279 280 public cPrintObject breakBlock(cUnit w, cUnit maxHeight) { 281 return null; 282 } 283 284 public int getType() { 285 return type; 286 } 287 288 public void setType(int type) { 289 this.type = type; 290 } 291 } 292 | Popular Tags |