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.

CommandSave.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 commands;
  7. import java.io.File;
  8. import java.util.prefs.Preferences;
  9. import javax.swing.JFileChooser;
  10. import model.model;
  11. import view.gui;
  12. /**
  13. * Save Command
  14. * @author matthias
  15. */
  16. public class CommandSave implements CommandInterface {
  17. private File data;
  18. private gui g;
  19. private model mdl;
  20. private Preferences prfs;
  21. private String pid;
  22. public CommandSave(gui G, Preferences p, model mdl, String pid)
  23. {
  24. this.g = G;
  25. this.mdl = mdl;
  26. this.prfs = p;
  27. this.pid = pid;
  28. this.data = null;
  29. }
  30. /**
  31. * overrides execute vom CommandInterface
  32. * Öffnet den File Dialog und führt dann die Funtkion DatenSpeichern aus dem Modell aus
  33. */
  34. @Override
  35. public void execute() {
  36. System.out.println("save...");
  37. JFileChooser fc = this.g.getFileChooser();
  38. try
  39. {
  40. fc.setCurrentDirectory(new File(this.prfs.get(this.pid, "")));
  41. }
  42. catch(Exception ex)
  43. {
  44. System.err.println(ex);
  45. }
  46. if(fc.showSaveDialog(g) == JFileChooser.APPROVE_OPTION)
  47. {
  48. this.data = fc.getSelectedFile();
  49. this.g.getLblFilePath().setText(this.data.getAbsolutePath());
  50. this.prfs.put(this.pid, this.data.getAbsolutePath());
  51. try
  52. {
  53. this.mdl.datenSpeichern(this.data);
  54. }
  55. catch(Exception ex)
  56. {
  57. System.err.println(ex);
  58. }
  59. //System.out.println(this.pref.get(PATH_ID, "xyz"));
  60. }
  61. }
  62. @Override
  63. public void undo() {
  64. }
  65. }