/*
 * Copyright
 *   2008 axYus - www.axyus.com
 *   2008 L.Meckert - laurent.meckert.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS 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.
 *
 * XEMELIOS 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 XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
/*
 * OutputFilePanel.java
 *
 * Created on 16 octobre 2008, 12:39
 */
package fr.gouv.finances.cp.xemelios.plugin.signerfichier;

import org.netbeans.spi.wizard.*;
import java.io.File;
import java.awt.Component;

/**
 *
 * @author  laurent.meckert
 */
public class OutputFilePanel extends WizardPage {

    /** Creates new form OutputFilePanel */
    public OutputFilePanel() {
        initComponents();
        if(Actions.getInstance().getFileToGenerate()!=null) {
            showSelectedOutputFile(Actions.getInstance().getFileToGenerate());
        }
    }

    void showSelectedOutputFile(File f) {
        textFieldOutputFile.setText(f.getAbsolutePath());
    }

    @Override
    protected String validateContents(Component comp, Object o) {
        if (textFieldOutputFile.getText().length() == 0) {
            return "Sélectionner un fichier SVP";
        } else {
            if(Actions.getInstance().getFileToGenerate().exists()) {
                return "Attention, un fichier de ce nom existe déjà.";
            }
            return null;
        }
    }

    public static final String getDescription() {
        return "Sélection du fichier résultat";
    }

    /** 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() {

        jLabel3 = new javax.swing.JLabel();
        textFieldOutputFile = new javax.swing.JTextField();
        jButtonOutputFile = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel3.setText("Utiliser le bouton .. pour indiquer le répertoire et le fichier résultat");

        textFieldOutputFile.setEditable(false);
        textFieldOutputFile.setDisabledTextColor(new java.awt.Color(204, 204, 255));
        textFieldOutputFile.setName("TextFieldOutputFile"); // NOI18N
        textFieldOutputFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldOutputFileActionPerformed(evt);
            }
        });

        jButtonOutputFile.setText("...");
        jButtonOutputFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOutputFileActionPerformed(evt);
            }
        });

        jLabel1.setText("Enregistrer le fichier signé sous");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(textFieldOutputFile, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButtonOutputFile))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
                    .add(jLabel1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(21, 21, 21)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(textFieldOutputFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonOutputFile))
                .add(18, 18, 18)
                .add(jLabel3)
                .addContainerGap(95, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void textFieldOutputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldOutputFileActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_textFieldOutputFileActionPerformed

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

    try {
        Actions.getInstance().chooseOutputFile();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (Actions.getInstance().getFileToGenerate() != null) {
        showSelectedOutputFile(Actions.getInstance().getFileToGenerate());
    }
}//GEN-LAST:event_jButtonOutputFileActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonOutputFile;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField textFieldOutputFile;
    // End of variables declaration//GEN-END:variables
}
