123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /*
- * 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 command.commands;
-
- import command.CommandInterface;
- import java.awt.event.ActionEvent;
- import java.io.File;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.prefs.Preferences;
- import javax.swing.JFileChooser;
- import model.AdressVerwaltungModel;
- import view.MainWindow;
-
- /**
- *
- * @author PC
- */
- public class CommandOpenFile implements CommandInterface{
- private MainWindow view;
- private AdressVerwaltungModel model;
- private Preferences prefs;
-
- public CommandOpenFile(MainWindow view, AdressVerwaltungModel model) {
-
- this.view = view;
- this.model = model;
- this.prefs = model.getPreferences();
-
- }
-
-
-
-
- @Override
- public void execute() {
- String lastDirectoryPath = prefs.get("lastFileOpened", "");
- File file = new File(lastDirectoryPath);
- view.getjFileChooser().setCurrentDirectory(file);
- int wahl = view.getjFileChooser().showOpenDialog(view);
- if(wahl == JFileChooser.APPROVE_OPTION)
- {
-
- file = view.getjFileChooser().getSelectedFile();
- view.getStatusbar().setText(file.getAbsolutePath());
- prefs.put("lastFileOpened", file.getAbsolutePath());
-
- try
- {
- model.datenLesen(file);
- }
- catch (UnsupportedEncodingException ex)
- {
- view.getStatusbar().setText(ex.toString());
- }
- catch (IOException | ClassNotFoundException ex )
- {
- view.getStatusbar().setText(ex.toString());
- }
-
-
- }
-
- }
-
-
- @Override
- public void undo() {
-
- }
-
- @Override
- public boolean isUndoable() {
- return false;
- }
-
- }
|