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.

CommandOpen.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * Open Command
  14. * @author matthias
  15. */
  16. public class CommandOpen implements CommandInterface {
  17. private File data;
  18. private gui g;
  19. private Preferences pref;
  20. private String PATH_ID;
  21. private String FILE_ID;
  22. private model mdl;
  23. public CommandOpen(gui G, Preferences p, String pid, String fid, model m)
  24. {
  25. this.g = G;
  26. this.pref = p;
  27. this.PATH_ID = pid;
  28. this.FILE_ID = fid;
  29. this.data = null;
  30. this.mdl = m;
  31. }
  32. /**
  33. * overrides execute vom CommandInterface
  34. * Öffnet den File Dialog und führt dann die Funktion datenLesen aus dem Modell aus
  35. */
  36. @Override
  37. public void execute() {
  38. System.out.println("opening a file...");
  39. //System.out.println(this.pref.get(PATH_ID, "xyz"));
  40. JFileChooser fc = this.g.getFileChooser();
  41. try
  42. {
  43. fc.setCurrentDirectory(new File(this.pref.get(PATH_ID, "")));
  44. }
  45. catch(Exception ex)
  46. {
  47. System.err.println(ex);
  48. }
  49. if(fc.showOpenDialog(g) == JFileChooser.APPROVE_OPTION)
  50. {
  51. this.data = fc.getSelectedFile();
  52. this.g.getLblFilePath().setText(this.data.getAbsolutePath());
  53. this.pref.put(this.PATH_ID, this.data.getAbsolutePath());
  54. //System.out.println(this.pref.get(PATH_ID, "xyz"));
  55. try
  56. {
  57. this.mdl.datenLesen(this.data);
  58. }
  59. catch(Exception ex)
  60. {
  61. System.err.println(ex);
  62. }
  63. }
  64. }
  65. @Override
  66. public void undo() {
  67. }
  68. }