KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > print > MPrintPaper


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

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 /**
23  * AD_PrintPaper Print Paper Model
24  *
25  * @author Jorg Janke
26  * @version $Id: MPrintPaper.java,v 1.11 2003/07/06 18:43:01 jjanke Exp $
27  */

28 public class MPrintPaper extends X_AD_PrintPaper
29 {
30     /**
31      * Constructor
32      * @param ctx context
33      * @param AD_PrintPaper_ID ID if 0 A4
34      */

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     } // MPrintPaper
49

50     /*************************************************************************/
51
52     /**
53      * Get Media Size.
54      * The search is hard coded as the javax.print.MediaSize* info is private
55      * @return MediaSize from Code
56      */

57     public MediaSize getMediaSize()
58     {
59         String JavaDoc nameCode = getCode();
60         if (nameCode == null)
61             return getMediaSizeDefault();
62         // Get Name
63
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         // other media sizes come here
69

70         if (nameMedia == null)
71             return getMediaSizeDefault();
72         //
73
MediaSize retValue = MediaSize.getMediaSizeForName(nameMedia);
74         if (retValue == null)
75             retValue = getMediaSizeDefault();
76     // Log.trace(Log.l6_Database, "MPrintPaper.getMediaSize", retValue);
77
return retValue;
78     } // getMediaSize
79

80     /**
81      * Get Media Size
82      * @return Default Media Size based on Language
83      */

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     } // getMediaSizeDefault
92

93     /**
94      * Get CPaper
95      * @return CPaper
96      */

97     public CPaper getCPaper()
98     {
99         CPaper retValue = new CPaper (getMediaSize(), isLandscape(),
100             getMarginLeft(), getMarginTop(), getMarginRight(), getMarginBottom());
101         return retValue;
102     } // getCPaper
103

104     /*************************************************************************/
105
106     /**
107      * Create Paper and save
108      * @param name name
109      * @param landscape landscape
110      * @return Paper
111      */

112     static MPrintPaper create (String JavaDoc 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     } // create
120

121     /*************************************************************************/
122
123     /** Cached Fonts */
124     static private CCache s_papers = new CCache("printPaper", 5);
125
126     /**
127      * Get Paper
128      * @param AD_PrintPaper_ID id
129      * @return Paper
130      */

131     static public MPrintPaper get (int AD_PrintPaper_ID)
132     {
133         Integer JavaDoc key = new Integer JavaDoc(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     } // get
144

145     /*************************************************************************/
146
147     /**
148      * Test
149      * @param args args
150      */

151     public static void main(String JavaDoc[] args)
152     {
153         org.compiere.Compiere.startupClient();
154
155     // create ("Standard Landscape", true);
156
// create ("Standard Portrait", false);
157

158         // Read All Colors
159
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 } // MPrintPaper
169
Popular Tags