@@ -71,7 +71,7 @@ jlink.additionalmodules= | |||
jlink.additionalparam= | |||
jlink.launcher=true | |||
jlink.launcher.name=Adressverwaltung | |||
main.class=adressverwaltung.main | |||
main.class=adressverwaltung.Main | |||
manifest.file=manifest.mf | |||
meta.inf.dir=${src.dir}/META-INF | |||
mkdist.disabled=false |
@@ -33,9 +33,9 @@ public class CommandEintragHinzufuegen implements CommandInterface{ | |||
@Override | |||
public void undo() { | |||
this.model.eintragLoeschen(this.model.getRowCount()-1); | |||
} | |||
@Override | |||
public boolean isUndoable() { | |||
return true; |
@@ -0,0 +1,81 @@ | |||
/* | |||
* 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; | |||
} | |||
} |
@@ -0,0 +1,68 @@ | |||
/* | |||
* 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.io.File; | |||
import java.io.IOException; | |||
import java.io.UnsupportedEncodingException; | |||
import java.util.prefs.Preferences; | |||
import javax.swing.JFileChooser; | |||
import model.AdressVerwaltungModel; | |||
import view.MainWindow; | |||
/** | |||
* | |||
* @author PC | |||
*/ | |||
public class CommandSaveFile implements CommandInterface{ | |||
private MainWindow view; | |||
private AdressVerwaltungModel model; | |||
private Preferences prefs; | |||
public CommandSaveFile(MainWindow view, AdressVerwaltungModel model) { | |||
this.view = view; | |||
this.model = model; | |||
this.prefs = model.getPreferences(); | |||
} | |||
@Override | |||
public void execute() { | |||
int wahl = view.getjFileChooser().showSaveDialog(view); | |||
if(wahl == JFileChooser.APPROVE_OPTION) | |||
{ | |||
File file = view.getjFileChooser().getSelectedFile(); | |||
view.getStatusbar().setText("Datei wird gespeichert..."); | |||
try | |||
{ | |||
model.datenSpeichern(file); | |||
} | |||
catch (UnsupportedEncodingException ex) | |||
{ | |||
view.getStatusbar().setText(ex.toString()); | |||
} | |||
catch (IOException ex ) | |||
{ | |||
view.getStatusbar().setText(ex.toString()); | |||
} | |||
} | |||
} | |||
@Override | |||
public void undo() { | |||
} | |||
@Override | |||
public boolean isUndoable() { | |||
return false; | |||
} | |||
} |
@@ -9,6 +9,8 @@ import command.CommandInterface; | |||
import command.CommandInvoker; | |||
import command.commands.CommandEintragHinzufuegen; | |||
import command.commands.CommandEintragLoeschen; | |||
import command.commands.CommandOpenFile; | |||
import command.commands.CommandSaveFile; | |||
import java.awt.event.ActionEvent; | |||
import java.awt.event.ActionListener; | |||
import java.awt.event.WindowEvent; | |||
@@ -29,16 +31,15 @@ public class CommandController implements ActionListener, WindowListener{ | |||
private MainWindow view; | |||
private AdressVerwaltungModel model; | |||
private CommandInvoker invoker; | |||
private Preferences prefs; | |||
//private Preferences prefs; | |||
public CommandController(MainWindow view, AdressVerwaltungModel model) | |||
{ | |||
this.view = view; | |||
this.model = model; | |||
this.invoker = new CommandInvoker(); | |||
this.prefs = Preferences.userRoot().node(this.getClass().getName()); | |||
view.getjTableAdressen().setModel(model); //Übernehme Model | |||
//this.prefs = Preferences.userRoot().node(this.getClass().getName()); | |||
registerEvents(); | |||
registerCommands(); | |||
@@ -50,6 +51,15 @@ public class CommandController implements ActionListener, WindowListener{ | |||
{ | |||
view.getJpopEintragHinzufuegen().addActionListener(this); | |||
view.getJpopEintragLoeschen().addActionListener(this); | |||
view.getJbOpen().addActionListener(this); | |||
view.getJbSave().addActionListener(this); | |||
view.getFileOpen().addActionListener(this); | |||
view.getFileSave().addActionListener(this); | |||
view.getMiUndo().addActionListener(this); | |||
} | |||
@@ -57,17 +67,47 @@ public class CommandController implements ActionListener, WindowListener{ | |||
{ | |||
CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model); | |||
CommandEintragLoeschen cmdLoeschen = new CommandEintragLoeschen(view, model); | |||
CommandSaveFile cmdSaveFile = new CommandSaveFile(view, model); | |||
CommandOpenFile cmdOpenFile = new CommandOpenFile(view, model); | |||
invoker.addCommand(view.getJpopEintragHinzufuegen(), cmdHinzufuegen); | |||
invoker.addCommand(view.getJpopEintragLoeschen(), cmdLoeschen); | |||
invoker.addCommand(view.getJbOpen(), cmdOpenFile); | |||
invoker.addCommand(view.getJbSave(), cmdSaveFile); | |||
invoker.addCommand(view.getFileOpen(), cmdOpenFile); | |||
invoker.addCommand(view.getFileSave(), cmdSaveFile); | |||
} | |||
/** | |||
* actionPerformed Funktion wird aufgerufen | |||
* @param evt | |||
* <br> | |||
* Hallo Guten Tag | |||
*/ | |||
@Override | |||
public void actionPerformed(ActionEvent evt) { | |||
Object key = evt.getSource(); | |||
invoker.executeCommand(key); | |||
if(key == view.getMiUndo()) | |||
{ | |||
invoker.undoCommand(); | |||
} | |||
else | |||
{ | |||
invoker.executeCommand(key); | |||
} | |||
} | |||
@Override |
@@ -1,43 +0,0 @@ | |||
/* | |||
* 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 controller; | |||
import java.awt.event.ActionEvent; | |||
import java.awt.event.ActionListener; | |||
import java.io.File; | |||
import java.util.Locale; | |||
import javax.swing.JFileChooser; | |||
import view.MainWindow; | |||
/** | |||
* | |||
* @author PC | |||
*/ | |||
public class OpenController implements ActionListener{ | |||
private MainWindow mainwindow; | |||
public OpenController(MainWindow mainwindow) | |||
{ | |||
this.mainwindow = mainwindow; | |||
registerEvents(); | |||
} | |||
public void registerEvents() | |||
{ | |||
mainwindow.getJbOpen().addActionListener(this); | |||
mainwindow.getFileOpen().addActionListener(this); | |||
} | |||
@Override | |||
public void actionPerformed(ActionEvent ae) { | |||
int wahl = mainwindow.getjFileChooser().showOpenDialog(mainwindow); | |||
if(wahl == JFileChooser.APPROVE_OPTION) | |||
{ | |||
File file = mainwindow.getjFileChooser().getSelectedFile(); | |||
mainwindow.getStatusbar().setText(file.getAbsolutePath()); | |||
} | |||
} | |||
} |
@@ -15,6 +15,7 @@ import java.io.IOException; | |||
import java.io.ObjectInputStream; | |||
import java.io.ObjectOutputStream; | |||
import java.util.ArrayList; | |||
import java.util.prefs.Preferences; | |||
import javax.swing.table.AbstractTableModel; | |||
/** | |||
@@ -30,6 +31,7 @@ public class AdressVerwaltungModel extends AbstractTableModel | |||
private ArrayList<ArrayList<String>> daten; | |||
private ArrayList<String> adressEintraegeDaten; | |||
private ArrayList<String> adressEintraegeNamen; | |||
private Preferences prefs; | |||
/** | |||
@@ -37,6 +39,10 @@ public class AdressVerwaltungModel extends AbstractTableModel | |||
*/ | |||
public AdressVerwaltungModel() | |||
{ | |||
initializePreferences(); | |||
adressEintraegeDaten = new ArrayList<>(); | |||
adressEintraegeNamen = new ArrayList<>(); | |||
daten = new ArrayList<>(); | |||
@@ -92,6 +98,16 @@ public class AdressVerwaltungModel extends AbstractTableModel | |||
return adressEintraegeNamen.get(col); | |||
} | |||
public Preferences getPreferences() | |||
{ | |||
return this.prefs; | |||
} | |||
public void initializePreferences() | |||
{ | |||
this.prefs = Preferences.userRoot().node(this.getClass().getName()); | |||
} | |||
public ArrayList<String> getLastRowData() | |||
{ | |||
ArrayList<String> lastRow = new ArrayList<>(); |
@@ -25,6 +25,9 @@ public class MainWindow extends javax.swing.JFrame { | |||
return jpopEintragLoeschen; | |||
} | |||
/** | |||
* Creates new form MainFrame | |||
*/ | |||
@@ -287,4 +290,11 @@ public class MainWindow extends javax.swing.JFrame { | |||
public void setjTableAdressen(javax.swing.JTable jTableAdressen) { | |||
this.jTableAdressen = jTableAdressen; | |||
} | |||
/** | |||
* @return the miUndo | |||
*/ | |||
public javax.swing.JMenuItem getMiUndo() { | |||
return miUndo; | |||
} | |||
} |