Browse Source

Neuer Commit 10.11.2020

master
Sebastian Schneider 4 years ago
parent
commit
23f78083c6

+ 1
- 1
nbproject/project.properties View File

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

+ 2
- 2
src/command/commands/CommandEintragHinzufuegen.java View File

@Override @Override
public void undo() { public void undo() {
this.model.eintragLoeschen(this.model.getRowCount()-1);
} }
@Override @Override
public boolean isUndoable() { public boolean isUndoable() {
return true; return true;

+ 81
- 0
src/command/commands/CommandOpenFile.java View File

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

+ 68
- 0
src/command/commands/CommandSaveFile.java View File

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

+ 46
- 6
src/controller/CommandController.java View File

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;
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());
view.getjTableAdressen().setModel(model); //Übernehme Model
//this.prefs = Preferences.userRoot().node(this.getClass().getName());
registerEvents(); registerEvents();
registerCommands(); registerCommands();
{ {
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);
} }
{ {
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();
invoker.executeCommand(key);
if(key == view.getMiUndo())
{
invoker.undoCommand();
}
else
{
invoker.executeCommand(key);
}
} }
@Override @Override

+ 0
- 43
src/controller/OpenController.java View File

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

+ 16
- 0
src/model/AdressVerwaltungModel.java View File

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;
/** /**
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;
/** /**
*/ */
public AdressVerwaltungModel() public AdressVerwaltungModel()
{ {
initializePreferences();
adressEintraegeDaten = new ArrayList<>(); adressEintraegeDaten = new ArrayList<>();
adressEintraegeNamen = new ArrayList<>(); adressEintraegeNamen = new ArrayList<>();
daten = new ArrayList<>(); daten = new ArrayList<>();
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<>();

+ 10
- 0
src/view/MainWindow.java View File

return jpopEintragLoeschen; return jpopEintragLoeschen;
} }


/** /**
* Creates new form MainFrame * Creates new form MainFrame
*/ */
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…
Cancel
Save