private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed

    if (!evt.getActionCommand().equals("CancelSelection")){
    /*    System.err.println("Cancel");
    }
    else{*/
        if (this.jFileChooser1.getSelectedFile() != null){
               // File file = this.jFileChooser1.getSelectedFile();
                if (true){
                    if (this.genfitController != null){
                        //this.genfitController.setGenfitFile(new GenfitFile(this.jFileChooser1.getSelectedFile().getAbsolutePath()));
                        try {
                            if ((this.jFileChooser1.getSelectedFile().getName().length() == 11) && (this.jFileChooser1.getSelectedFile().getName().startsWith("gen") && this.jFileChooser1.getSelectedFile().getName().endsWith(".dat"))){
                                this.genfitController.save(this.jFileChooser1.getSelectedFile().getAbsolutePath());                           
                                GenfitPropertiesReader.setLastOpenedFile(this.jFileChooser1.getSelectedFile().getAbsolutePath());
                                
                                if (this.genfitView != null){
                                    this.genfitView.setStatusBarLabel("File saved " + this.jFileChooser1.getSelectedFile().getAbsolutePath());
                                }
                            }
                            else{                                
                                JOptionPane.showMessageDialog(null,
                                    "File name is not correct. It should be named as genXXXX.dat where XXXX is the run number",
                                    "Warning",
                                    JOptionPane.WARNING_MESSAGE);
                                return;                            
                            }
                        } catch (Exception ex) {
                            Logger.getLogger(SaveJDialog.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    else{
                         GenfitLogger.error("Controller is null");
                    }
                }
                else{
                    GenfitLogger.error("File no readable");
                }            
        }
        else{
            GenfitLogger.error("Selected file: null");
        }       
    }
    this.setVisible(false);
    
    
}//GEN-LAST:event_jFileChooser1ActionPerformed