81 lines
2.2 KiB
Java
81 lines
2.2 KiB
Java
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
*/
|
|
|
|
package mvcgrafik.controller.commands;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import javax.swing.JFileChooser;
|
|
import mvcgrafik.model.GrafikModel;
|
|
import mvcgrafik.view.GrafikFrame;
|
|
|
|
/**
|
|
*
|
|
* @author ahren
|
|
*/
|
|
public class SaveCommand implements CommandInterface
|
|
{
|
|
private GrafikFrame view;
|
|
private GrafikModel model;
|
|
|
|
public SaveCommand(GrafikFrame view, GrafikModel model){
|
|
this.view = view;
|
|
this.model = model;
|
|
}
|
|
|
|
/**
|
|
* Aufrufen des File Choosers in zuletzt verwendeten Ordner, versuchen die
|
|
* Tabellendatei zu speichern
|
|
*/
|
|
@Override
|
|
public void execute() {
|
|
JFileChooser fc = view.getFcFileChooser();
|
|
String lastDirectory = model.getPref();
|
|
if (lastDirectory != null) {
|
|
fc.setCurrentDirectory(new File(lastDirectory));
|
|
}
|
|
int choice = fc.showSaveDialog(view);
|
|
if (choice == JFileChooser.APPROVE_OPTION)
|
|
{
|
|
File selectedFile = fc.getSelectedFile();
|
|
String filename = selectedFile.getAbsolutePath();
|
|
model.putPref("lastDirectory", selectedFile.getParent());
|
|
|
|
try
|
|
{
|
|
model.speicherePunkte(filename);
|
|
}
|
|
catch (FileNotFoundException ex)
|
|
{
|
|
Logger.getLogger(SaveCommand.class.getName()).log(Level.SEVERE, null, ex);
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
Logger.getLogger(SaveCommand.class.getName()).log(Level.SEVERE, null, ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public void undo() {
|
|
throw new UnsupportedOperationException("Not undoable."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
|
}
|
|
|
|
@Override
|
|
public void redo() {
|
|
throw new UnsupportedOperationException("Not redoable."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
|
}
|
|
|
|
@Override
|
|
public boolean isUndoable() {
|
|
return false;
|
|
}
|
|
|
|
}
|