1 14 package org.compiere.print.layout; 15 16 import java.awt.*; 17 import java.awt.geom.*; 18 import java.awt.image.*; 19 import javax.swing.*; 20 import java.util.*; 21 22 import org.compiere.print.*; 23 import org.compiere.model.*; 24 import org.compiere.util.*; 25 26 32 public abstract class PrintElement implements ImageObserver 33 { 34 37 protected PrintElement () 38 { 39 } 41 42 public static final Color LINK_COLOR = Color.blue; 43 44 45 protected float p_width = 0f; 46 protected float p_height = 0f; 47 protected boolean p_sizeCalculated = false; 48 49 protected float p_maxWidth = 0f; 50 protected float p_maxHeight = 0f; 51 52 protected String p_FieldAlignmentType; 53 54 protected Point2D.Double p_pageLocation = null; 55 56 57 58 62 public float getWidth() 63 { 64 if (!p_sizeCalculated) 65 p_sizeCalculated = calculateSize(); 66 return p_width; 67 } 69 73 public float getHeight() 74 { 75 if (!p_sizeCalculated) 76 p_sizeCalculated = calculateSize(); 77 return p_height; 78 } 80 85 public float getHeight (int pageNo) 86 { 87 return getHeight(); 88 } 90 94 public int getPageCount() 95 { 96 return 1; 97 } 99 104 protected abstract boolean calculateSize(); 105 106 113 public void layout (float maxWidth, float maxHeight, boolean isHeightOneLine, 114 String FieldAlignmentType) 115 { 116 if (isHeightOneLine) 117 p_maxHeight = -1f; 118 else if (maxHeight > 0f) 119 p_maxHeight = maxHeight; 120 p_maxWidth = maxWidth; 121 p_FieldAlignmentType = FieldAlignmentType; 123 if (p_FieldAlignmentType == null || p_FieldAlignmentType == MPrintFormatItem.FIELDALIGNMENTTYPE_Default) 124 p_FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft; 125 p_sizeCalculated = calculateSize(); 127 } 129 133 public void setMaxHeight (float maxHeight) 134 { 135 p_maxHeight = maxHeight; 136 } 138 142 public void setMaxWidth (float maxWidth) 143 { 144 p_maxWidth = maxWidth; 145 } 147 151 public void setLocation (Point2D pageLocation) 152 { 153 p_pageLocation = new Point2D.Double(pageLocation.getX(), pageLocation.getY()); 154 } 156 160 public Point2D getLocation() 161 { 162 return p_pageLocation; 163 } 165 170 protected Point2D.Double getAbsoluteLocation(Point2D pageStart) 171 { 172 Point2D.Double retValue = new Point2D.Double( 173 p_pageLocation.x + pageStart.getX(), p_pageLocation.y + pageStart.getY()); 174 return retValue; 177 } 179 183 public Rectangle getBounds() 184 { 185 if (p_pageLocation == null) 186 return new Rectangle (0,0, (int)p_width, (int)p_height); 187 return new Rectangle ((int)p_pageLocation.x, (int)p_pageLocation.y, (int)p_width, (int)p_height); 188 } 190 196 public MQuery getDrillDown (Point relativePoint, int pageNo) 197 { 198 return null; 199 } 201 207 public MQuery getDrillAcross (Point relativePoint, int pageNo) 208 { 209 return null; 210 } 212 213 214 220 public void translate (Properties ctx) 221 { 222 } 225 229 public boolean isTranslated() 230 { 231 return false; 232 } 234 235 236 244 public abstract void paint (Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView); 245 246 247 248 258 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) 259 { 260 boolean imageNotLoaded = (infoflags & (ALLBITS|ABORT)) == 0; 262 return imageNotLoaded; 265 } 267 271 public void waitForLoad (Image image) 272 { 273 long start = System.currentTimeMillis(); 274 int count = 0; 275 while (!Toolkit.getDefaultToolkit().prepareImage(image, -1, -1, this)) 276 { 277 try 278 { 279 Thread.sleep(1); 280 } 281 catch (InterruptedException ex) 282 { 283 Log.error("PrintElement.waitForLoad", ex); 284 break; 285 } 286 count++; 287 } 288 if (count > 0) 289 Log.trace(Log.l6_Database, "PrintElement.waitForLoad - " + (System.currentTimeMillis()-start) + "ms - #" + count); 290 } 292 296 public String toString() 297 { 298 String cn = getClass().getName(); 299 StringBuffer sb = new StringBuffer (); 300 sb.append(cn.substring(cn.lastIndexOf('.')+1)).append("["); 301 sb.append("Bounds=").append(getBounds()) 302 .append(",Height=").append(p_height).append("(").append(p_maxHeight) 303 .append("),Width=").append(p_width).append("(").append(p_maxHeight) 304 .append("),PageLocation=").append(p_pageLocation); 305 sb.append("]"); 306 return sb.toString(); 307 } 309 } | Popular Tags |