Source Code Cross Referenced for BufferPrinter1_4.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » 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 » Swing Library » jEdit » org.gjt.sp.jedit.print 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BufferPrinter1_4.java - Main class that controls printing
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2001 Slava Pestov
007:         * Portions copyright (C) 2002 Thomas Dilts
008:         *
009:         * This program is free software; you can redistribute it and/or
010:         * modify it under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; either version 2
012:         * of the License, or any later version.
013:         *
014:         * This program is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017:         * GNU General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU General Public License
020:         * along with this program; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
022:         */
023:
024:        package org.gjt.sp.jedit.print;
025:
026:        //{{{ Imports
027:        import javax.print.attribute.*;
028:        import javax.print.attribute.standard.*;
029:        import java.awt.print.*;
030:        import java.awt.*;
031:        import java.io.*;
032:        import org.gjt.sp.jedit.*;
033:        import org.gjt.sp.util.Log;
034:
035:        //}}}
036:
037:        public class BufferPrinter1_4 {
038:            //{{{ getPrintJob() method
039:            private static PrinterJob getPrintJob(String jobName) {
040:                job = PrinterJob.getPrinterJob();
041:
042:                format = new HashPrintRequestAttributeSet();
043:
044:                String settings = jEdit.getSettingsDirectory();
045:                if (settings != null) {
046:                    String printSpecPath = MiscUtilities.constructPath(
047:                            settings, "printspec");
048:                    File filePrintSpec = new File(printSpecPath);
049:
050:                    if (filePrintSpec.exists()) {
051:                        try {
052:                            FileInputStream fileIn = new FileInputStream(
053:                                    filePrintSpec);
054:                            ObjectInputStream obIn = new ObjectInputStream(
055:                                    fileIn);
056:                            format = (HashPrintRequestAttributeSet) obIn
057:                                    .readObject();
058:                        } catch (Exception e) {
059:                            Log.log(Log.ERROR, BufferPrinter1_4.class, e);
060:                        }
061:                        //for backwards compatibility, the color variable is stored also as a property
062:                        if (jEdit.getBooleanProperty("print.color"))
063:                            format.add(Chromaticity.COLOR);
064:                        else
065:                            format.add(Chromaticity.MONOCHROME);
066:
067:                        //no need to always keep the same job name for every printout.
068:                        format.add(new JobName(jobName, null));
069:                    }
070:                }
071:
072:                return job;
073:            } //}}}
074:
075:            //{{{ pageSetup() method
076:            public static void pageSetup(View view) {
077:                PrinterJob prnJob = getPrintJob("PageSetupOnly");
078:                if (prnJob.pageDialog(format) != null)
079:                    savePrintSpec();
080:            } //}}}
081:
082:            //{{{ print() method
083:            public static void print(final View view, final Buffer buffer,
084:                    boolean selection) {
085:                job = getPrintJob(buffer.getPath());
086:
087:                boolean header = jEdit.getBooleanProperty("print.header");
088:                boolean footer = jEdit.getBooleanProperty("print.footer");
089:                boolean lineNumbers = jEdit
090:                        .getBooleanProperty("print.lineNumbers");
091:                boolean color = jEdit.getBooleanProperty("print.color");
092:                Font font = jEdit.getFontProperty("print.font");
093:
094:                BufferPrintable printable = new BufferPrintable(job, format,
095:                        view, buffer, font, header, footer, lineNumbers, color);
096:                job.setPrintable(printable);
097:
098:                if (!job.printDialog(format))
099:                    return;
100:
101:                savePrintSpec();
102:
103:                printable.print();
104:            } //}}}
105:
106:            //{{{ getPageFormat() method
107:            public static PageFormat getPageFormat() {
108:                //convert from PrintRequestAttributeSet to the pageFormat
109:                PrinterJob prnJob = getPrintJob(" ");
110:                PageFormat pf = prnJob.defaultPage();
111:                Paper pap = pf.getPaper();
112:
113:                MediaSizeName media = (MediaSizeName) format.get(Media.class);
114:                MediaSize ms = MediaSize.getMediaSizeForName(media);
115:
116:                MediaPrintableArea mediaarea = (MediaPrintableArea) format
117:                        .get(MediaPrintableArea.class);
118:                if (mediaarea != null)
119:                    pap
120:                            .setImageableArea(
121:                                    (mediaarea.getX(MediaPrintableArea.INCH) * 72),
122:                                    (mediaarea.getY(MediaPrintableArea.INCH) * 72),
123:                                    (mediaarea
124:                                            .getWidth(MediaPrintableArea.INCH) * 72),
125:                                    (mediaarea
126:                                            .getHeight(MediaPrintableArea.INCH) * 72));
127:                if (ms != null)
128:                    pap.setSize((ms.getX(MediaSize.INCH) * 72), (ms
129:                            .getY(MediaSize.INCH) * 72));
130:                pf.setPaper(pap);
131:
132:                OrientationRequested orientation = (OrientationRequested) format
133:                        .get(OrientationRequested.class);
134:                if (orientation != null) {
135:                    if (orientation.getValue() == OrientationRequested.LANDSCAPE
136:                            .getValue()) {
137:                        pf.setOrientation(PageFormat.LANDSCAPE);
138:                    } else if (orientation.getValue() == OrientationRequested.REVERSE_LANDSCAPE
139:                            .getValue()) {
140:                        pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
141:                    } else if (orientation.getValue() == OrientationRequested.PORTRAIT
142:                            .getValue()) {
143:                        pf.setOrientation(PageFormat.PORTRAIT);
144:                    } else if (orientation.getValue() == OrientationRequested.REVERSE_PORTRAIT
145:                            .getValue()) {
146:                        //doesnt exist??
147:                        //pf.setOrientation(PageFormat.REVERSE_PORTRAIT);
148:                        //then just do the next best thing
149:                        pf.setOrientation(PageFormat.PORTRAIT);
150:                    }
151:                }
152:                return pf;
153:            } //}}}
154:
155:            //{{{ savePrintSpec() method
156:            private static void savePrintSpec() {
157:                String settings = jEdit.getSettingsDirectory();
158:                if (settings == null)
159:                    return;
160:
161:                String printSpecPath = MiscUtilities.constructPath(settings,
162:                        "printspec");
163:                File filePrintSpec = new File(printSpecPath);
164:
165:                try {
166:                    FileOutputStream fileOut = new FileOutputStream(
167:                            filePrintSpec);
168:                    ObjectOutputStream obOut = new ObjectOutputStream(fileOut);
169:                    obOut.writeObject(format);
170:                    //for backwards compatibility, the color variable is stored also as a property
171:                    Chromaticity cc = (Chromaticity) format
172:                            .get(Chromaticity.class);
173:                    if (cc != null)
174:                        jEdit.setBooleanProperty("print.color",
175:                                cc.getValue() == Chromaticity.COLOR.getValue());
176:                } catch (Exception e) {
177:                    e.printStackTrace();
178:                }
179:            }
180:
181:            //}}}
182:
183:            //{{{ Private members
184:            private static PrintRequestAttributeSet format;
185:            private static PrinterJob job;
186:            //}}}
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.