Source Code Cross Referenced for PrintableFrameSet.java in  » XML-UI » xui32 » com » xoetrope » print » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML UI » xui32 » com.xoetrope.print 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.print;
002:
003:        import java.util.Vector;
004:
005:        import java.awt.Container;
006:        import java.awt.Dimension;
007:        import java.awt.Font;
008:        import java.awt.FontMetrics;
009:        import java.awt.Graphics;
010:        import java.awt.Graphics2D;
011:        import java.awt.Point;
012:        import java.awt.geom.AffineTransform;
013:        import java.awt.print.PageFormat;
014:        import java.awt.print.Printable;
015:        import java.awt.print.PrinterException;
016:        import net.xoetrope.xui.XProject;
017:
018:        import net.xoetrope.xui.XProjectManager;
019:        import net.xoetrope.xui.style.XStyle;
020:
021:        /**
022:         * A decoration of the container to allow printing when the page is contains multiple pages within frames
023:         *
024:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
025:         * the GNU Public License (GPL), please see license.txt for more details. If
026:         * you make commercial use of this software you must purchase a commercial
027:         * license from Xoetrope.</p>
028:         * <p> $Revision: 1.4 $</p>
029:         */
030:        public class PrintableFrameSet implements  Printable {
031:            /**
032:             * Storage for the frames of this page
033:             */
034:            protected Vector frames;
035:
036:            /**
037:             * The PrintOut object that owns this printable page
038:             */
039:            protected Printout printout;
040:
041:            /**
042:             * The owner project and the context in which this object operates.
043:             */
044:            protected XProject currentProject = XProjectManager
045:                    .getCurrentProject();
046:
047:            /**
048:             * Craete a new PrintableFrameSet
049:             * @param po The owner PrintOut
050:             */
051:            public PrintableFrameSet(Printout po) {
052:                frames = new Vector();
053:                printout = po;
054:            }
055:
056:            /**
057:             * Add a frame to the page.
058:             * @param targetFrame the frame to add
059:             */
060:            public void addFrame(Container targetFrame) {
061:                frames.addElement(targetFrame);
062:            }
063:
064:            /**
065:             * Print the frameset.The frame elements are assumed to be XTargets, the 
066:             * coordinates of which are used to position each frame on the page. The 
067:             * content of each target area is then printed.
068:             * @param g the graphics context
069:             * @param pf the page format
070:             * @param pageIndex the index of the page within the page set
071:             * @throws java.awt.print.PrinterException some printing error
072:             * @return Printable.PAGE_EXISTS on success
073:             */
074:            public int print(Graphics g, PageFormat pf, int pageIndex)
075:                    throws PrinterException {
076:                Font f = currentProject.getStyleManager().getFont("base");
077:                g.setFont(f);
078:                g.setColor(currentProject.getStyleManager().getStyle("base")
079:                        .getStyleAsColor(XStyle.COLOR_FORE));
080:                FontMetrics fm = g.getFontMetrics();
081:
082:                int numFrames = frames.size();
083:                if (pageIndex != 0)
084:                    return Printable.NO_SUCH_PAGE;
085:
086:                double imageableX = pf.getImageableX();
087:                double imageableY = pf.getImageableY();
088:                double imageableW = pf.getImageableWidth();
089:                double imageableH = pf.getImageableHeight();
090:
091:                // Determine the maximum coordinates
092:                int maxX = 0, maxY = 0;
093:                for (int i = 0; i < numFrames; i++) {
094:                    Container currentTarget = (Container) frames.elementAt(i);
095:                    Point pos = currentTarget.getLocation();
096:                    Dimension size = currentTarget.getSize();
097:                    maxX = Math.max(maxX, pos.x + size.width);
098:                    maxY = Math.max(maxY, pos.y + size.height);
099:                }
100:
101:                Graphics2D g2 = (Graphics2D) g;
102:
103:                // Draw the decorations
104:                int headerHeight = 0, footerHeight = 10;
105:                for (int i = 0; i < 3; i++)
106:                    headerHeight = Math.max(headerHeight, printout
107:                            .printDecoration(g2, pf, true, i, imageableX + i
108:                                    * imageableW / 3.0, imageableY, fm));
109:
110:                for (int i = 0; i < 3; i++)
111:                    footerHeight = Math.max(footerHeight, printout
112:                            .printDecoration(g2, pf, false, i, imageableX + i
113:                                    * imageableW / 3.0, imageableY + imageableH
114:                                    - footerHeight, fm));
115:
116:                // Setup the scaling
117:                double scale;
118:                imageableH -= (headerHeight + footerHeight);
119:                if (pf.getOrientation() == PageFormat.LANDSCAPE)
120:                    scale = imageableH / maxY;
121:                else
122:                    scale = imageableW / maxX;
123:
124:                AffineTransform transform = g2.getTransform();
125:
126:                // Paint the individual elements
127:                for (int i = 0; i < numFrames; i++) {
128:                    Container currentTarget = (Container) frames.elementAt(i);
129:                    Container currentPage = (Container) currentTarget
130:                            .getComponent(0);
131:                    Point pos = currentTarget.getLocation();
132:
133:                    g2.setTransform(transform);
134:                    g2.translate(imageableX + pos.x * scale, imageableY + pos.y
135:                            * scale + headerHeight);
136:                    g2.scale(scale, scale);
137:                    g2.setClip(0, 0, currentPage.getWidth(), currentPage
138:                            .getHeight());
139:                    currentPage.print(g);
140:                    currentPage.printComponents(g);
141:                }
142:
143:                return Printable.PAGE_EXISTS;
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.