/************************************************************************** /* This class is a demo for JFreeReport /* /* Copyright (c) 2004 by Bernhard Bablok (mail@bablokb.de) /* /* This program is free software; you can redistribute it and/or modify /* it under the terms of the GNU General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This program is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU General Public License for more details. /* /* You should have received a copy of the GNU General Public License /* along with this program; see the file COPYING. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ import java.awt.*; import java.awt.event.*; import java.net.*; import java.text.*; import javax.swing.*; import javax.swing.table.*; import org.jfree.report.*; import org.jfree.report.modules.gui.base.*; import org.jfree.report.modules.gui.base.components.*; import org.jfree.report.modules.parser.base.*; import org.jfree.report.util.*; import org.jfree.ui.*; /** This class is a demo for JFreeReport @version $Revision: 1.2 $ @author $Author: bablokb $ */ public class FreeSpace extends JFrame { private static final String REPORT_DEFINITION="freespace-report.xml"; ////////////////////////////////////////////////////////////////////////////// /** The data for the report. */ private TableModel iData; ////////////////////////////////////////////////////////////////////////////// /** Constructs the demo application. @param title the frame title. */ public FreeSpace() { setTitle("FreeSpace"); createGUI(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); }}); } ////////////////////////////////////////////////////////////////////////////// /** Creates the application GUI. */ public void createGUI() { iData = new FreeSpaceTableModel(); final JTable table = new JTable(iData); final JScrollPane scrollPane = new JScrollPane(table); getContentPane().add(scrollPane,BorderLayout.CENTER); setJMenuBar(createMenuBar()); } ////////////////////////////////////////////////////////////////////////////// /** Creates the menu bar. @return the menu bar. */ public JMenuBar createMenuBar() { JMenuBar mb = new JMenuBar(); JMenu fileMenu = new JMenu("Datei"); JMenuItem previewItem = new JMenuItem("Preview"); previewItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { processPreview(); } }); JMenuItem exitItem = new JMenuItem("Beenden"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(previewItem); fileMenu.addSeparator(); fileMenu.add(exitItem); mb.add(fileMenu); return mb; } ////////////////////////////////////////////////////////////////////////////// /** Displays a print preview screen. */ protected void processPreview() { final JFreeReport report; try { report = parseReport(); report.setData(iData); PreviewFrame frame = new PreviewFrame(report); frame.getBase().setToolbarFloatable(true); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.setVisible(true); frame.requestFocus(); } catch (Exception ex) { JOptionPane.showMessageDialog(this,ex.toString(), "Exception",JOptionPane.ERROR_MESSAGE); return; } } ////////////////////////////////////////////////////////////////////////////// /** Reads the report from the specified template file. @return a report. */ private JFreeReport parseReport() throws Exception { JFreeReport result = null; final ReportGenerator generator = ReportGenerator.getInstance(); result = generator.parseReport(REPORT_DEFINITION); return result; } ////////////////////////////////////////////////////////////////////////////// /** Entry point for running the demo application... @param args ignored. */ public static void main(final String[] args) { Boot.start(); FreeSpace fs = new FreeSpace(); fs.pack(); fs.setVisible(true); } }