You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BtnController.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package mvcgrafik.controller;
  7. import java.awt.Point;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.io.File;
  11. import java.io.IOException;
  12. import java.io.UnsupportedEncodingException;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. import java.util.prefs.Preferences;
  16. import javax.swing.JFileChooser;
  17. import mvcgrafik.model.Figure;
  18. import mvcgrafik.model.GrafikModel;
  19. import mvcgrafik.view.GrafikMenuView;
  20. import ohmlogger.OhmLogger;
  21. /**
  22. *
  23. * @author le
  24. */
  25. public class BtnController implements ActionListener
  26. {
  27. private GrafikMenuView view;
  28. //private GrafikMenuView menuview;
  29. private GrafikModel model;
  30. private Figure figure;
  31. private Point p_old;
  32. private static Logger lg = OhmLogger.getLogger();
  33. public BtnController(GrafikMenuView view, GrafikModel model)
  34. {
  35. this.view = view;
  36. this.model = model;
  37. }
  38. public void registerEvents()
  39. {
  40. view.getBtnOpen().addActionListener(this);
  41. view.getBtnSafe().addActionListener(this);
  42. }
  43. @Override
  44. public void actionPerformed(ActionEvent ae)
  45. {
  46. if(ae.getSource() == view.getBtnSafe())
  47. {
  48. Preferences pref = Preferences.userNodeForPackage(this.getClass());
  49. String path = pref.get("DEFAULT_PATH", "");
  50. view.getjFileChooser1().setCurrentDirectory(new File(path));
  51. int choice = view.getjFileChooser1().showSaveDialog(view);
  52. if (choice == JFileChooser.APPROVE_OPTION)
  53. {
  54. File selectedFile = view.getjFileChooser1().getSelectedFile();
  55. pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath());
  56. try
  57. {
  58. //model.datenSpeichern(selectedFile);
  59. model.speichereDatei("TEST");
  60. }
  61. catch (UnsupportedEncodingException ex)
  62. {
  63. Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
  64. }
  65. catch (IOException ex)
  66. {
  67. Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
  68. }
  69. }
  70. }
  71. if(ae.getSource() == view.getBtnOpen())
  72. {
  73. Preferences pref = Preferences.userNodeForPackage(this.getClass());
  74. String path = pref.get("DEFAULT_PATH", "");
  75. view.getjFileChooser1().setCurrentDirectory(new File(path));
  76. int choice = view.getjFileChooser1().showOpenDialog(view);
  77. if (choice == JFileChooser.APPROVE_OPTION)
  78. {
  79. File selectedFile = view.getjFileChooser1().getSelectedFile();
  80. pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath());
  81. try
  82. {
  83. //model.datenLesen(selectedFile);
  84. model.ladeDatei("TEST");
  85. }
  86. catch (UnsupportedEncodingException ex)
  87. {
  88. Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
  89. }
  90. catch (IOException | ClassNotFoundException ex)
  91. {
  92. Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex);
  93. }
  94. }
  95. }
  96. }
  97. }