1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /*
- * 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 commands;
-
- import java.io.File;
- import java.util.prefs.Preferences;
- import javax.swing.JFileChooser;
- import model.model;
- import view.gui;
-
- /**
- * Save Command
- * @author matthias
- */
- public class CommandSave implements CommandInterface {
- private File data;
- private gui g;
- private model mdl;
- private Preferences prfs;
- private String pid;
-
-
- public CommandSave(gui G, Preferences p, model mdl, String pid)
- {
- this.g = G;
- this.mdl = mdl;
- this.prfs = p;
- this.pid = pid;
- this.data = null;
- }
-
- /**
- * overrides execute vom CommandInterface
- * Öffnet den File Dialog und führt dann die Funtkion DatenSpeichern aus dem Modell aus
- */
- @Override
- public void execute() {
- System.out.println("save...");
- JFileChooser fc = this.g.getFileChooser();
- try
- {
- fc.setCurrentDirectory(new File(this.prfs.get(this.pid, "")));
- }
- catch(Exception ex)
- {
- System.err.println(ex);
- }
- if(fc.showSaveDialog(g) == JFileChooser.APPROVE_OPTION)
- {
- this.data = fc.getSelectedFile();
- this.g.getLblFilePath().setText(this.data.getAbsolutePath());
- this.prfs.put(this.pid, this.data.getAbsolutePath());
-
- try
- {
- this.mdl.datenSpeichern(this.data);
- }
- catch(Exception ex)
- {
- System.err.println(ex);
- }
- //System.out.println(this.pref.get(PATH_ID, "xyz"));
-
- }
- }
-
- @Override
- public void undo() {
- }
-
- }
|