package cz.cvut.fel.restauracefel.storage.sklad_gui; import cz.cvut.fel.restauracefel.library.library_gui.PrintDialog; import java.awt.Dimension; import java.awt.Toolkit; import java.io.File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Map; import javax.swing.JFrame; import javax.swing.JOptionPane; import cz.cvut.fel.restauracefel.library.service.ConfigParser; import cz.cvut.fel.restauracefel.library.service.LocalizationManager; import cz.cvut.fel.restauracefel.sklad_service.ResultTableModel; import cz.cvut.fel.restauracefel.storage.storageController.StorageController; /** * * @author Lukas Camra */ public class StatistikaDialog extends javax.swing.JDialog { /** Creates new form StatistikaDialog */ //private Object[][]data; public StatistikaDialog(java.awt.Frame parent, boolean modal, Object[][] data) { super(parent, modal); initComponents(); LocalizationManager manager = LocalizationManager.getInstance(); manager.localizeDialog(StorageController.DEFAULT_BUNDLE_BASE_NAME, "StatisticsDialog", this); manager.localizeButton(StorageController.DEFAULT_BUNDLE_BASE_NAME, "PrintButton", print); manager.localizeButton(StorageController.DEFAULT_BUNDLE_BASE_NAME, "CloseButton", close); ResultTableModel model = new ResultTableModel(ResultTableModel.namesUzaverkaStatistika, data); //this.data = data; table.setModel(model); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int y = (int) ((dim.getHeight() - getHeight()) / 2); int x = (int) ((dim.getWidth() - getWidth()) / 2); setLocation(x, y); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { scrollPane = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); print = new javax.swing.JButton(); close = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); table.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { } )); scrollPane.setViewportView(table); print.setText("Vytisknout"); print.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { printActionPerformed(evt); } }); close.setText("Zavřít"); close.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(print) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(close) .addGap(240, 240, 240)) .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(print) .addComponent(close)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeActionPerformed // TODO add your handling code here: dispose(); }//GEN-LAST:event_closeActionPerformed private void printActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printActionPerformed // TODO add your handling code here: Map<String, Object> params = new HashMap<String, Object>(); try { String template = "stats.jasper"; ConfigParser config = new ConfigParser(); params.put("title", "Statistika uzávěrek"); String printingFilePath = config.getTemplatesDir() + System.getProperty("file.separator") + template; File printFile = new File(printingFilePath); if (!printFile.exists()) { JOptionPane.showMessageDialog(null, "Šablona \"" + template + "\" nebyla v adresáři:\n\n " + config.getTemplatesDir() + "\n\n nelezena. Pokud se šablony nachází v jiném adresáři, " + "nastavte cestu k tomuto adresáři v nastavení.", "Tisková sestava nenalezena", JOptionPane.ERROR_MESSAGE); return; } PrintDialog printDialog = new PrintDialog((JFrame) super.getParent(), true, params, printFile); printDialog.setTable(table); printDialog.setVisible(true); //Printer.compileReport(printFile, config.getTemplatesDir() + System.getProperty("file.separator") + "stats.jasper"); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(this, "Konfigurační soubor \"" + ConfigParser.getConfigFile() + "\" nebyl nalezen.", "Chyba", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "Nelze navázat spojení se serverem.", "Chyba komunikace", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_printActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton close; private javax.swing.JButton print; private javax.swing.JScrollPane scrollPane; private javax.swing.JTable table; // End of variables declaration//GEN-END:variables }