KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > print > layout > LayoutEngine


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.layout;
15
16 import java.awt.*;
17 import java.awt.print.*;
18 import java.awt.geom.*;
19 import java.util.*;
20 import java.sql.*;
21 import java.net.*;
22
23 import javax.print.*;
24 import javax.print.attribute.*;
25 import javax.print.attribute.standard.*;
26
27 import org.apache.log4j.Logger;
28
29 import org.compiere.model.*;
30 import org.compiere.print.*;
31 import org.compiere.util.DisplayType;
32 import org.compiere.util.NamePair;
33 import org.compiere.util.KeyNamePair;
34 import org.compiere.util.ValueNamePair;
35 import org.compiere.util.Env;
36 import org.compiere.util.Msg;
37 import org.compiere.util.Log;
38
39 /**
40  * Print Engine Abstract Class.
41  * All coordinates are relative to the Page.
42  * The Language setting is maintained in the format
43  *
44  * @author Jorg Janke
45  * @version $Id: LayoutEngine.java,v 1.43 2003/10/31 05:32:48 jjanke Exp $
46  */

47 public class LayoutEngine
48 {
49     /**
50      * Detail Constructor
51      * @param format Print Format
52      * @param data Print Data
53      * @param query query for parameter info
54      */

55     public LayoutEngine (MPrintFormat format, PrintData data, MQuery query)
56     {
57         log.info(format + " - " + data + " - " + query);
58         setPrintFormat(format, false);
59         setPrintData(data, query, false);
60         layout();
61     } // LayoutEngine
62

63
64     /*************************************************************************/
65
66     /** Logger */
67     private Logger log = Logger.getLogger (getClass());
68     /** Existing Layout */
69     private boolean m_hasLayout = false;
70     /** The Format */
71     private MPrintFormat m_format;
72     /** Print Context */
73     private Properties m_printCtx;
74     /** The Data */
75     private PrintData m_data;
76     /** The Query (parameter */
77     private MQuery m_query;
78     /** Default Color */
79     private MPrintColor m_printColor;
80     /** Default Font */
81     private MPrintFont m_printFont;
82     /** Printed Column Count */
83     private int m_columnCount = -1;
84
85
86     /** Paper - default: standard portrait */
87     private CPaper m_paper;
88     /** Header Area Height (1/4") */
89     private int m_headerHeight = 18; // 1/4" => 72/4
90
/** Footer Area Height (1/4") */
91     private int m_footerHeight = 18;
92
93
94     /** Current Page Number */
95     private int m_pageNo = 0;
96     /** Current Page */
97     private Page m_currPage;
98     /** Pages */
99     private ArrayList m_pages = new ArrayList();
100     /** Header&Footer for all pages */
101     private HeaderFooter m_headerFooter;
102
103
104     /** Header Coordinates */
105     private Rectangle m_header = new Rectangle ();
106     /** Content Coordinates */
107     private Rectangle m_content = new Rectangle();
108     /** Footer Coordinates */
109     private Rectangle m_footer = new Rectangle();
110     /** Temporary NL Position */
111     private int m_tempNLPositon = 0;
112
113     /** Header Area */
114     public static final int AREA_HEADER = 0;
115     /** Content Area */
116     public static final int AREA_CONTENT = 1;
117     /** Footer Area */
118     public static final int AREA_FOOTER = 2;
119     /** Area Pointer */
120     private int m_area = AREA_CONTENT;
121
122     /** Current Position in 1/72 inch */
123     private Point2D.Double[] m_position = new Point2D.Double[] {new Point2D.Double(0,0), new Point2D.Double(0,0), new Point2D.Double(0,0)};
124     /** Max Height Since New Line */
125     private float m_maxHeightSinceNewLine[] = new float[] {0f, 0f, 0f};
126     /** Current Font */
127     private Font m_font;
128     /** Current Paint */
129     private Paint m_paint;
130     /** Current Stroke */
131     private Stroke m_stroke;
132
133     /** Primary Table Element for Page XY Info */
134     private TableElement m_tableElement = null;
135
136     /*************************************************************************/
137
138     public static Image IMAGE_TRUE = null;
139     public static Image IMAGE_FALSE = null;
140     public static Dimension IMAGE_SIZE = new Dimension(10,10);
141
142     static {
143         Toolkit tk = Toolkit.getDefaultToolkit();
144         URL url = LayoutEngine.class.getResource("true10.gif");
145         if (url != null)
146             IMAGE_TRUE = tk.getImage(url);
147         url = LayoutEngine.class.getResource("false10.gif");
148         /** @todo load images via medialoader */
149         if (url != null)
150             IMAGE_FALSE = tk.getImage(url);
151     } // static init
152

153     /*************************************************************************/
154
155     /**
156      * Set Print Format
157      * Optionally re-calculate layout
158      * @param doLayout if layout exists, redo it
159      * @param format print Format
160      */

161     public void setPrintFormat (MPrintFormat format, boolean doLayout)
162     {
163         m_format = format;
164         // Initial & Default Settings
165
m_printCtx = new Properties(format.getCtx());
166
167         // Set Paper
168
boolean tempHasLayout = m_hasLayout;
169         m_hasLayout = false; // do not start re-calculation
170
MPrintPaper mPaper = MPrintPaper.get(format.getAD_PrintPaper_ID());
171         if (m_format.isStandardHeaderFooter())
172             setPaper(mPaper.getCPaper());
173         else
174             setPaper(mPaper.getCPaper(),
175                 m_format.getHeaderMargin(), m_format.getFooterMargin());
176         m_hasLayout = tempHasLayout;
177         //
178
m_printColor = MPrintColor.get(format.getAD_PrintColor_ID());
179         setPaint(m_printColor.getColor());
180         m_printFont = MPrintFont.get (format.getAD_PrintFont_ID());
181         setFont(m_printFont.getFont());
182         m_stroke = new BasicStroke (1.0f);
183
184         // Print Context
185
Env.setContext(m_printCtx, Page.CONTEXT_REPORTNAME, m_format.getName());
186         Env.setContext(m_printCtx, Page.CONTEXT_HEADER, Env.getHeader(m_printCtx, 0));
187         Env.setContext(m_printCtx, Env.LANG, m_format.getLanguage().getAD_Language());
188
189         if (m_hasLayout && doLayout)
190             layout(); // re-calculate
191
} // setPrintFormat
192

193     /**
194      * Set PrintData.
195      * Optionally re-calculate layout
196      * @param data data
197      * @param doLayout if layout exists, redo it
198      * @param query query for parameter
199      */

200     public void setPrintData (PrintData data, MQuery query, boolean doLayout)
201     {
202         m_data = data;
203         m_query = query;
204         if (m_hasLayout && doLayout)
205             layout(); // re-calculate
206
} // setPrintData
207

208     /*************************************************************************/
209
210     /**
211      * Set Paper
212      * @param paper Paper
213      */

214     public void setPaper (CPaper paper)
215     {
216         setPaper(paper, m_headerHeight, m_footerHeight);
217     } // setPaper
218

219     /**
220      * Set Paper
221      * Optionally re-calculate layout
222      * @param paper Paper
223      * @param headerHeight header height
224      * @param footerHeight footer height
225      */

226     public void setPaper (CPaper paper, int headerHeight, int footerHeight)
227     {
228         if (paper == null)
229             return;
230         //
231
boolean paperChange = headerHeight != m_headerHeight || footerHeight != m_footerHeight;
232         if (!paperChange)
233             paperChange = !paper.equals(m_paper);
234         //
235
log.debug("setPaper " + paper + " - Header=" + headerHeight + ", Footer=" + footerHeight);
236         m_paper = paper;
237         m_headerHeight = headerHeight;
238         m_footerHeight = footerHeight;
239         calculatePageSize();
240         //
241
if (m_hasLayout && paperChange)
242             layout(); // re-calculate
243
} // setPaper
244

245     /**
246      * Show Dialog and Set Paper
247      * Optionally re-calculate layout
248      * @param job printer job
249      */

250     public void pageSetupDialog (PrinterJob job)
251     {
252         log.info("pageSetupDialog");
253         if (m_paper.pageSetupDialog(job))
254         {
255             setPaper(m_paper);
256             layout();
257         }
258     } // pageSetupDialog
259

260     /**
261      * Set Paper from Page Format.
262      * PageFormat is derived from CPaper
263      * @param pf Optional PageFormat - if null standard paper Portrait
264      */

265     protected void setPageFormat (PageFormat pf)
266     {
267         if (pf != null)
268             setPaper(new CPaper(pf));
269         else
270             setPaper(null);
271     } // setPageFormat
272

273     /**
274      * Get Page Format
275      * @return page format
276      */

277     public PageFormat getPageFormat ()
278     {
279         return m_paper.getPageFormat();
280     } // getPageFormat
281

282     /**
283      * Calculate Page size based on Paper and header/footerHeight.
284      * <pre>
285      * Paper: 8.5x11.0" Portrait x=32.0,y=32.0 w=548.0,h=728.0
286      * +------------------------ Paper 612x792
287      * | non-imageable space 32x32
288      * | +--------------------- Header = printable area start
289      * | | headerHeight=32 => [x=32,y=32,width=548,height=32]
290      * | +--------------------- Content
291      * | | => [x=32,y=64,width=548,height=664]
292      * | |
293      * | |
294      * | |
295      * | +--------------------- Footer
296      * | | footerHeight=32 => [x=32,y=728,width=548,height=32]
297      * | +--------------------- Footer end = printable area end
298      * | non-imageable space
299      * +------------------------
300      * </pre>
301      */

302     private void calculatePageSize()
303     {
304         int x = (int)m_paper.getImageableX (true);
305         int w = (int)m_paper.getImageableWidth (true);
306         //
307
int y = (int)m_paper.getImageableY (true);
308         int h = (int)m_paper.getImageableHeight (true);
309
310         int height = m_headerHeight;
311         m_header.setBounds (x, y, w, height);
312         //
313
y += height;
314         height = h-m_headerHeight-m_footerHeight;
315         m_content.setBounds (x, y, w, height);
316         //
317
y += height;
318         height = m_footerHeight;
319         m_footer.setBounds (x, y, w, height);
320
321         log.debug ("calulatePaperSize - Paper=" + m_paper + ",HeaderHeight=" + m_headerHeight + ",FooterHeight=" + m_footerHeight
322             + " => Header=" + m_header + ",Contents=" + m_content + ",Footer=" + m_footer);
323     } // calculatePageSize
324

325     /**
326      * Set Paper
327      * @return Paper
328      */

329     public CPaper getPaper()
330     {
331         return m_paper;
332     } // getPaper
333

334     /*************************************************************************/
335
336     /**
337      * Create Layout
338      */

339     private void layout()
340     {
341         log.debug("layout");
342
343         // Header/Footer
344
m_headerFooter = new HeaderFooter(m_printCtx);
345         if (!m_format.isForm() && m_format.isStandardHeaderFooter())
346             createStandardHeaderFooter();
347         //
348
m_pageNo = 0;
349         m_pages.clear();
350         m_tableElement = null;
351         newPage();
352         //
353
if (m_format.isForm())
354             layoutForm();
355         else
356         {
357             // Parameter
358
PrintElement element = layoutParameter();
359             if (element != null)
360             {
361                 m_currPage.addElement (element);
362                 element.setLocation(m_position[AREA_CONTENT]);
363                 m_position[AREA_CONTENT].y += element.getHeight() + 5; // GAP
364
}
365             // Table
366
element = layoutTable(m_format, m_data, 0);
367             element.setLocation(m_content.getLocation());
368             for (int p = 1; p <= element.getPageCount(); p++)
369             {
370                 if (p != 1)
371                     newPage();
372                 m_currPage.addElement (element);
373             }
374         }
375         //
376
String JavaDoc pageInfo = String.valueOf(m_pages.size()) + getPageInfo(m_pages.size());
377         Env.setContext(m_printCtx, Page.CONTEXT_PAGECOUNT, pageInfo);
378         Timestamp now = new Timestamp(System.currentTimeMillis());
379         Env.setContext(m_printCtx, Page.CONTEXT_DATE,
380             DisplayType.getDateFormat(DisplayType.Date).format(now));
381         Env.setContext(m_printCtx, Page.CONTEXT_TIME,
382             DisplayType.getDateFormat(DisplayType.DateTime).format(now));
383         // Update Page Info
384
int pages = m_pages.size();
385         for (int i = 0; i < pages; i++)
386         {
387             Page page = (Page)m_pages.get(i);
388             int pageNo = page.getPageNo();
389             pageInfo = String.valueOf(pageNo) + getPageInfo(pageNo);
390             page.setPageInfo(pageInfo);
391             page.setPageCount(pages);
392         }
393
394
395         m_hasLayout = true;
396     } // layout
397

398     /*************************************************************************/
399
400     /**
401      * Get PrintLayout (Report) Context
402      * @return context
403      */

404     public Properties getCtx()
405     {
406         return m_printCtx;
407     } // getCtx
408

409     /**
410      * Get the number of printed Columns
411      * @return np of printed columns
412      */

413     public int getColumnCount()
414     {
415         return m_columnCount;
416     } // getColumnCount
417

418     /**
419      * Set the current Print Area
420      * @param area see HEADER_.. constants
421      */

422     protected void setArea (int area)
423     {
424         if (m_area == area)
425             return;
426         if (area < 0 || area > 2)
427             throw new ArrayIndexOutOfBoundsException JavaDoc (area);
428         m_area = area;
429     } // setArea
430

431     /**
432      * Get the current Print Area
433      * @return area see HEADER_.. constants
434      */

435     public int getArea ()
436     {
437         return m_area;
438     } // getArea
439

440     /**
441      * Return bounds of current Area
442      * @return rectangle with bounds
443      */

444     public Rectangle getAreaBounds()
445     {
446         Rectangle part = m_content;
447         if (m_area == AREA_HEADER)
448             part = m_header;
449         else if (m_area == AREA_FOOTER)
450             part = m_footer;
451         //
452
return part;
453     } // getAreaBounds
454

455     /*************************************************************************/
456
457     /**
458      * Create New Page, set position to top content
459      * @return new page no
460      */

461     protected int newPage()
462     {
463         m_pageNo++;
464         m_currPage = new Page (m_printCtx, m_pageNo);
465         m_pages.add(m_currPage);
466         //
467
m_position[AREA_HEADER].setLocation(m_header.x, m_header.y);
468         m_position[AREA_CONTENT].setLocation(m_content.x, m_content.y);
469         m_position[AREA_FOOTER].setLocation(m_footer.x, m_footer.y);
470         m_maxHeightSinceNewLine = new float[] {0f, 0f, 0f};;
471         log.debug("newPage - Page=" + m_pageNo);
472         return m_pageNo;
473     } // newPage
474

475     /**
476      * Move to New Line (may cause new page)
477      */

478     protected void newLine ()
479     {
480         Rectangle part = m_content;
481         if (m_area == AREA_HEADER)
482             part = m_header;
483         else if (m_area == AREA_FOOTER)
484             part = m_footer;
485
486         // Temporary NL Position
487
int xPos = part.x;
488         if (m_tempNLPositon != 0)
489             xPos = m_tempNLPositon;
490
491         if (isYspaceFor(m_maxHeightSinceNewLine[m_area]))
492         {
493             m_position[m_area].setLocation(xPos, m_position[m_area].y + m_maxHeightSinceNewLine[m_area]);
494             if (Log.isTraceLevel(10))
495                 log.debug("newLine - Page=" + m_pageNo + " [" + m_area + "] " + m_position[m_area].x + "/" + m_position[m_area].y);
496         }
497         else if (m_area == AREA_CONTENT)
498             newPage();
499         else // footer/header
500
{
501             m_position[m_area].setLocation(part.x, m_position[m_area].y + m_maxHeightSinceNewLine[m_area]);
502             log.error("newLine - Outside of Area(" + m_area + "): " + m_position[m_area]);
503         }
504         m_maxHeightSinceNewLine[m_area] = 0f;
505     } // newLine
506

507
508     /**
509      * Get current Page Number (not zero based)
510      * @return Page No
511      */

512     public int getPageNo()
513     {
514         return m_pageNo;
515     } // getPageNo
516

517     /**
518      * Get Page No
519      * @param pageNo page number (NOT zero based)
520      * @return Page
521      */

522     public Page getPage (int pageNo)
523     {
524         if (pageNo <= 0 || pageNo > m_pages.size())
525         {
526             log.error("getPage - No page #" + pageNo);
527             return null;
528         }
529         Page retValue = (Page)m_pages.get(pageNo-1);
530         return retValue;
531     } // getPage
532

533     /**
534      * Het Page Count
535      * @return Page Count
536      */

537     public int getPageCount ()
538     {
539         return m_pages.size();
540     } // getPageCount
541

542
543     /**
544      * Get Pages
545      * @return Pages in ArrayList
546      */

547     public ArrayList getPages()
548     {
549         return m_pages;
550     } // getPages
551

552     /**
553      * Get Header & Footer info
554      * @return Header&Footer
555      */

556     public HeaderFooter getHeaderFooter()
557     {
558         return m_headerFooter;
559     } // getPages
560

561     /**
562      * Set Current page to Page No
563      * @param pageNo page number (NOT zero based)
564      */

565     protected void setPage (int pageNo)
566     {
567         if (pageNo <= 0 || pageNo > m_pages.size())
568         {
569             log.error("setPage - No page #" + pageNo);
570             return;
571         }
572         Page retValue = (Page)m_pages.get(pageNo-1);
573         m_currPage = retValue;
574     } // setPage
575

576     /**
577      * Get Page Info for Multi-Page tables
578      * @param pageNo page
579      * @return info e.g. (1,1)
580      */

581     public String JavaDoc getPageInfo(int pageNo)
582     {
583         if (m_tableElement == null || m_tableElement.getPageXCount() == 1)
584             return "";
585         int pi = m_tableElement.getPageIndex(pageNo);
586         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("(");
587         sb.append(m_tableElement.getPageYIndex(pi)+1).append(",")
588             .append(m_tableElement.getPageXIndex(pi)+1).append(")");
589         return sb.toString();
590     } // getPageInfo
591

592     /**
593      * Get Max Page Info for Multi-Page tables
594      * @return info e.g. (3,2)
595      */

596     public String JavaDoc getPageInfoMax()
597     {
598         if (m_tableElement == null || m_tableElement.getPageXCount() == 1)
599             return "";
600         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("(");
601         sb.append(m_tableElement.getPageYCount()).append(",")
602             .append(m_tableElement.getPageXCount()).append(")");
603         return sb.toString();
604     } // getPageInfoMax
605

606     /*************************************************************************/
607
608     /**
609      * Set Position on current page (no check)
610      * @param p point relative in area
611      */

612     protected void setRelativePosition (Point2D p)
613     {
614         if (p == null)
615             return;
616         Rectangle part = m_content;
617         if (m_area == AREA_HEADER)
618             part = m_header;
619         else if (m_area == AREA_FOOTER)
620             part = m_footer;
621         m_position[m_area].setLocation(part.x + p.getX(), part.y + p.getY());
622         if (Log.isTraceLevel(10))
623             log.debug("setPosition - Page=" + m_pageNo + " [" + m_area + "] " + m_position[m_area].x + "/" + m_position[m_area].y);
624     } // setPosition
625

626     /**
627      * Set Position on current page (no check)
628      * @param x x position in 1/72 inch
629      * @param y y position in 1/72 inch
630      */

631     protected void setRelativePosition (float x, float y)
632     {
633         setRelativePosition(new Point2D.Float(x, y));
634     } // setPosition
635

636     /**
637      * Get the current position on current page
638      * @return current position
639      */

640     public Point2D getPosition ()
641     {
642         return m_position[m_area];
643     } // getPosition
644

645     /**
646      * Set X Position on current page
647      * @param x x position in 1/72 inch
648      */

649     protected void setX (float x)
650     {
651         m_position[m_area].x = x;
652         if (Log.isTraceLevel(10))
653             log.debug("setX - Page=" + m_pageNo + " [" + m_area + "] " + m_position[m_area].x + "/" + m_position[m_area].y);
654     } // setX
655

656     /**
657      * Add to X Position on current page
658      * @param xOffset add offset to x position in 1/72 inch
659      */

660     protected void addX (float xOffset)
661     {
662         if (xOffset == 0f)
663             return;
664         m_position[m_area].x += xOffset;
665         if (Log.isTraceLevel(10))
666             log.debug("addX - Page=" + m_pageNo + " [" + m_area + "] " + m_position[m_area].x + "/" + m_position[m_area].y);
667     } // addX
668

669     /**
670      * Get X Position on current page
671      * @return x position in 1/72 inch
672      */

673     public float getX ()
674     {
675         return (float)m_position[m_area].x;
676     } // getX
677

678     /**
679      * Set Y Position on current page
680      * @param y y position in 1/72 inch
681      */

682     protected void setY (int y)
683     {
684         m_position[m_area].y = y;
685         if (Log.isTraceLevel(10))
686             log.debug("setY - Page=" + m_pageNo + " [" + m_area + "] " + m_position[m_area].x + "/" + m_position[m_area].y);
687     } // setY
688

689     /**
690      * Add to Y Position - may cause New Page
691      * @param yOffset add offset to y position in 1/72 inch
692      */

693     protected void addY (int yOffset)
694     {
695         if (yOffset == 0f)
696             return;
697         if (isYspaceFor(yOffset))
698         {
699             m_position[m_area].y += yOffset;
700             if (Log.isTraceLevel(10))
701                 log.debug("addY - Page=" + m_pageNo + " [" + m_area + "] " + m_position[m_area].x + "/" + m_position[m_area].y);
702         }
703         else if (m_area == AREA_CONTENT)
704             newPage();
705         else
706         {
707             m_position[m_area].y += yOffset;
708             log.error("addY - Outside of Area: " + m_position);
709         }
710     } // addY
711

712     /**
713      * Get Y Position on current page
714      * @return y position in 1/72 inch
715      */

716     public float getY ()
717     {
718         return (float)m_position[m_area].y;
719     } // getY
720

721     /*************************************************************************/
722
723     /**
724      * Return remaining X dimension space _ on current page in Area
725      * @return space in 1/72 inch remaining in line
726      */

727     public float getXspace()
728     {
729         Rectangle part = m_content;
730         if (m_area == AREA_HEADER)
731             part = m_header;
732         else if (m_area == AREA_FOOTER)
733             part = m_footer;
734         //
735
return (float)(part.x + part.width - m_position[m_area].x);
736     } // getXspace
737

738     /**
739      * Remaining Space is OK for Width in Area
740      * @param width width
741      * @return true if width fits in area
742      */

743     public boolean isXspaceFor (float width)
744     {
745         return (getXspace()-width) > 0f;
746     } // isXspaceFor
747

748     /**
749      * Return remaining Y dimension space | on current page in Area
750      * @return space in 1/72 inch remaining on page
751      */

752     public float getYspace()
753     {
754         Rectangle part = m_content;
755         if (m_area == AREA_HEADER)
756             part = m_header;
757         else if (m_area == AREA_FOOTER)
758             part = m_footer;
759         //
760
return (float)(part.y + part.height - m_position[m_area].y);
761     } // getYspace
762

763     /**
764      * Remaining Space is OK for Height in Area
765      * @param height height
766      * @return true if height fits in area
767      */

768     public boolean isYspaceFor (float height)
769     {
770         return (getYspace()-height) > 0f;
771     } // isYspaceFor
772

773     /*************************************************************************/
774
775     /**
776      * Set Current Font
777      * @param font font
778      */

779     protected void setFont (Font font)
780     {
781         if (font != null)
782             m_font = font;
783     } // setFont
784

785     /**
786      * Get current Font
787      * @return font
788      */

789     public Font getFont()
790     {
791         return m_font;
792     } // setFont
793

794     /**
795      * Set Current Font Name
796      * @param name font name like Dialog, DialogInput, Monospaced, Serif, or SansSerif
797      */

798     protected void setFontName (String JavaDoc name)
799     {
800         m_font = new Font(name, m_font.getStyle(), m_font.getSize());
801     } // setFontSize
802

803     /**
804      * Set Current Font Style
805      * @param style font style - Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD|Font.ITALIC
806      */

807     protected void setFontStyle (int style)
808     {
809         m_font = new Font(m_font.getName(), style, m_font.getSize());
810     } // setFontStyle
811

812     /**
813      * Set Current Font Size
814      * @param size font size in points
815      */

816     protected void setFontSize (int size)
817     {
818         m_font = new Font(m_font.getName(), m_font.getStyle(), size);
819     } // setFontSize
820

821     /*************************************************************************/
822
823     /**
824      * Set Current Foreground Paint
825      * @param paint Color, GardientPaint, TexturePaint
826      */

827     protected void setPaint (Paint paint)
828     {
829         if (paint != null)
830             m_paint = paint;
831     } // setPaint
832

833     /**
834      * Get Current Foreground Paint
835      * @return Color, GardientPaint, TexturePaint
836      */

837     public Paint getPaint ()
838     {
839         return m_paint;
840     } // getPaint
841

842     /**
843      * Set the alpha value (transparency) of a color - if the current paint is a Color.
844      * An alpha value of 255 means that the color is completely opaque
845      * and an alpha value of 0 means that the color is completely transparent.
846      * @param alpha 0 - 255
847      */

848     protected void setPaintAlpha (int alpha)
849     {
850         if (m_paint instanceof Color)
851         {
852             Color c = (Color)m_paint;
853             m_paint = new Color (c.getRed(), c.getGreen(), c.getBlue(), alpha);
854         }
855     } // setPaintAlpha
856

857     /*************************************************************************/
858
859     /**
860      * Set Current Stroke
861      * @param stroke Stroke
862      */

863     protected void setStroke (Stroke stroke)
864     {
865         if (stroke != null)
866             m_stroke = stroke;
867     } // setStroke
868

869     /**
870      * Get Current Stroke
871      * @return Stroke
872      */

873     public Stroke getStroke()
874     {
875         return m_stroke;
876     } // setStroke
877

878     /*************************************************************************/
879
880     /**
881      * Create Standard Header/Footer
882      * <pre>
883      * title C Page x of x
884      * Copyright who date&time
885      * </pre>
886      */

887     private void createStandardHeaderFooter()
888     {
889     // element = new ImageElement(org.compiere.Compiere.getImageLogo()); // 100x30
890
PrintElement element = new ImageElement(org.compiere.Compiere.getImageLogoSmall()); // 48x15
891
element.layout(m_header.width, 0, false, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
892         element.setLocation(m_header.getLocation());
893         m_headerFooter.addElement(element);
894         //
895
MPrintTableFormat tf = m_format.getTableFormat();
896         Font font = tf.getPageHeader_Font();
897         Color color = tf.getPageHeaderFG_Color();
898         //
899
element = new StringElement("@*ReportName@", font, color, null, true);
900         element.layout (m_header.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_Center);
901         element.setLocation(m_header.getLocation());
902         m_headerFooter.addElement(element);
903         //
904
//
905
element = new StringElement("@Page@ @*Page@ @of@ @*PageCount@", font, color, null, true);
906         element.layout (m_header.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight);
907         element.setLocation(m_header.getLocation());
908         m_headerFooter.addElement(element);
909
910         // Footer
911
font = tf.getPageFooter_Font();
912         color = tf.getPageFooterFG_Color();
913         //
914
element = new StringElement("@CopyRight@", font, color, null, true);
915         element.layout (m_footer.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
916         Point ft = m_footer.getLocation();
917         ft.y += m_footer.height - element.getHeight() - 2; // 2pt above min
918
element.setLocation(ft);
919         m_headerFooter.addElement(element);
920         //
921
element = new StringElement("@*Header@", font, color, null, true);
922         element.layout (m_footer.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_Center);
923         element.setLocation(ft);
924         m_headerFooter.addElement(element);
925         //
926
element = new StringElement("@*CurrentDateTime@", font, color, null, true);
927         element.layout (m_footer.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight);
928         element.setLocation(ft);
929         m_headerFooter.addElement(element);
930     } // createStandardHeaderFooter
931

932     /*************************************************************************/
933
934     /**
935      * Layout Form.
936      * For every Row, loop through the Format
937      * and calculate element size and position.
938      */

939     private void layoutForm()
940     {
941         log.info("layoutForm");
942         m_columnCount = 0;
943         float lastHeight[] = new float[] {0f, 0f, 0f};
944         float lastWidth[] = new float[] {0f, 0f, 0f};
945         // for every row
946
for (int row = 0; row < m_data.getRowCount(); row++)
947         {
948             log.debug("layoutForm - Row=" + row);
949             m_data.setRowIndex(row);
950             boolean somethingPrinted = true; // prevent NL of nothing printed and supress null
951
// for every item
952
for (int i = 0; i < m_format.getItemCount(); i++)
953             {
954                 MPrintFormatItem item = m_format.getItem(i);
955                 if (!item.isPrinted())
956                     continue;
957                 m_columnCount++;
958                 // Read Header/Footer just once
959
if (row > 0 && (item.isHeader() || item.isFooter()))
960                     continue;
961                 // Position
962
if (item.isHeader()) // Area
963
setArea(AREA_HEADER);
964                 else if (item.isFooter())
965                     setArea(AREA_FOOTER);
966                 else
967                     setArea(AREA_CONTENT);
968                 //
969
if (item.isSetNLPosition() && item.isRelativePosition())
970                     m_tempNLPositon = 0;
971                 if (item.isNextPage()) // item.isPageBreak() // new page
972
newPage();
973                 else if (item.isNextLine() && somethingPrinted) // new line
974
{
975                     newLine ();
976                     somethingPrinted = false;
977                 }
978                 else
979                     addX(lastWidth[m_area]);
980                 if (item.isRelativePosition())
981                 {
982                     addX(item.getXspace());
983                     addY(item.getYspace());
984                 }
985                 else // Absolute relative position
986
setRelativePosition(item.getXposition(), item.getYposition());
987                 // Temporary NL Position when absolute positioned
988
if (item.isSetNLPosition() && !item.isRelativePosition())
989                     m_tempNLPositon = (int)getPosition().getX();
990
991                 // line alignment
992
String JavaDoc alignment = item.getFieldAlignmentType();
993                 int maxWidth = item.getMaxWidth();
994                 boolean lineAligned = false;
995                 if (item.isRelativePosition())
996                 {
997                     if (item.isLineAlignLeading())
998                     {
999                         alignment = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
1000                        maxWidth = getAreaBounds().width;
1001                        lineAligned = true;
1002                    }
1003                    else if (item.isLineAlignCenter())
1004                    {
1005                        alignment = MPrintFormatItem.FIELDALIGNMENTTYPE_Center;
1006                        maxWidth = getAreaBounds().width;
1007                        lineAligned = true;
1008                    }
1009                    else if (item.isLineAlignTrailing())
1010                    {
1011                        alignment = MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight;
1012                        maxWidth = getAreaBounds().width;
1013                        lineAligned = true;
1014                    }
1015                }
1016
1017                // Type
1018
PrintElement element = null;
1019                if (item.isTypePrintFormat()) //** PrintFormat
1020
{
1021                    newLine();
1022                    try
1023                    {
1024                        MPrintFormat format = MPrintFormat.get (item.getAD_PrintFormatChild_ID(), false);
1025                        format.setLanguage(m_format.getLanguage());
1026                        if (m_format.isTranslationView())
1027                            format.setTranslationLanguage(m_format.getLanguage());
1028                        log.info("layoutForm - include Format " + format + " - Item=" + item.getName());
1029                        //
1030
int AD_Column_ID = item.getAD_Column_ID();
1031                        Object JavaDoc obj = m_data.getNode(new Integer JavaDoc(AD_Column_ID));
1032                    // Object obj = m_data.getNode(item.getColumnName()); // slower
1033
PrintDataElement data = (PrintDataElement)obj;
1034                        int Record_ID = Integer.parseInt(data.getValueKey());
1035                        MQuery query = new MQuery (format.getAD_Table_ID());
1036                        query.addRestriction(item.getColumnName(), MQuery.EQUAL, new Integer JavaDoc(Record_ID));
1037                        format.setTranslationViewQuery(query);
1038                        log.debug("layoutForm - include " + query);
1039                        //
1040
DataEngine de = new DataEngine(format.getLanguage());
1041                        PrintData printData = de.getPrintData(m_data.getCtx(), format, query);
1042                        log.debug("layoutForm - include " + printData);
1043                        //
1044
element = layoutTable (format, printData, item.getXspace());
1045                        // handle multi page tables
1046
if (element.getPageCount() > 1)
1047                        {
1048                            Point2D.Double loc = m_position[m_area];
1049                            element.setLocation(loc);
1050                            for (int p = 1; p < element.getPageCount(); p++) // don't add last one
1051
{
1052                                m_currPage.addElement (element);
1053                                newPage();
1054                            }
1055                            m_position[m_area] = loc;
1056                            ((TableElement)element).setHeightToLastPage();
1057                        }
1058                    }
1059                    catch (Exception JavaDoc e)
1060                    {
1061                        log.error("layoutForm", e);
1062                    }
1063                    if (element == null)
1064                        log.error("layoutForm - No included Format");
1065                }
1066                else if (item.isTypeImage()) //** Image
1067
{
1068                    if (item.isImageIsAttached())
1069                        element = new ImageElement(item.getID());
1070                    else
1071                        element = new ImageElement(item.getImageURL());
1072                    element.layout(maxWidth, item.getMaxHeight(), false, alignment);
1073                }
1074                else if (item.isTypeField()) //** Field
1075
{
1076                    if (maxWidth == 0 && item.isFieldAlignBlock())
1077                        maxWidth = getAreaBounds().width;
1078                    element = createFieldElement (item, maxWidth, alignment, m_format.isForm());
1079                }
1080                else // (item.isTypeText()) //** Text
1081
{
1082                    if (maxWidth == 0 && item.isFieldAlignBlock())
1083                        maxWidth = getAreaBounds().width;
1084                    element = createStringElement (item.getPrintName (m_format.getLanguage ()),
1085                        item.getAD_PrintColor_ID (), item.getAD_PrintFont_ID (),
1086                        maxWidth, item.getMaxHeight (), item.isHeightOneLine (), alignment, true);
1087                }
1088                //
1089
if (element != null)
1090                {
1091                    somethingPrinted = true;
1092                    if (!lineAligned)
1093                        lastWidth[m_area] = element.getWidth();
1094                    lastHeight[m_area] = element.getHeight();
1095                }
1096                else
1097                {
1098                    somethingPrinted = false;
1099                    lastWidth[m_area] = 0f;
1100                    lastHeight[m_area] = 0f;
1101                }
1102
1103                // Does it fit?
1104
if (item.isRelativePosition() && !lineAligned)
1105                {
1106                    if (!isXspaceFor(lastWidth[m_area]))
1107                    {
1108                        if (Log.isTraceLevel(9))
1109                            log.debug("layoutForm - new Line - not enough X space for "
1110                                + lastWidth[m_area] + " - remaining " + getXspace() + " - Area=" + m_area);
1111                        newLine ();
1112                    }
1113                    if (m_area == AREA_CONTENT && !isYspaceFor(lastHeight[m_area]))
1114                    {
1115                        if (Log.isTraceLevel(9))
1116                            log.debug("layoutForm - new Page - not enough Y space "
1117                                + lastHeight[m_area] + " - remaining " + getXspace() + " - Area=" + m_area);
1118                        newPage ();
1119                    }
1120                }
1121                // We know Position and Size
1122
// Log.trace(Log.l6_Database, "LayoutEngine.layoutForm",
1123
// "Page=" + m_pageNo + " [" + m_area + "] " + m_position[m_area].x + "/" + m_position[m_area].y
1124
// + " w=" + lastWidth[m_area] + ",h=" + lastHeight[m_area] + " " + item);
1125
if (element != null)
1126                    element.setLocation(m_position[m_area]);
1127                // Add to Area
1128
if (m_area == AREA_CONTENT)
1129                    m_currPage.addElement (element);
1130                else
1131                    m_headerFooter.addElement (element);
1132                //
1133
if (lastHeight[m_area] > m_maxHeightSinceNewLine[m_area])
1134                    m_maxHeightSinceNewLine[m_area] = lastHeight[m_area];
1135
1136            } // for every item
1137
} // for every row
1138
} // layoutForm
1139

1140    /**
1141     * Create String Element
1142     *
1143     * @param content string to be printed
1144     * @param AD_PrintColor_ID color
1145     * @param AD_PrintFont_ID font
1146     * @param maxWidth max width
1147     * @param maxHeight max height
1148     * @param isHeightOneLine onle line only
1149     * @param FieldAlignmentType alignment type (MPrintFormatItem.FIELD_ALIGN_*)
1150     * @param isTranslated if true and content contaiins @variable@, it is dynamically translated during print
1151     * @return Print Element
1152     */

1153    private PrintElement createStringElement (String JavaDoc content, int AD_PrintColor_ID, int AD_PrintFont_ID,
1154        int maxWidth, int maxHeight, boolean isHeightOneLine, String JavaDoc FieldAlignmentType, boolean isTranslated)
1155    {
1156        // Color / Font
1157
Color color = m_printColor.getColor(); // default
1158
if (AD_PrintColor_ID != 0 && m_printColor.getID() != AD_PrintColor_ID)
1159        {
1160            MPrintColor c = MPrintColor.get (AD_PrintColor_ID);
1161            if (c.getColor() != null)
1162                color = c.getColor();
1163        }
1164        Font font = m_printFont.getFont(); // default
1165
if (AD_PrintFont_ID != 0 && m_printFont.getID() != AD_PrintFont_ID)
1166        {
1167            MPrintFont f = MPrintFont.get (AD_PrintFont_ID);
1168            if (f.getFont() != null)
1169                font = f.getFont();
1170        }
1171        PrintElement e = new StringElement(content, font, color, null, isTranslated);
1172        e.layout (maxWidth, maxHeight, isHeightOneLine, FieldAlignmentType);
1173        return e;
1174    } // createStringElement
1175

1176    /**
1177     * Create Field Element
1178     * @param item Format Item
1179     * @param maxWidth max width
1180     * @param FieldAlignmentType alignment type (MPrintFormatItem.FIELD_ALIGN_*)
1181     * @param isForm true if document
1182     * @return Print Element or null if nothing to print
1183     */

1184    private PrintElement createFieldElement (MPrintFormatItem item, int maxWidth,
1185        String JavaDoc FieldAlignmentType, boolean isForm)
1186    {
1187        // Get Data
1188
Object JavaDoc obj = m_data.getNode(new Integer JavaDoc(item.getAD_Column_ID()));
1189        if (obj == null)
1190            return null;
1191        else if (obj instanceof PrintDataElement)
1192            ;
1193        else
1194        {
1195            log.error("createFieldElement - Element not PrintDataElement " + obj.getClass());
1196            return null;
1197        }
1198
1199        // Convert DataElement to String
1200
PrintDataElement data = (PrintDataElement)obj;
1201        if (data.isNull() && item.isSuppressNull())
1202            return null;
1203        String JavaDoc stringContent = data.getValueDisplay (m_format.getLanguage());
1204        if ((stringContent == null || stringContent.length() == 0) && item.isSuppressNull())
1205            return null;
1206        Object JavaDoc content = stringContent;
1207        if (data.getValue() instanceof Boolean JavaDoc)
1208            content = data.getValue();
1209        // Convert AmtInWords Content to alpha
1210
if (item.getColumnName().equals("AmtInWords"))
1211        {
1212            String JavaDoc amtInWords = Msg.getAmtInWords (m_format.getLanguage(), stringContent);
1213            log.debug("createFieldElement - AmtInWords: " + content);
1214            content = amtInWords;
1215        }
1216        // Label
1217
String JavaDoc label = item.getPrintName(m_format.getLanguage());
1218        String JavaDoc labelSuffix = item.getPrintNameSuffix(m_format.getLanguage());
1219
1220        // ID Type
1221
NamePair ID = null;
1222        if (data.isID())
1223        { // Record_ID/ColumnName
1224
Object JavaDoc value = data.getValue();
1225            if (value instanceof KeyNamePair)
1226                ID = new KeyNamePair(((KeyNamePair)value).getKey(), item.getColumnName());
1227            else if (value instanceof ValueNamePair)
1228                ID = new ValueNamePair(((ValueNamePair)value).getValue(), item.getColumnName());
1229        }
1230        else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Default.equals(FieldAlignmentType))
1231        {
1232            if (data.isNumeric())
1233                FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight;
1234            else
1235                FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
1236        }
1237
1238        // Get Color/ Font
1239
Color color = m_printColor.getColor(); // default
1240
if (ID != null && !isForm)
1241            ; // link color/underline handeled in PrintElement classes
1242
else if (item.getAD_PrintColor_ID() != 0 && m_printColor.getID() != item.getAD_PrintColor_ID())
1243        {
1244            MPrintColor c = MPrintColor.get (item.getAD_PrintColor_ID());
1245            if (c.getColor() != null)
1246                color = c.getColor();
1247        }
1248
1249        Font font = m_printFont.getFont(); // default
1250
if (item.getAD_PrintFont_ID() != 0 && m_printFont.getID() != item.getAD_PrintFont_ID())
1251        {
1252            MPrintFont f = MPrintFont.get (item.getAD_PrintFont_ID());
1253            if (f.getFont() != null)
1254                font = f.getFont();
1255        }
1256
1257
1258        PrintElement e = null;
1259        if (data.getDisplayType() == DisplayType.Location)
1260        {
1261            e = new LocationElement(m_printCtx, ((KeyNamePair)ID).getKey(), font, color);
1262            e.layout (maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
1263        }
1264        else
1265        {
1266            e = new StringElement(content, font, color, isForm ? null : ID, label, labelSuffix);
1267            e.layout (maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
1268        }
1269        return e;
1270    } // createFieldElement
1271

1272
1273    /*************************************************************************/
1274
1275    /**
1276     * Layout Table.
1277     * Convert PrintData into TableElement
1278     * @param format format to use
1279     * @param printData data to use
1280     * @param xOffset X Axis - offset (start of table) i.e. indentation
1281     * @return TableElement
1282     */

1283    private PrintElement layoutTable (MPrintFormat format, PrintData printData,
1284        int xOffset)
1285    {
1286        log.debug("layoutTable " + format.getName() + " - " + printData.getName());
1287        MPrintTableFormat tf = format.getTableFormat();
1288        // Initial Values
1289
HashMap rowColFont = new HashMap();
1290        MPrintFont printFont = MPrintFont.get (format.getAD_PrintFont_ID());
1291        rowColFont.put(new Point(TableElement.ALL,TableElement.ALL), printFont.getFont());
1292        tf.setStandard_Font(printFont.getFont());
1293        rowColFont.put(new Point(TableElement.HEADER_ROW,TableElement.ALL), tf.getHeader_Font());
1294        //
1295
HashMap rowColColor = new HashMap();
1296        MPrintColor printColor = MPrintColor.get (format.getAD_PrintColor_ID());
1297        rowColColor.put(new Point(TableElement.ALL,TableElement.ALL), printColor.getColor());
1298        rowColColor.put(new Point(TableElement.HEADER_ROW,TableElement.ALL), tf.getHeaderFG_Color());
1299        //
1300
HashMap rowColBackground = new HashMap();
1301        rowColBackground.put(new Point(TableElement.HEADER_ROW,TableElement.ALL), tf.getHeaderBG_Color());
1302        // Sizes
1303
boolean multiLineHeader = false;
1304        int pageNoStart = m_pageNo;
1305        int repeatedColumns = 1;
1306        Rectangle firstPage = new Rectangle(m_content);
1307        firstPage.x += xOffset;
1308        firstPage.width -= xOffset;
1309        int yOffset = (int)m_position[AREA_CONTENT].y - m_content.y;
1310        firstPage.y += yOffset;
1311        firstPage.height -= yOffset;
1312        Rectangle nextPages = new Rectangle(m_content);
1313        nextPages.x += xOffset;
1314        nextPages.width -= xOffset;
1315        // Column count
1316
m_columnCount = 0;
1317        for (int c = 0; c < format.getItemCount(); c++)
1318        {
1319            if (format.getItem(c).isPrinted())
1320                m_columnCount++;
1321        }
1322        // System.out.println("Cols=" + cols);
1323

1324        // Header & Column Setup
1325
ValueNamePair[] columnHeader = new ValueNamePair[m_columnCount];
1326        int[] columnMaxWidth = new int[m_columnCount];
1327        int[] columnMaxHeight = new int[m_columnCount];
1328        boolean[] fixedWidth = new boolean [m_columnCount];
1329        String JavaDoc[] columnJustification = new String JavaDoc[m_columnCount];
1330        HashMap additionalLines = new HashMap();
1331
1332        int col = 0;
1333        for (int c = 0; c < format.getItemCount(); c++)
1334        {
1335            MPrintFormatItem item = format.getItem(c);
1336            if (item.isPrinted())
1337            {
1338                if (item.isNextLine() && item.getBelowColumn() != 0)
1339                {
1340                    additionalLines.put(new Integer JavaDoc(col), new Integer JavaDoc(item.getBelowColumn()-1));
1341                    item.setIsSuppressNull(true); // display size will be set to 0 in TableElement
1342
}
1343                columnHeader[col] = new ValueNamePair(item.getColumnName(),
1344                    item.getPrintName(format.getLanguage()));
1345                columnMaxWidth[col] = item.getMaxWidth();
1346                fixedWidth[col] = (columnMaxWidth[col] != 0 && item.isFixedWidth());
1347                if (item.isSuppressNull())
1348                {
1349                    if (columnMaxWidth[col] == 0)
1350                        columnMaxWidth[col] = -1; // indication suppress if Null
1351
else
1352                        columnMaxWidth[col] *= -1;
1353                }
1354                columnMaxHeight[col] = item.getMaxHeight();
1355                columnJustification[col] = item.getFieldAlignmentType();
1356                if (columnJustification[col] == null || columnJustification[col].equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Default))
1357                    columnJustification[col] = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft; // when generated sets correct alignment
1358
// Column Fonts
1359
if (item.getAD_PrintFont_ID() != 0 && item.getAD_PrintFont_ID() != format.getAD_PrintFont_ID())
1360                {
1361                    MPrintFont font = MPrintFont.get(item.getAD_PrintFont_ID());
1362                    rowColFont.put(new Point(TableElement.ALL, col), font.getFont());
1363                }
1364                if (item.getAD_PrintColor_ID() != 0 && item.getAD_PrintColor_ID() != format.getAD_PrintColor_ID())
1365                {
1366                    MPrintColor color = MPrintColor.get (item.getAD_PrintColor_ID());
1367                    rowColColor.put(new Point(TableElement.ALL, col), color.getColor());
1368                }
1369                //
1370
col++;
1371            }
1372        }
1373
1374        // The Data
1375
int rows = printData.getRowCount();
1376    // System.out.println("Rows=" + rows);
1377
Object JavaDoc[][] data = new Object JavaDoc [rows][m_columnCount];
1378        KeyNamePair[] pk = new KeyNamePair[rows];
1379        String JavaDoc pkColumnName = null;
1380        boolean lastLineFunction = false;
1381        ArrayList pageBreak = new ArrayList();
1382
1383        // for all rows
1384
for (int row = 0; row < rows; row++)
1385        {
1386        // System.out.println("row=" + row);
1387
printData.setRowIndex(row);
1388            if (printData.isFunctionRow())
1389            {
1390                rowColFont.put(new Point(row, TableElement.ALL), tf.getFunct_Font());
1391                rowColColor.put(new Point(row, TableElement.ALL), tf.getFunctFG_Color());
1392                rowColBackground.put(new Point(row, TableElement.ALL), tf.getFunctBG_Color());
1393                lastLineFunction = true;
1394                if (printData.isPageBreak())
1395                {
1396                    pageBreak.add(new Integer JavaDoc(row));
1397                    if (Log.isTraceLevel(8))
1398                        log.debug("layoutTable - PageBreak row=" + row);
1399                }
1400            }
1401            // Summary/Line Levels for Finanial Reports
1402
else
1403            {
1404                int levelNo = printData.getLineLevelNo();
1405                if (levelNo != 0)
1406                {
1407                    Font base = printFont.getFont();
1408                    rowColFont.put(new Point(row, TableElement.ALL), new Font (base.getName(),
1409                        Font.PLAIN, base.getSize()-levelNo));
1410                }
1411            }
1412            // for all columns
1413
col = 0;
1414            for (int c = 0; c < format.getItemCount(); c++)
1415            {
1416                MPrintFormatItem item = format.getItem(c);
1417                Object JavaDoc dataElement = null;
1418                if (item.isPrinted())
1419                {
1420                    Object JavaDoc obj = printData.getNode(new Integer JavaDoc(item.getAD_Column_ID()));
1421                    if (obj == null)
1422                        ;
1423                    else if (obj instanceof PrintDataElement)
1424                    {
1425                        PrintDataElement pde = (PrintDataElement)obj;
1426                        if (pde.isID() || pde.isYesNo())
1427                            dataElement = pde.getValue();
1428                        else
1429                            dataElement = pde.getValueDisplay(format.getLanguage());
1430                    }
1431                    else
1432                        log.error("layoutTable - Element not PrintDataElement " + obj.getClass());
1433
1434                // System.out.println(" col=" + col + " " + item.getAD_Column_ID() + " => " + dataElement);
1435
data[row][col] = dataElement;
1436                    col++;
1437                } // printed
1438
} // for all columns
1439

1440            PrintDataElement pde = printData.getPKey();
1441            if (pde != null) // for FunctionRows
1442
{
1443                pk[row] = (KeyNamePair)pde.getValue();
1444                if (pkColumnName == null)
1445                    pkColumnName = pde.getColumnName();
1446            }
1447        // else
1448
// System.out.println("No PK " + printData);
1449
} // for all rows
1450

1451        //
1452
TableElement table = new TableElement(columnHeader,
1453            columnMaxWidth, columnMaxHeight, columnJustification,
1454            fixedWidth, lastLineFunction, multiLineHeader,
1455            data, pk, pkColumnName,
1456            pageNoStart, firstPage, nextPages, repeatedColumns, additionalLines,
1457            rowColFont, rowColColor, rowColBackground,
1458            tf, pageBreak);
1459        table.layout(0,0,false, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
1460        if (m_tableElement == null)
1461            m_tableElement = table;
1462        return table;
1463    } // layoutTable
1464

1465    /**
1466     * Layout Parameter based on MQuery
1467     * @return PrintElement
1468     */

1469    private PrintElement layoutParameter ()
1470    {
1471        if (m_query == null || !m_query.isActive())
1472            return null;
1473        //
1474
ParameterElement pe = new ParameterElement(m_query, m_printCtx, m_format.getTableFormat());
1475        pe.layout(0, 0, false, null);
1476        return pe;
1477    } // layoutParameter
1478

1479    /*************************************************************************/
1480
1481} // LayoutEngine
1482
Popular Tags