You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandSaveFile.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package command.commands;
  7. import command.CommandInterface;
  8. import java.io.File;
  9. import java.io.IOException;
  10. import java.io.UnsupportedEncodingException;
  11. import java.util.prefs.Preferences;
  12. import javax.swing.JFileChooser;
  13. import model.AdressVerwaltungModel;
  14. import view.MainWindow;
  15. /**
  16. *
  17. * @author PC
  18. */
  19. public class CommandSaveFile implements CommandInterface{
  20. private MainWindow view;
  21. private AdressVerwaltungModel model;
  22. private Preferences prefs;
  23. public CommandSaveFile(MainWindow view, AdressVerwaltungModel model) {
  24. this.view = view;
  25. this.model = model;
  26. this.prefs = model.getPreferences();
  27. }
  28. @Override
  29. public void execute() {
  30. int wahl = view.getjFileChooser().showSaveDialog(view);
  31. if(wahl == JFileChooser.APPROVE_OPTION)
  32. {
  33. File file = view.getjFileChooser().getSelectedFile();
  34. view.getStatusbar().setText("Datei wird gespeichert...");
  35. try
  36. {
  37. model.datenSpeichern(file);
  38. }
  39. catch (UnsupportedEncodingException ex)
  40. {
  41. view.getStatusbar().setText(ex.toString());
  42. }
  43. catch (IOException ex )
  44. {
  45. view.getStatusbar().setText(ex.toString());
  46. }
  47. }
  48. }
  49. @Override
  50. public void undo() {
  51. }
  52. @Override
  53. public boolean isUndoable() {
  54. return false;
  55. }
  56. }