Coverage details for net.sourceforge.demetrix.ui.balancesheets.BalanceSheetDialog

LineHitsSource
1 /*******************************************************************************
2  * Demetrix process modelling system
3  *
4  * Copyright (c) 2003, 2004 Dimitri A. Pissarenko
5  *
6  * This file is part of Demetrix.
7  *
8  * Demetrix is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * Demetrix is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Demetrix; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * For further information you may
23  *
24  * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net
25  * - look at http://sourceforge.net/projects/demetrix/
26  * - look at http://demetrix.sourceforge.net/
27  * - look at http://members.inode.at/d.pissarenko/
28  *
29  *****************************************************************************/
30  
31 package net.sourceforge.demetrix.ui.balancesheets;
32  
33 import java.awt.GridBagConstraints;
34 import java.awt.Insets;
35 import java.awt.event.ActionEvent;
36 import java.io.File;
37 import java.io.FileOutputStream;
38 import java.io.IOException;
39  
40 import javax.swing.AbstractAction;
41 import javax.swing.Action;
42 import javax.swing.JFileChooser;
43 import javax.swing.JLabel;
44 import javax.swing.JOptionPane;
45 import javax.swing.JPanel;
46  
47 import net.sourceforge.demetrix.Demetrix;
48 import net.sourceforge.demetrix.ui.CursorManagementSingleton;
49 import net.sourceforge.demetrix.util.ExcelFileFilter;
50  
51 import org.apache.log4j.Logger;
52 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
53 import org.swixml.SwingEngine;
54 import org.swixml.XDialog;
55  
56 /**
57  * @author Dimitri Pissarenko
58  *
59  */
60  
610public abstract class BalanceSheetDialog {
62  
63     private Logger logger = Logger.getLogger(getClass());
64     public final static String UI_DEF_FILE_NAME="net/sourceforge/demetrix/ui/balancesheets/BalanceSheetDialog.xml";
65     private XDialog dialog;
66  
67     public JPanel balanceSheetPanel;
68  
69     public JLabel nameLabel;
702    public Action saveInExcelButtonAction = new AbstractAction() {
71  
72         public void actionPerformed(ActionEvent event) {
73  
74             saveInExcelButtonAction();
75  
76         }
77  
78     };
79  
802    public Action okButtonAction = new AbstractAction() {
81  
82         public void actionPerformed(ActionEvent event) {
83  
84             okButtonAction();
85  
86         }
87  
88     };
89  
90     public BalanceSheetDialog(
91         SwixMLBalanceSheetRenderer balanceSheet,
922        String nameLabelText) {
93  
942        GridBagConstraints constraints = null;
95  
96  
97         try {
98  
992            this.dialog =
100                 (XDialog) (new SwingEngine(this)).render(
101             ClassLoader.getSystemClassLoader().getResource(UI_DEF_FILE_NAME));
102  
1030        } catch (Exception exception) {
104  
105             this.logger.error("", exception);
106  
1072        }
108  
1092        constraints =
110             new GridBagConstraints(
111                 0,
112                 1,
113                 1,
114                 1,
115                 1.,
116                 1.,
117                 GridBagConstraints.WEST,
118                 GridBagConstraints.NONE,
119                 new Insets(5, 5, 5, 5),
120                 0,
121                 0);
122  
1232        this.dialog.getContentPane().add(balanceSheet.getPanel(), constraints);
124  
1252        this.balanceSheetPanel = balanceSheet.getPanel();
126  
1272        this.nameLabel.setText(nameLabelText);
128  
1292        this.dialog.pack();
130  
1312    }
132  
133     public XDialog getDialog() {
134  
1352        return dialog;
136  
137     }
138  
139     private void okButtonAction() {
140  
1410        this.dialog.hide();
142  
1430    }
144  
145     protected void saveInExcelButtonAction() {
146  
1470        ExcelTaskBalanceSheetRenderer renderer = null;
148  
1490        JFileChooser fileChooser = null;
150  
1510        File file = null;
152  
1530        HSSFWorkbook workBook = null;
154  
1550        FileOutputStream fileOutputStream = null;
156  
1570        fileChooser = new JFileChooser();
158  
1590        fileChooser.setFileFilter(new ExcelFileFilter());
160  
1610        if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
162  
1630            file = fileChooser.getSelectedFile();
164  
1650            CursorManagementSingleton.getInstance().setWaitCursor();
166  
1670            workBook = this.getRenderedBalanceSheet();
168  
169             try {
170  
1710                fileOutputStream = new FileOutputStream(file);
172  
1730                workBook.write(fileOutputStream);
174  
1750                fileOutputStream.close();
176  
1770            } catch (IOException exception) {
178  
179                 this.logger.error("", exception);
180  
1810                CursorManagementSingleton.getInstance().setDefaultCursor();
182  
1830                JOptionPane.showMessageDialog(
184                     null,
185                     "An error occured while saving the balance sheet. See console output for details.",
186                     Demetrix.PRODUCT_NAME,
187                     JOptionPane.OK_OPTION);
188  
1890            }
190  
1910            CursorManagementSingleton.getInstance().setDefaultCursor();
192  
193         }
194  
1950    }
196  
197     protected abstract HSSFWorkbook getRenderedBalanceSheet();
198  
199 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.