Source Code Cross Referenced for PrintUtilities.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » client » util » 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 » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.client.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.client.util;
002:
003:        /*
004:         * This code below originates from Rob MacGrogan's blog here:
005:         * 
006:         * http://www.developerdotstar.com/community/node/124
007:         * 
008:         * My changes were minimal to support logging - Rob Manning
009:         * This printing method is easy and preserves syntax highlighting, but it 
010:         * is not able to handle pagination correctly. 
011:         */
012:
013:        /*
014:         * Copied from this tutorial:
015:         *
016:         * http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html
017:         *
018:         * And also from a post on the forums at java.swing.com. My apologies that do 
019:         * not have a link to that post, by my hat goes off to the poster because 
020:         * he/she figured out the sticky problem of paging properly when printing a 
021:         * Swing component.
022:         */
023:        import java.awt.Component;
024:        import java.awt.Dimension;
025:        import java.awt.Graphics;
026:        import java.awt.Graphics2D;
027:        import java.awt.print.PageFormat;
028:        import java.awt.print.Printable;
029:        import java.awt.print.PrinterException;
030:        import java.awt.print.PrinterJob;
031:
032:        import javax.swing.RepaintManager;
033:
034:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
035:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
036:
037:        public class PrintUtilities implements  Printable {
038:
039:            private Component componentToBePrinted;
040:
041:            /** Logger for this class. */
042:            private final static ILogger s_log = LoggerController
043:                    .createLogger(PrintUtilities.class);
044:
045:            public static void printComponent(Component c) {
046:                new PrintUtilities(c).print();
047:            }
048:
049:            public PrintUtilities(Component componentToBePrinted) {
050:                this .componentToBePrinted = componentToBePrinted;
051:            }
052:
053:            public void print() {
054:                PrinterJob printJob = PrinterJob.getPrinterJob();
055:                printJob.setPrintable(this );
056:                if (printJob.printDialog()) {
057:                    try {
058:                        printJob.print();
059:                    } catch (PrinterException pe) {
060:                        s_log.error("Error printing", pe);
061:                    }
062:                }
063:            }
064:
065:            public int print(Graphics g, PageFormat pf, int pageIndex) {
066:                int response = NO_SUCH_PAGE;
067:                Graphics2D g2 = (Graphics2D) g;
068:                Dimension d = componentToBePrinted.getSize(); //get size of document
069:                double panelWidth = d.width; //width in pixels
070:                double panelHeight = d.height; //height in pixels
071:                double pageHeight = pf.getImageableHeight(); //height of printer page
072:                double pageWidth = pf.getImageableWidth(); //width of printer page
073:                double scale = pageWidth / panelWidth;
074:                int totalNumPages = (int) Math.ceil(scale * panelHeight
075:                        / pageHeight);
076:                // make sure not print empty pages
077:                if (pageIndex >= totalNumPages) {
078:                    response = NO_SUCH_PAGE;
079:                } else {
080:                    // shift Graphic to line up with beginning of print-imageable region
081:                    g2.translate(pf.getImageableX(), pf.getImageableY());
082:                    // shift Graphic to line up with beginning of next page to print
083:                    g2.translate(0f, -pageIndex * pageHeight);
084:                    // scale the page so the width fits...
085:                    g2.scale(scale, scale);
086:                    // for faster printing, turn off double buffering
087:                    disableDoubleBuffering(componentToBePrinted);
088:                    componentToBePrinted.paint(g2); //repaint the page for printing
089:                    enableDoubleBuffering(componentToBePrinted);
090:                    response = Printable.PAGE_EXISTS;
091:                }
092:                return response;
093:            }
094:
095:            public static void disableDoubleBuffering(Component c) {
096:                RepaintManager currentManager = RepaintManager
097:                        .currentManager(c);
098:                currentManager.setDoubleBufferingEnabled(false);
099:            }
100:
101:            public static void enableDoubleBuffering(Component c) {
102:                RepaintManager currentManager = RepaintManager
103:                        .currentManager(c);
104:                currentManager.setDoubleBufferingEnabled(true);
105:            }
106:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.