/* * 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 mvcgrafik.controller; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; import javax.swing.JFileChooser; import mvcgrafik.model.Figure; import mvcgrafik.model.GrafikModel; import mvcgrafik.view.GrafikMenuView; import ohmlogger.OhmLogger; /** * * @author le */ public class BtnController implements ActionListener { private GrafikMenuView view; //private GrafikMenuView menuview; private GrafikModel model; private Figure figure; private Point p_old; private static Logger lg = OhmLogger.getLogger(); public BtnController(GrafikMenuView view, GrafikModel model) { this.view = view; this.model = model; } public void registerEvents() { view.getBtnOpen().addActionListener(this); view.getBtnSafe().addActionListener(this); } @Override public void actionPerformed(ActionEvent ae) { if(ae.getSource() == view.getBtnSafe()) { Preferences pref = Preferences.userNodeForPackage(this.getClass()); String path = pref.get("DEFAULT_PATH", ""); view.getjFileChooser1().setCurrentDirectory(new File(path)); int choice = view.getjFileChooser1().showSaveDialog(view); if (choice == JFileChooser.APPROVE_OPTION) { File selectedFile = view.getjFileChooser1().getSelectedFile(); pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath()); try { //model.datenSpeichern(selectedFile); model.speichereDatei("TEST"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); } } } if(ae.getSource() == view.getBtnOpen()) { Preferences pref = Preferences.userNodeForPackage(this.getClass()); String path = pref.get("DEFAULT_PATH", ""); view.getjFileChooser1().setCurrentDirectory(new File(path)); int choice = view.getjFileChooser1().showOpenDialog(view); if (choice == JFileChooser.APPROVE_OPTION) { File selectedFile = view.getjFileChooser1().getSelectedFile(); pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath()); try { //model.datenLesen(selectedFile); model.ladeDatei("TEST"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); } } } } }