Package practica1.actions

Source Code of practica1.actions.ActionGuardarComo

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package practica1.actions;

import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import practica1.Practica1;
import practica1.controller.Controller;
import practica1.language.Language;
import practica1.language.LanguageEvent;
import practica1.language.LanguageListener;
import practica1.logic.LogicExperimento;
import practica1.manejoExperimento.ExperimentoInvalidoException;
import practica1.manejoExperimento.ManejoExperimento;
import practica1.ui.dialog.DialogGuardarComo;

/**
* Clase que implementa la acción de Guardar Como de un experimento
* @author Miguel González - Ceura
*/
public class ActionGuardarComo extends AbstractAction implements LanguageListener {

    /**
     * Constructor de la clase
     */
    public ActionGuardarComo() {
        super(Language.getI().getP("GUARDAR_COMO"), null);

        Language.getI().addLanguageListener(this);
       
        putValue(SHORT_DESCRIPTION, Language.getI().getP("GUARDAR_COMO"));
        putValue(NAME, Language.getI().getP("GUARDAR_COMO"));
        putValue(SELECTED_KEY, Boolean.TRUE);
    }
   
    /**
     * Cuando sucede la acción nos encargamos de guardar el experimento seleccionado
     * @param e ActionEvent
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        LogicExperimento exp = Controller.getInstance().
                getExperimentoSeleccionado();
       
        DialogGuardarComo dialog = new DialogGuardarComo(
                Practica1.getInstance(), exp);
       
        dialog.setVisible(true);

        if(dialog.getAction() == DialogGuardarComo.ACEPTAR) {
            File fich = new File(dialog.getRutaFichExperimento());
            exp.setFichExperimento(fich);
           
            try {
                ManejoExperimento.guardarExperimento(exp);
            } catch (ExperimentoInvalidoException ex) {
                JOptionPane.showMessageDialog(Practica1.getInstance(),
                    Language.getI().getP("PROBLEMA_GUARDAR"),
                    Language.getI().getP("ERROR"), JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    /**
     * Al cambiar el idioma actualizamos el nombre y la descripción
     * @param evt LanguageEvent
     */
    @Override
    public void idiomaChange(LanguageEvent evt) {
        putValue(SHORT_DESCRIPTION, Language.getI().getP("GUARDAR_COMO"));
        putValue(NAME, Language.getI().getP("GUARDAR_COMO"));
    }
}
TOP

Related Classes of practica1.actions.ActionGuardarComo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.