From 41ba75bd7caa78831b1a73ee92773c2d45b5fae7 Mon Sep 17 00:00:00 2001 From: Sebastian Schneider Date: Mon, 9 Nov 2020 17:17:30 +0100 Subject: [PATCH] Initial Commit --- build.xml | 73 + manifest.mf | 3 + nbproject/build-impl.xml | 1770 +++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/project.properties | 95 + nbproject/project.xml | 15 + src/adressverwaltung/main.java | 40 + src/command/CommandInterface.java | 17 + src/command/CommandInvoker.java | 50 + .../commands/CommandEintragHinzufuegen.java | 44 + .../commands/CommandEintragLoeschen.java | 50 + src/controller/CommandController.java | 108 + src/controller/OpenController.java | 43 + src/model/AdressVerwaltungModel.java | 156 ++ src/view/MainWindow.form | 224 +++ src/view/MainWindow.java | 290 +++ src/view/icons/Open16.gif | Bin 0 -> 228 bytes src/view/icons/Save16.gif | Bin 0 -> 206 bytes src/view/icons/Undo24.gif | Bin 0 -> 239 bytes 19 files changed, 2986 insertions(+) create mode 100644 build.xml create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/adressverwaltung/main.java create mode 100644 src/command/CommandInterface.java create mode 100644 src/command/CommandInvoker.java create mode 100644 src/command/commands/CommandEintragHinzufuegen.java create mode 100644 src/command/commands/CommandEintragLoeschen.java create mode 100644 src/controller/CommandController.java create mode 100644 src/controller/OpenController.java create mode 100644 src/model/AdressVerwaltungModel.java create mode 100644 src/view/MainWindow.form create mode 100644 src/view/MainWindow.java create mode 100644 src/view/icons/Open16.gif create mode 100644 src/view/icons/Save16.gif create mode 100644 src/view/icons/Undo24.gif diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..9f484db --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Adressverwaltung. + + + diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..3375924 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1770 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..8d20fb2 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=d49cad62 +build.xml.script.CRC32=bbedcb41 +build.xml.stylesheet.CRC32=f85dc8f2@1.96.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=d49cad62 +nbproject/build-impl.xml.script.CRC32=d791273f +nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.96.0.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..6739be2 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,95 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Adressverwaltung.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/Adressverwaltung +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=Adressverwaltung +main.class=adressverwaltung.main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..5ba1ee0 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Adressverwaltung + + + + + + + + + diff --git a/src/adressverwaltung/main.java b/src/adressverwaltung/main.java new file mode 100644 index 0000000..96ef251 --- /dev/null +++ b/src/adressverwaltung/main.java @@ -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(); + } + +} diff --git a/src/command/CommandInterface.java b/src/command/CommandInterface.java new file mode 100644 index 0000000..a4b8c00 --- /dev/null +++ b/src/command/CommandInterface.java @@ -0,0 +1,17 @@ +/* + * 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; + +/** + * + * @author PC + */ +public interface CommandInterface { + public void execute(); + public void undo(); + //public void redo(); + public boolean isUndoable(); +} diff --git a/src/command/CommandInvoker.java b/src/command/CommandInvoker.java new file mode 100644 index 0000000..2fca43d --- /dev/null +++ b/src/command/CommandInvoker.java @@ -0,0 +1,50 @@ +/* + * 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; + +import command.CommandInterface; +import java.util.HashMap; +import java.util.Stack; + + +/** + * + * @author PC + */ +public class CommandInvoker { + private HashMap commands; + private Stack undoStack; + + public CommandInvoker() + { + commands = new HashMap<>(); + undoStack = new Stack<>(); + } + + public void addCommand(Object key, CommandInterface value) + { + commands.put(key, value); + } + + public void executeCommand(Object key) + { + CommandInterface cmd = commands.get(key); + cmd.execute(); + if(cmd.isUndoable()) + { + undoStack.push(cmd); + } + } + + public void undoCommand() + { + if(!undoStack.empty()) + { + undoStack.pop().undo(); + } + } + +} diff --git a/src/command/commands/CommandEintragHinzufuegen.java b/src/command/commands/CommandEintragHinzufuegen.java new file mode 100644 index 0000000..d150256 --- /dev/null +++ b/src/command/commands/CommandEintragHinzufuegen.java @@ -0,0 +1,44 @@ +/* + * 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 model.AdressVerwaltungModel; +import view.MainWindow; + +/** + * + * @author PC + */ +public class CommandEintragHinzufuegen implements CommandInterface{ + + private MainWindow view; + private AdressVerwaltungModel model; + + + public CommandEintragHinzufuegen(MainWindow view, AdressVerwaltungModel model) + { + this.view = view; + this.model = model; + + } + + @Override + public void execute() { + this.model.eintragHinzufuegen(); + } + + @Override + public void undo() { + + } + + @Override + public boolean isUndoable() { + return true; + } + +} diff --git a/src/command/commands/CommandEintragLoeschen.java b/src/command/commands/CommandEintragLoeschen.java new file mode 100644 index 0000000..9150807 --- /dev/null +++ b/src/command/commands/CommandEintragLoeschen.java @@ -0,0 +1,50 @@ +/* + * 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.util.ArrayList; +import model.AdressVerwaltungModel; +import view.MainWindow; + +/** + * + * @author PC + */ +public class CommandEintragLoeschen implements CommandInterface{ + + private MainWindow view; + private AdressVerwaltungModel model; + private ArrayList cache; + + public CommandEintragLoeschen(MainWindow view, AdressVerwaltungModel model) { + + this.view = view; + this.model = model; + this.cache = new ArrayList<>(); + + + + } + + @Override + public void execute() { + this.cache = this.model.getLastRowData(); + this.model.eintragLoeschen(this.model.getRowCount()-1); + } + + @Override + public void undo() { + this.model.eintragHinzufuegen(this.cache); + } + + @Override + public boolean isUndoable() { + return true; + } + + +} diff --git a/src/controller/CommandController.java b/src/controller/CommandController.java new file mode 100644 index 0000000..d5adb09 --- /dev/null +++ b/src/controller/CommandController.java @@ -0,0 +1,108 @@ +/* + * 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 command.CommandInterface; +import command.CommandInvoker; +import command.commands.CommandEintragHinzufuegen; +import command.commands.CommandEintragLoeschen; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.util.prefs.Preferences; +import model.AdressVerwaltungModel; +import view.MainWindow; + +/** + * + * @author PC + */ + + + +public class CommandController implements ActionListener, WindowListener{ + + private MainWindow view; + private AdressVerwaltungModel model; + private CommandInvoker invoker; + 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 + + registerEvents(); + registerCommands(); + + } + + + public void registerEvents() + { + view.getJpopEintragHinzufuegen().addActionListener(this); + view.getJpopEintragLoeschen().addActionListener(this); + } + + + public void registerCommands() + { + CommandEintragHinzufuegen cmdHinzufuegen = new CommandEintragHinzufuegen(view, model); + CommandEintragLoeschen cmdLoeschen = new CommandEintragLoeschen(view, model); + + invoker.addCommand(view.getJpopEintragHinzufuegen(), cmdHinzufuegen); + invoker.addCommand(view.getJpopEintragLoeschen(), cmdLoeschen); + } + + + + @Override + public void actionPerformed(ActionEvent evt) { + Object key = evt.getSource(); + invoker.executeCommand(key); + } + + @Override + public void windowOpened(WindowEvent we) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void windowClosing(WindowEvent we) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void windowClosed(WindowEvent we) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void windowIconified(WindowEvent we) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void windowDeiconified(WindowEvent we) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void windowActivated(WindowEvent we) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void windowDeactivated(WindowEvent we) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/src/controller/OpenController.java b/src/controller/OpenController.java new file mode 100644 index 0000000..8f28c15 --- /dev/null +++ b/src/controller/OpenController.java @@ -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()); + + } + + } +} diff --git a/src/model/AdressVerwaltungModel.java b/src/model/AdressVerwaltungModel.java new file mode 100644 index 0000000..51bb5a0 --- /dev/null +++ b/src/model/AdressVerwaltungModel.java @@ -0,0 +1,156 @@ +/* + * 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 model; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import javax.swing.table.AbstractTableModel; + +/** + * + * @author PC + */ +/** + * + * @author le + */ +public class AdressVerwaltungModel extends AbstractTableModel +{ + private ArrayList> daten; + private ArrayList adressEintraegeDaten; + private ArrayList adressEintraegeNamen; + + + /** + *Konstruktor für AdressverwaltungModel + */ + public AdressVerwaltungModel() + { + adressEintraegeDaten = new ArrayList<>(); + adressEintraegeNamen = new ArrayList<>(); + daten = new ArrayList<>(); + + adressEintraegeNamen.add("Vorname"); + adressEintraegeNamen.add("Name"); + adressEintraegeNamen.add("Adresse"); + adressEintraegeNamen.add("E-Mail"); + adressEintraegeDaten.add(""); + adressEintraegeDaten.add(""); + adressEintraegeDaten.add(""); + adressEintraegeDaten.add(""); + + + +// adressEintraegeNamen.add("Telefon"); +// adressEintraegeDaten.add("122345"); + daten.add(adressEintraegeDaten); + } + + @Override + public int getRowCount() + { + return daten.size(); + } + + @Override + public int getColumnCount() + { + return adressEintraegeDaten.size(); + } + + @Override + public Object getValueAt(int row, int col) + { + return daten.get(row).get(col); + } + @Override + public void setValueAt(Object value, int row, int col) + { + daten.get(row).set(col, (String)value); + } + + @Override + public boolean isCellEditable(int row, int col) + { + return true; + } + + @Override + public String getColumnName(int col) + { + return adressEintraegeNamen.get(col); + } + + public ArrayList getLastRowData() + { + ArrayList lastRow = new ArrayList<>(); + + for (int i = 0; i <= daten.get(0).size()-1; i++) + { + lastRow.add(daten.get(daten.size()-1).get(i)); + } + + return lastRow; + } + + + public void eintragHinzufuegen(ArrayList letzteSpalte) + { + daten.add(letzteSpalte); + this.fireTableDataChanged(); + } + + public void eintragHinzufuegen() + { + adressEintraegeDaten = new ArrayList<>(); + adressEintraegeNamen.forEach(s -> adressEintraegeDaten.add("")); + daten.add(adressEintraegeDaten); + this.fireTableDataChanged(); + } + + public void eintragLoeschen(int row) + { + daten.remove(row); + this.fireTableDataChanged(); + } + + public void spalteHinzufuegen(String name) + { + adressEintraegeNamen.add(name); + } + + public void datenSpeichern(File datei) throws FileNotFoundException, IOException + { + FileOutputStream fos = new FileOutputStream(datei); + BufferedOutputStream bos = new BufferedOutputStream(fos); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(daten); + oos.writeObject(adressEintraegeNamen); + oos.flush(); + oos.close(); + } + + public void datenLesen(File datei) throws FileNotFoundException, IOException, ClassNotFoundException + { + FileInputStream fis = new FileInputStream(datei); + BufferedInputStream bis = new BufferedInputStream(fis); + ObjectInputStream ois = new ObjectInputStream(bis); + daten = (ArrayList>)ois.readObject(); + adressEintraegeNamen = (ArrayList)ois.readObject(); + adressEintraegeDaten = daten.get(daten.size()-1); + ois.close(); + this.fireTableDataChanged(); + } + +} \ No newline at end of file diff --git a/src/view/MainWindow.form b/src/view/MainWindow.form new file mode 100644 index 0000000..c94e3ba --- /dev/null +++ b/src/view/MainWindow.form @@ -0,0 +1,224 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + </TableColumnModel> + </Property> + <Property name="componentPopupMenu" type="javax.swing.JPopupMenu" editor="org.netbeans.modules.form.ComponentChooserEditor"> + <ComponentRef name="jpopMenu"/> + </Property> + <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> + <TableHeader reorderingAllowed="true" resizingAllowed="true"/> + </Property> + </Properties> + </Component> + </SubComponents> + </Container> + </SubComponents> + </Container> + </SubComponents> +</Form> diff --git a/src/view/MainWindow.java b/src/view/MainWindow.java new file mode 100644 index 0000000..8a096a3 --- /dev/null +++ b/src/view/MainWindow.java @@ -0,0 +1,290 @@ +/* + * 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 view; + +/** + * + * @author PC + */ +public class MainWindow extends javax.swing.JFrame { + + /** + * @return the jpopEintragHinzufuegen + */ + public javax.swing.JMenuItem getJpopEintragHinzufuegen() { + return jpopEintragHinzufuegen; + } + + /** + * @return the jpopEintragLoeschen + */ + public javax.swing.JMenuItem getJpopEintragLoeschen() { + return jpopEintragLoeschen; + } + + /** + * Creates new form MainFrame + */ + public MainWindow() { + initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + jpopMenu = new javax.swing.JPopupMenu(); + jpopEintragHinzufuegen = new javax.swing.JMenuItem(); + jpopEintragLoeschen = new javax.swing.JMenuItem(); + jFileChooser = new javax.swing.JFileChooser(); + jpmainpanel = new javax.swing.JPanel(); + jtbmaintoolbar = new javax.swing.JToolBar(); + jbOpen = new javax.swing.JButton(); + jbSave = new javax.swing.JButton(); + statusbar = new javax.swing.JLabel(); + jSPAdressPane = new javax.swing.JScrollPane(); + jTableAdressen = new javax.swing.JTable(); + jMainMenu = new javax.swing.JMenuBar(); + jmFile = new javax.swing.JMenu(); + FileOpen = new javax.swing.JMenuItem(); + FileSave = new javax.swing.JMenuItem(); + jMenu2 = new javax.swing.JMenu(); + miUndo = new javax.swing.JMenuItem(); + + jpopEintragHinzufuegen.setText("Eintrag hinzufügen"); + jpopMenu.add(jpopEintragHinzufuegen); + + jpopEintragLoeschen.setText("Eintrag löschen"); + jpopEintragLoeschen.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jpopEintragLoeschenActionPerformed(evt); + } + }); + jpopMenu.add(jpopEintragLoeschen); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jpmainpanel.setLayout(new java.awt.BorderLayout()); + + jtbmaintoolbar.setRollover(true); + + jbOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/icons/Open16.gif"))); // NOI18N + jbOpen.setToolTipText("Open a file"); + jbOpen.setFocusable(false); + jbOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + jbOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + jbOpen.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jbOpenActionPerformed(evt); + } + }); + jtbmaintoolbar.add(jbOpen); + + jbSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/icons/Save16.gif"))); // NOI18N + jbSave.setToolTipText("Save a file"); + jbSave.setFocusable(false); + jbSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + jbSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + jtbmaintoolbar.add(jbSave); + + jpmainpanel.add(jtbmaintoolbar, java.awt.BorderLayout.PAGE_START); + + statusbar.setText(" "); + jpmainpanel.add(statusbar, java.awt.BorderLayout.PAGE_END); + + jTableAdressen.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null}, + {null, null, null}, + {null, null, null}, + {null, null, null} + }, + new String [] { + "Telefonnummer", "Adresse", "Name" + } + )); + jTableAdressen.setComponentPopupMenu(jpopMenu); + jSPAdressPane.setViewportView(jTableAdressen); + + jpmainpanel.add(jSPAdressPane, java.awt.BorderLayout.CENTER); + + jmFile.setMnemonic('f'); + jmFile.setText("File"); + jmFile.setToolTipText("General File Menu"); + + FileOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_DOWN_MASK)); + FileOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/icons/Open16.gif"))); // NOI18N + FileOpen.setMnemonic('o'); + FileOpen.setText("Open"); + FileOpen.setToolTipText("Open a selected File"); + jmFile.add(FileOpen); + + FileSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_DOWN_MASK)); + FileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/icons/Save16.gif"))); // NOI18N + FileSave.setText("Save"); + FileSave.setToolTipText("Save a file"); + jmFile.add(FileSave); + + jMainMenu.add(jmFile); + + jMenu2.setText("Edit"); + + miUndo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_DOWN_MASK)); + miUndo.setText("Undo"); + miUndo.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + miUndoActionPerformed(evt); + } + }); + jMenu2.add(miUndo); + + jMainMenu.add(jMenu2); + + setJMenuBar(jMainMenu); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jpmainpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jpmainpanel, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE) + ); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + private void jpopEintragLoeschenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jpopEintragLoeschenActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jpopEintragLoeschenActionPerformed + + private void jbOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbOpenActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jbOpenActionPerformed + + private void miUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miUndoActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_miUndoActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + //</editor-fold> + //</editor-fold> + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new MainWindow().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JMenuItem FileOpen; + private javax.swing.JMenuItem FileSave; + private javax.swing.JFileChooser jFileChooser; + private javax.swing.JMenuBar jMainMenu; + private javax.swing.JMenu jMenu2; + private javax.swing.JScrollPane jSPAdressPane; + private javax.swing.JTable jTableAdressen; + private javax.swing.JButton jbOpen; + private javax.swing.JButton jbSave; + private javax.swing.JMenu jmFile; + private javax.swing.JPanel jpmainpanel; + private javax.swing.JMenuItem jpopEintragHinzufuegen; + private javax.swing.JMenuItem jpopEintragLoeschen; + private javax.swing.JPopupMenu jpopMenu; + private javax.swing.JToolBar jtbmaintoolbar; + private javax.swing.JMenuItem miUndo; + private javax.swing.JLabel statusbar; + // End of variables declaration//GEN-END:variables + + /** + * @return the FileOpen + */ + public javax.swing.JMenuItem getFileOpen() { + return FileOpen; + } + + /** + * @return the FileSave + */ + public javax.swing.JMenuItem getFileSave() { + return FileSave; + } + + /** + * @return the jbOpen + */ + public javax.swing.JButton getJbOpen() { + return jbOpen; + } + + /** + * @return the jbSave + */ + public javax.swing.JButton getJbSave() { + return jbSave; + } + + /** + * @return the jFileChooser1 + */ + public javax.swing.JFileChooser getjFileChooser() { + return jFileChooser; + } + + /** + * @return the statusbar + */ + public javax.swing.JLabel getStatusbar() { + return statusbar; + } + + /** + * @return the jTableAdressen + */ + public javax.swing.JTable getjTableAdressen() { + return jTableAdressen; + } + + /** + * @param jTableAdressen the jTableAdressen to set + */ + public void setjTableAdressen(javax.swing.JTable jTableAdressen) { + this.jTableAdressen = jTableAdressen; + } +} diff --git a/src/view/icons/Open16.gif b/src/view/icons/Open16.gif new file mode 100644 index 0000000000000000000000000000000000000000..fabd5676f96cf46b62fe3c91fce204c2339b64ea GIT binary patch literal 228 zcmZ?wbhEHb6krfw*!-X2KM*`S^X2Zb&v%ZV*}Lw{mRV;u&ssCHZS@QwYMt3ton~yz zz`$_ezyTl$1d2ad7#SFN8FWA#kQojvb{kH5u1-<NKFhW3ic*(o^1K)9>qNFOwm)DL zUM5f|DAMG)`M?5!8MjshY0h2MsCcKyI-XnYHYZ=p(kDk{gOnH)|M@%T7gQEyre~BW z7#SECC?r)X1efM1_+};-<rh~Lm!#$v>nM2UCF?0T=Hw^@ffN=i1f>?I7L}!@=<#xS W`M4>#2PuT57AY9&8Srv3SOWl92UWNL literal 0 HcmV?d00001 diff --git a/src/view/icons/Save16.gif b/src/view/icons/Save16.gif new file mode 100644 index 0000000000000000000000000000000000000000..954f1accde64db9e98e9a6e528b459f3027b018c GIT binary patch literal 206 zcmZ?wbhEHb6krfwSoELa|NsAI&YVe0OJiVQIB?(qkc0rmpDc_F3@i*fATCHP1G9t2 zt~>woPk7#DV0y9hrl_L@i#VrFyvHoHu9Y#Xr$ntic|`q<O~p>h+po<JGlVogTsgy0 ztMQO}ms70KBGZnri3|*i|NNcv3o45;(=$pGj0_A66p|_xf=lxhd^3}a@{22rOHy-- xbrd}FlJyiEb8-}dKnjZ$f>Mi9i^@_{^mw_veB2b=gA~G2ixdp?40yR1tO0)kMS%bS literal 0 HcmV?d00001 diff --git a/src/view/icons/Undo24.gif b/src/view/icons/Undo24.gif new file mode 100644 index 0000000000000000000000000000000000000000..1d545a77b2adfa6b5496a0523bb3804e818d12db GIT binary patch literal 239 zcmZ?wbhEHblwgoxSoELa|NsAI&itP_^Ng`^8Uq8vfddDCBoHY6WMO1rU}ew&aX@Mr zm=hy*-T7y5%4yZywQXm$m(5n_lQtAQxMC8Eg5YA-)o-=8IM{W6eQmV+_WR8@zIJel z<adN{88-X8`YFXTH-zKVtT}1&ry7s`p4w&cWHIyZsCl<+N>kLfJ(<O%XSDdf@vpi% zP6ow){?7RYl|`B986^rv1_lNSNtFu0rFjaznaM@@#g)Y+sky~E3Z8k%dJ2v?ISN4_ kg~bX%sl};9WvMB8yj)&BZVK)}3Sp^53Wj<Hyj%>{0HiEhLjV8( literal 0 HcmV?d00001