12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- /*
- * 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;
-
-
- /**
- * Open Command
- * @author matthias
- */
- public class CommandOpen implements CommandInterface {
- private File data;
- private gui g;
- private Preferences pref;
- private String PATH_ID;
- private String FILE_ID;
- private model mdl;
-
- public CommandOpen(gui G, Preferences p, String pid, String fid, model m)
- {
- this.g = G;
- this.pref = p;
- this.PATH_ID = pid;
- this.FILE_ID = fid;
- this.data = null;
- this.mdl = m;
- }
-
- /**
- * overrides execute vom CommandInterface
- * Öffnet den File Dialog und führt dann die Funktion datenLesen aus dem Modell aus
- */
- @Override
- public void execute() {
- System.out.println("opening a file...");
- //System.out.println(this.pref.get(PATH_ID, "xyz"));
- JFileChooser fc = this.g.getFileChooser();
- try
- {
- fc.setCurrentDirectory(new File(this.pref.get(PATH_ID, "")));
- }
- catch(Exception ex)
- {
- System.err.println(ex);
- }
- if(fc.showOpenDialog(g) == JFileChooser.APPROVE_OPTION)
- {
- this.data = fc.getSelectedFile();
- this.g.getLblFilePath().setText(this.data.getAbsolutePath());
- this.pref.put(this.PATH_ID, this.data.getAbsolutePath());
-
- //System.out.println(this.pref.get(PATH_ID, "xyz"));
- try
- {
- this.mdl.datenLesen(this.data);
- }
- catch(Exception ex)
- {
- System.err.println(ex);
- }
- }
- }
-
- @Override
- public void undo() {
- }
-
- }
|