 
| Line | Hits | Source | 
|---|---|---|
| 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 | ||
| 61 | 0 | public 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; | |
| 70 | 2 | public Action saveInExcelButtonAction = new AbstractAction() { | 
| 71 | ||
| 72 | public void actionPerformed(ActionEvent event) { | |
| 73 | ||
| 74 | saveInExcelButtonAction(); | |
| 75 | ||
| 76 | } | |
| 77 | ||
| 78 | }; | |
| 79 | ||
| 80 | 2 | 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, | |
| 92 | 2 | String nameLabelText) { | 
| 93 | ||
| 94 | 2 | GridBagConstraints constraints = null; | 
| 95 | ||
| 96 | ||
| 97 | try { | |
| 98 | ||
| 99 | 2 | this.dialog = | 
| 100 | (XDialog) (new SwingEngine(this)).render( | |
| 101 | ClassLoader.getSystemClassLoader().getResource(UI_DEF_FILE_NAME)); | |
| 102 | ||
| 103 | 0 | } catch (Exception exception) { | 
| 104 | ||
| 105 | this.logger.error("", exception); | |
| 106 | ||
| 107 | 2 | } | 
| 108 | ||
| 109 | 2 | 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 | ||
| 123 | 2 | this.dialog.getContentPane().add(balanceSheet.getPanel(), constraints); | 
| 124 | ||
| 125 | 2 | this.balanceSheetPanel = balanceSheet.getPanel(); | 
| 126 | ||
| 127 | 2 | this.nameLabel.setText(nameLabelText); | 
| 128 | ||
| 129 | 2 | this.dialog.pack(); | 
| 130 | ||
| 131 | 2 | } | 
| 132 | ||
| 133 | public XDialog getDialog() { | |
| 134 | ||
| 135 | 2 | return dialog; | 
| 136 | ||
| 137 | } | |
| 138 | ||
| 139 | private void okButtonAction() { | |
| 140 | ||
| 141 | 0 | this.dialog.hide(); | 
| 142 | ||
| 143 | 0 | } | 
| 144 | ||
| 145 | protected void saveInExcelButtonAction() { | |
| 146 | ||
| 147 | 0 | ExcelTaskBalanceSheetRenderer renderer = null; | 
| 148 | ||
| 149 | 0 | JFileChooser fileChooser = null; | 
| 150 | ||
| 151 | 0 | File file = null; | 
| 152 | ||
| 153 | 0 | HSSFWorkbook workBook = null; | 
| 154 | ||
| 155 | 0 | FileOutputStream fileOutputStream = null; | 
| 156 | ||
| 157 | 0 | fileChooser = new JFileChooser(); | 
| 158 | ||
| 159 | 0 | fileChooser.setFileFilter(new ExcelFileFilter()); | 
| 160 | ||
| 161 | 0 | if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { | 
| 162 | ||
| 163 | 0 | file = fileChooser.getSelectedFile(); | 
| 164 | ||
| 165 | 0 | CursorManagementSingleton.getInstance().setWaitCursor(); | 
| 166 | ||
| 167 | 0 | workBook = this.getRenderedBalanceSheet(); | 
| 168 | ||
| 169 | try { | |
| 170 | ||
| 171 | 0 | fileOutputStream = new FileOutputStream(file); | 
| 172 | ||
| 173 | 0 | workBook.write(fileOutputStream); | 
| 174 | ||
| 175 | 0 | fileOutputStream.close(); | 
| 176 | ||
| 177 | 0 | } catch (IOException exception) { | 
| 178 | ||
| 179 | this.logger.error("", exception); | |
| 180 | ||
| 181 | 0 | CursorManagementSingleton.getInstance().setDefaultCursor(); | 
| 182 | ||
| 183 | 0 | 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 | ||
| 189 | 0 | } | 
| 190 | ||
| 191 | 0 | CursorManagementSingleton.getInstance().setDefaultCursor(); | 
| 192 | ||
| 193 | } | |
| 194 | ||
| 195 | 0 | } | 
| 196 | ||
| 197 | protected abstract HSSFWorkbook getRenderedBalanceSheet(); | |
| 198 | ||
| 199 | } | 
| 
this report was generated by version 1.0.5 of jcoverage. | 
copyright © 2003, jcoverage ltd. all rights reserved. |