123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /*
- * 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);
- }
- }
- }
- }
- }
|