1 14 package org.compiere.print; 15 16 import java.util.*; 17 import javax.print.attribute.standard.*; 18 19 import org.compiere.model.*; 20 import org.compiere.util.*; 21 22 28 public class MPrintPaper extends X_AD_PrintPaper 29 { 30 35 private MPrintPaper(Properties ctx, int AD_PrintPaper_ID) 36 { 37 super(ctx, AD_PrintPaper_ID); 38 if (AD_PrintPaper_ID == 0) 39 { 40 setIsDefault (false); 41 setIsLandscape (true); 42 setCode ("iso-a4"); 43 setMarginTop (36); 44 setMarginBottom (36); 45 setMarginLeft (36); 46 setMarginRight (36); 47 } 48 } 50 51 52 57 public MediaSize getMediaSize() 58 { 59 String nameCode = getCode(); 60 if (nameCode == null) 61 return getMediaSizeDefault(); 62 MediaSizeName nameMedia = null; 64 if (nameCode.equals("iso-a4")) 65 nameMedia = MediaSizeName.ISO_A4; 66 else if (nameCode.equals("na-letter")) 67 nameMedia = MediaSizeName.NA_LETTER; 68 70 if (nameMedia == null) 71 return getMediaSizeDefault(); 72 MediaSize retValue = MediaSize.getMediaSizeForName(nameMedia); 74 if (retValue == null) 75 retValue = getMediaSizeDefault(); 76 return retValue; 78 } 80 84 public MediaSize getMediaSizeDefault() 85 { 86 MediaSize retValue = Language.getLanguage().getMediaSize(); 87 if (retValue == null) 88 retValue = MediaSize.ISO.A4; 89 Log.trace(Log.l6_Database, "MPrintPaper.getMediaSizeDefault", retValue); 90 return retValue; 91 } 93 97 public CPaper getCPaper() 98 { 99 CPaper retValue = new CPaper (getMediaSize(), isLandscape(), 100 getMarginLeft(), getMarginTop(), getMarginRight(), getMarginBottom()); 101 return retValue; 102 } 104 105 106 112 static MPrintPaper create (String name, boolean landscape) 113 { 114 MPrintPaper pp = new MPrintPaper (Env.getCtx(), 0); 115 pp.setName(name); 116 pp.setIsLandscape(landscape); 117 pp.save(); 118 return pp; 119 } 121 122 123 124 static private CCache s_papers = new CCache("printPaper", 5); 125 126 131 static public MPrintPaper get (int AD_PrintPaper_ID) 132 { 133 Integer key = new Integer (AD_PrintPaper_ID); 134 MPrintPaper pp = (MPrintPaper)s_papers.get(key); 135 if (pp == null) 136 { 137 pp = new MPrintPaper (Env.getCtx(), AD_PrintPaper_ID); 138 s_papers.put(key, pp); 139 } 140 else 141 Log.trace(Log.l4_Data, "MPrintPaper.get", "AD_PrintPaper_ID=" + AD_PrintPaper_ID); 142 return pp; 143 } 145 146 147 151 public static void main(String [] args) 152 { 153 org.compiere.Compiere.startupClient(); 154 155 158 int[] IDs = PO.getAllIDs ("AD_PrintPaper", null); 160 for (int i = 0; i < IDs.length; i++) 161 { 162 System.out.println("--"); 163 MPrintPaper pp = new MPrintPaper(Env.getCtx(), IDs[i]); 164 pp.dump(); 165 } 166 167 } 168 } | Popular Tags |