private void saveToFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveToFileMenuItemActionPerformed
        int button = this.saveToFileFileChooser.showSaveDialog(this);
        try {
            if (button == JFileChooser.APPROVE_OPTION) {
                File f = this.saveToFileFileChooser.getSelectedFile();
                if (f != null) {
                    if (!f.getName().toUpperCase().endsWith(".PNG")) {
                        f = new File(f.getParent(), f.getName() + ".png");
                    }

                    if (f.exists()) {
                        if (f.isFile()) {
                            int yesNo = JOptionPane.showConfirmDialog(this,
                                    "Do you want to overwrite the file \"" + f.getName() + "\"?",
                                    "Confirm overwrite",
                                    JOptionPane.YES_NO_OPTION,
                                    JOptionPane.QUESTION_MESSAGE);

                            if (yesNo == JOptionPane.YES_OPTION) {
                                this.saveFile(f);
                            }
                        } else {
                            throw new Exception("Invalid file.");
                        }
                    } else {
                        this.saveFile(f);
                    }
                } else {
                    throw new Exception("Empty file name.");
                }
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error while saving: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_saveToFileMenuItemActionPerformed