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 java.awt.Dimension;
025: import javax.swing.JOptionPane;
026:
027: public class ExportThread implements Runnable {
028: private javax.swing.JWindow export;
029: private javax.swing.JProgressBar bar;
030: private java.awt.Toolkit objToolkit;
031: private java.awt.Dimension dScSize;
032: private JPreviewPanel jPrewPanel;
033: private String savePath;
034: private int counter;
035: private int totalPage;
036:
037: public ExportThread(javax.swing.JFrame owner,
038: JPreviewPanel jPrewPanel, int totalPage) {
039: objToolkit = java.awt.Toolkit.getDefaultToolkit();
040: dScSize = objToolkit.getScreenSize();
041:
042: this .jPrewPanel = jPrewPanel;
043: this .totalPage = totalPage;
044:
045: export = new javax.swing.JWindow(owner);
046: export.setBounds((dScSize.width / 2 - 250),
047: (dScSize.height / 2 - 10), 500, 20);
048:
049: bar = new javax.swing.JProgressBar(
050: javax.swing.JProgressBar.HORIZONTAL);
051: bar.setStringPainted(true);
052: bar.setString("");
053: export.getContentPane().add(bar);
054: export.setVisible(false);
055: }
056:
057: public void run() {
058: int counter = 1;
059:
060: try {
061: Object obj = JOptionPane.showInputDialog(null, null,
062: "Pages to be exported ? ( tot. pages " + totalPage
063: + ")", JOptionPane.QUESTION_MESSAGE, null,
064: null, null);
065:
066: if (obj != null) {
067: int pagePrint = 0;
068:
069: try {
070: pagePrint = new Integer(((String) obj)).intValue();
071:
072: } catch (NumberFormatException e) {
073: JOptionPane.showMessageDialog(null,
074: "Attention not and' inserts a number!");
075: }
076:
077: if (totalPage != 0) {
078: javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
079: XmlFileFilter filter = new XmlFileFilter();
080:
081: filter.addExtension("dpv");
082: filter.setDescription("DataReport exp.");
083: chooser.setFileFilter(filter);
084:
085: if (chooser.showSaveDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) {
086: String path = chooser.getSelectedFile()
087: .getAbsolutePath();
088:
089: if (chooser.getSelectedFile().getAbsolutePath()
090: .indexOf(".") == -1) {
091: path = chooser.getSelectedFile()
092: .getAbsolutePath()
093: + ".dpv";
094: } else {
095: path = chooser.getSelectedFile()
096: .getAbsolutePath();
097: }
098:
099: if (path != "") {
100: bar.setMinimum(1);
101: bar.setMaximum(pagePrint);
102: bar.setString("Pagina 0 di " + pagePrint);
103:
104: jPrewPanel.setVisible(false);
105: export.setVisible(true);
106:
107: XmlFileWriter xmlwrite = new XmlFileWriter(
108: jPrewPanel, path);
109: java.io.FileWriter flws = new java.io.FileWriter(
110: path, false);
111: flws
112: .write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n");
113: flws.write("<report>\n");
114: xmlwrite.flws = flws;
115: flws.write("<page." + counter + ">\n");
116: xmlwrite.writeContainer(jPrewPanel);
117: bar.setValue(1);
118: bar.setString("Pagina 1 di " + pagePrint);
119: flws.write("</page." + counter + ">\n");
120:
121: while (!(pagePrint == counter)
122: && !(jPrewPanel.getRowsCount() == jPrewPanel
123: .getCursorPosition() + 1)) {
124: counter = counter + 1;
125:
126: flws.write("<page." + counter + ">\n");
127: jPrewPanel.nextPage();
128: xmlwrite.writeContainer(jPrewPanel);
129: bar.setValue(counter);
130: bar.setString("Pagina " + counter
131: + " di " + pagePrint);
132: flws.write("</page." + counter + ">\n");
133: }
134:
135: flws.write("<TotalPage>");
136: flws.write(String.valueOf(counter));
137: flws.write("</TotalPage>\n");
138: flws.write("</report>");
139: xmlwrite.flws.close();
140: bar
141: .setString("Esportazione conclusa correttamente!");
142: export.setVisible(false);
143: jPrewPanel.setVisible(true);
144: }
145: }
146: }
147: }
148: } catch (java.io.IOException e) {
149: JOptionPane.showMessageDialog(null, "Errore IOException");
150: System.exit(0);
151:
152: } catch (java.sql.SQLException e) {
153: JOptionPane
154: .showMessageDialog(null,
155: "An error is occurred in the advancement of the page.");
156: System.exit(0);
157: }
158: }
159: }
|