12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
- package controller.commands;
-
- import model.AdressverwaltungModel;
- import controller.Interface;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import javax.swing.JFileChooser;
- import prfourgui.Constants;
- import prfourgui.View.AdressbuchView;
-
- /**
- *
- * @author jechowma68968
- */
- public class CommandSave implements Interface
- {
- private final AdressbuchView view;
- private final AdressverwaltungModel model;
-
- public CommandSave(AdressbuchView view, AdressverwaltungModel model)
- {
- this.view = view;
- this.model = model;
- }
-
- @Override
- public void execute()
- {
- File datei;
- JFileChooser fc = view.getjFileChooser1();
- int wahl = fc.showOpenDialog(view);
- if(wahl == JFileChooser.APPROVE_OPTION){
- datei = fc.getSelectedFile();
- String dateiname = datei.getAbsolutePath();
- model.setPref(Constants.PREF_KEY_DIR, dateiname);
- view.getTxtStatus().setText("Dateipfad:" + dateiname);
-
- try{
- model.datenSpeichern(datei);
- }
- catch(FileNotFoundException e){
- System.out.println("File not Found Error");
- }
- catch(IOException e){
- System.out.println("Reading Error");
- }
- }
- }
-
- @Override
- public void undo()
- {
- }
- }
|