001: /*
002: * Copyright (C) 2004 Giuseppe MANNA
003: *
004: * This file is part of FreeReportBuilder
005: *
006: * FreeReportBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package it.frb;
023:
024: import it.frb.*;
025: import java.awt.print.PageFormat;
026:
027: public class PrintThread implements Runnable {
028: private int page;
029: private javax.swing.JWindow print;
030: private javax.swing.JProgressBar bar;
031: private java.awt.print.Printable jPrewPanel;
032: private java.awt.Toolkit objToolkit;
033: private java.awt.Dimension dScSize;
034: private javax.swing.JFrame owner;
035:
036: public PrintThread(javax.swing.JFrame owner,
037: java.awt.print.Printable jPrewPanel, int page) {
038: super ();
039:
040: objToolkit = java.awt.Toolkit.getDefaultToolkit();
041: dScSize = objToolkit.getScreenSize();
042:
043: print = new javax.swing.JWindow(owner);
044: print.setBounds((dScSize.width / 2 - 250),
045: (dScSize.height / 2 - 10), 500, 20);
046:
047: bar = new javax.swing.JProgressBar(
048: javax.swing.JProgressBar.HORIZONTAL, 1, page);
049: bar.setStringPainted(true);
050: bar.setString("");
051: print.getContentPane().add(bar);
052: print.setVisible(false);
053:
054: this .jPrewPanel = jPrewPanel;
055: this .page = page;
056: }
057:
058: public javax.swing.JProgressBar getJProgressBarPrint() {
059: return bar;
060: }
061:
062: public void run() {
063: SecurityManager security = System.getSecurityManager();
064:
065: if (security != null) {
066: try {
067: security.checkPrintJobAccess();
068: } catch (SecurityException se) {
069: System.out
070: .println("Security error trying to print data !!! :(");
071: }
072: } else {
073: System.out.println("No security manager !!! :(");
074: java.awt.print.PrinterJob printJob = java.awt.print.PrinterJob
075: .getPrinterJob();
076:
077: PageFormat pf = null;
078:
079: try {
080: pf = printJob.pageDialog(printJob.defaultPage());
081:
082: // Test
083: // try
084: // {
085: // if (((JPreviewPanel)jPrewPanel).getVectorDati()==null)
086: // {
087: // ((JPreviewPanel)jPrewPanel).getResultSet().beforeFirst();
088: // }else
089: // {
090: // ((JPreviewPanel)jPrewPanel).setCursorPosition(0);
091: // }
092: //
093: // ((JPreviewPanel)jPrewPanel).nextPage();
094: //
095: // }catch(java.sql.SQLException sqle)
096: // {
097: // System.out.println(sqle.getMessage());
098: // }
099: // Test
100:
101: printJob.setPrintable(jPrewPanel, pf);
102: // ((JPreviewPanel)jPrewPanel).setPageIndex(0);
103: ((JPreviewPanel) jPrewPanel).setFormatPage(pf);
104: ((JPreviewPanel) jPrewPanel).setPrintJob(printJob);
105: ((JPreviewPanel) jPrewPanel).setJProgressBar(bar);
106:
107: } catch (ClassCastException e) {
108: ((DataReportViewer.ReportView) jPrewPanel)
109: .setPrintJob(printJob);
110: }
111:
112: // java.awt.print.Book book = new java.awt.print.Book();
113: // book.append(jPrewPanel,pf,page);
114: // printJob.setPageable (book);
115:
116: ((javax.swing.JComponent) jPrewPanel).setVisible(false);
117:
118: if (printJob.printDialog()) {
119: try {
120: print.setVisible(true);
121: printJob.print();
122: } catch (Exception ex) {
123: ex.printStackTrace();
124: System.exit(0);
125: }
126:
127: print.setVisible(false);
128: bar = null;
129: }
130:
131: ((javax.swing.JComponent) jPrewPanel).setVisible(true);
132: }
133: }
134: }
|