Compare commits
No commits in common. "c111929961bcb2890d19209613aad8abdd8b3683" and "41ba75bd7caa78831b1a73ee92773c2d45b5fae7" have entirely different histories.
c111929961
...
41ba75bd7c
@ -71,7 +71,7 @@ jlink.additionalmodules=
|
|||||||
jlink.additionalparam=
|
jlink.additionalparam=
|
||||||
jlink.launcher=true
|
jlink.launcher=true
|
||||||
jlink.launcher.name=Adressverwaltung
|
jlink.launcher.name=Adressverwaltung
|
||||||
main.class=adressverwaltung.Main
|
main.class=adressverwaltung.main
|
||||||
manifest.file=manifest.mf
|
manifest.file=manifest.mf
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
mkdist.disabled=false
|
mkdist.disabled=false
|
||||||
|
40
src/adressverwaltung/main.java
Normal file
40
src/adressverwaltung/main.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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 adressverwaltung;
|
||||||
|
import controller.CommandController;
|
||||||
|
import view.MainWindow;
|
||||||
|
import controller.OpenController;
|
||||||
|
import model.AdressVerwaltungModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author PC
|
||||||
|
*/
|
||||||
|
public class main {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public main() {
|
||||||
|
MainWindow mainwindow = new MainWindow();
|
||||||
|
OpenController opencontroller = new OpenController(mainwindow);
|
||||||
|
AdressVerwaltungModel model = new AdressVerwaltungModel();
|
||||||
|
CommandController cmdController = new CommandController(mainwindow, model);
|
||||||
|
|
||||||
|
mainwindow.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new main();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,7 +33,7 @@ public class CommandEintragHinzufuegen implements CommandInterface{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
this.model.eintragLoeschen(this.model.getRowCount()-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,81 +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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,68 +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 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,8 +9,6 @@ import command.CommandInterface;
|
|||||||
import command.CommandInvoker;
|
import command.CommandInvoker;
|
||||||
import command.commands.CommandEintragHinzufuegen;
|
import command.commands.CommandEintragHinzufuegen;
|
||||||
import command.commands.CommandEintragLoeschen;
|
import command.commands.CommandEintragLoeschen;
|
||||||
import command.commands.CommandOpenFile;
|
|
||||||
import command.commands.CommandSaveFile;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
@ -31,15 +29,16 @@ public class CommandController implements ActionListener, WindowListener{
|
|||||||
private MainWindow view;
|
private MainWindow view;
|
||||||
private AdressVerwaltungModel model;
|
private AdressVerwaltungModel model;
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
//private Preferences prefs;
|
private Preferences prefs;
|
||||||
|
|
||||||
public CommandController(MainWindow view, AdressVerwaltungModel model)
|
public CommandController(MainWindow view, AdressVerwaltungModel model)
|
||||||
{
|
{
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
//this.prefs = Preferences.userRoot().node(this.getClass().getName());
|
this.prefs = Preferences.userRoot().node(this.getClass().getName());
|
||||||
|
|
||||||
|
view.getjTableAdressen().setModel(model); //Übernehme Model
|
||||||
|
|
||||||
registerEvents();
|
registerEvents();
|
||||||
registerCommands();
|
registerCommands();
|
||||||
@ -51,15 +50,6 @@ public class CommandController implements ActionListener, WindowListener{
|
|||||||
{
|
{
|
||||||
view.getJpopEintragHinzufuegen().addActionListener(this);
|
view.getJpopEintragHinzufuegen().addActionListener(this);
|
||||||
view.getJpopEintragLoeschen().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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,49 +57,19 @@ public class CommandController implements ActionListener, WindowListener{
|
|||||||
{
|
{
|
||||||
CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model);
|
CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model);
|
||||||
CommandEintragLoeschen cmdLoeschen = new CommandEintragLoeschen(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.getJpopEintragHinzufuegen(), cmdHinzufuegen);
|
||||||
invoker.addCommand(view.getJpopEintragLoeschen(), cmdLoeschen);
|
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
|
@Override
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
Object key = evt.getSource();
|
Object key = evt.getSource();
|
||||||
|
|
||||||
if(key == view.getMiUndo())
|
|
||||||
{
|
|
||||||
invoker.undoCommand();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
invoker.executeCommand(key);
|
invoker.executeCommand(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowOpened(WindowEvent we) {
|
public void windowOpened(WindowEvent we) {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
43
src/controller/OpenController.java
Normal file
43
src/controller/OpenController.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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,7 +15,6 @@ import java.io.IOException;
|
|||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.prefs.Preferences;
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +30,6 @@ public class AdressVerwaltungModel extends AbstractTableModel
|
|||||||
private ArrayList<ArrayList<String>> daten;
|
private ArrayList<ArrayList<String>> daten;
|
||||||
private ArrayList<String> adressEintraegeDaten;
|
private ArrayList<String> adressEintraegeDaten;
|
||||||
private ArrayList<String> adressEintraegeNamen;
|
private ArrayList<String> adressEintraegeNamen;
|
||||||
private Preferences prefs;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,10 +37,6 @@ public class AdressVerwaltungModel extends AbstractTableModel
|
|||||||
*/
|
*/
|
||||||
public AdressVerwaltungModel()
|
public AdressVerwaltungModel()
|
||||||
{
|
{
|
||||||
|
|
||||||
initializePreferences();
|
|
||||||
|
|
||||||
|
|
||||||
adressEintraegeDaten = new ArrayList<>();
|
adressEintraegeDaten = new ArrayList<>();
|
||||||
adressEintraegeNamen = new ArrayList<>();
|
adressEintraegeNamen = new ArrayList<>();
|
||||||
daten = new ArrayList<>();
|
daten = new ArrayList<>();
|
||||||
@ -98,16 +92,6 @@ public class AdressVerwaltungModel extends AbstractTableModel
|
|||||||
return adressEintraegeNamen.get(col);
|
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()
|
public ArrayList<String> getLastRowData()
|
||||||
{
|
{
|
||||||
ArrayList<String> lastRow = new ArrayList<>();
|
ArrayList<String> lastRow = new ArrayList<>();
|
||||||
|
@ -25,9 +25,6 @@ public class MainWindow extends javax.swing.JFrame {
|
|||||||
return jpopEintragLoeschen;
|
return jpopEintragLoeschen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form MainFrame
|
* Creates new form MainFrame
|
||||||
*/
|
*/
|
||||||
@ -290,11 +287,4 @@ public class MainWindow extends javax.swing.JFrame {
|
|||||||
public void setjTableAdressen(javax.swing.JTable jTableAdressen) {
|
public void setjTableAdressen(javax.swing.JTable jTableAdressen) {
|
||||||
this.jTableAdressen = jTableAdressen;
|
this.jTableAdressen = jTableAdressen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the miUndo
|
|
||||||
*/
|
|
||||||
public javax.swing.JMenuItem getMiUndo() {
|
|
||||||
return miUndo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user