diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/.idea/misc.xml b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/misc.xml
new file mode 100644
index 0000000..44ae3bd
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/.idea/modules.xml b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/modules.xml
new file mode 100644
index 0000000..5314676
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/.idea/uiDesigner.xml b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/.idea/vcs.xml b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/.idea/workspace.xml b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/workspace.xml
new file mode 100644
index 0000000..a6de223
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/.idea/workspace.xml
@@ -0,0 +1,472 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ JList
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1562236408943
+
+
+ 1562236408943
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/de.hhn.ai.prog2.blatt3.pizzashop.iml b/de.hhn.ai.prog2.blatt3.pizzashop/de.hhn.ai.prog2.blatt3.pizzashop.iml
new file mode 100644
index 0000000..ea1542a
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/de.hhn.ai.prog2.blatt3.pizzashop.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/kunden.txt b/de.hhn.ai.prog2.blatt3.pizzashop/kunden.txt
new file mode 100644
index 0000000..f77a78c
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/kunden.txt
@@ -0,0 +1,3 @@
+1#Mustermann#Max
+2#Doe#John
+3#Musterfrau#Frau
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/pizza.txt b/de.hhn.ai.prog2.blatt3.pizzashop/pizza.txt
deleted file mode 100644
index 6c4446c..0000000
--- a/de.hhn.ai.prog2.blatt3.pizzashop/pizza.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-Test#LARGE#CHEESE#TOMATO#HAM#
-Hello World#FAMILY#CHEESE#TOMATO#HAM#MUSHROOM#
-Test#SMALL#HAM#
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/pizzas.txt b/de.hhn.ai.prog2.blatt3.pizzashop/pizzas.txt
new file mode 100644
index 0000000..0f66376
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/pizzas.txt
@@ -0,0 +1,4 @@
+Only Cheese#SMALL#CHEESE#
+Margaritha#LARGE#CHEESE#TOMATO#
+Multi Fruit#FAMILY#CHEESE#TOMATO#MUSHROOM#
+Neue Pizza#MEDIUM#CHEESE#TOMATO#HAM#MUSHROOM#
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java
deleted file mode 100644
index e6acfbf..0000000
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package app;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class KundenService {
- private List kunden = new ArrayList();
-
- public void create(Kunde kunde) {
- kunden.add(kunde);
- }
-
- // public void update(); // TODO:
-
- public void delete(Kunde kunde) {
- kunden.remove(kunde);
- }
-
- public Kunde read(int id) {
- for (Kunde kunde : kunden) {
- if (kunde.getId() == id)
- return kunde;
- }
- return null;
- }
-
- public Kunde read(String name, String lastName) {
- for (Kunde kunde : kunden) {
- if (kunde.getName() == name && kunde.getLastName() == lastName)
- return kunde;
- }
- return null;
- }
-}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java
deleted file mode 100644
index a80be79..0000000
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java
+++ /dev/null
@@ -1,169 +0,0 @@
-package app;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.GridLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.List;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import javax.swing.ListSelectionModel;
-import javax.swing.WindowConstants;
-
-import app.io.PizzaIOHandler;
-
-public class MyPizzaShop extends JFrame {
- private static final long serialVersionUID = -5421020006317002203L;
-
- private Container container;
-
- public MyPizzaShop() {
- super("My Pizza Shop");
- this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- this.setSize(800, 600);
- this.setJMenuBar(new MenuBar());
- container = this.getContentPane();
- container.setLayout(new BorderLayout());
- StatusPanel panel = new StatusPanel();
- container.add(panel, BorderLayout.SOUTH);
- showCenterPanel(new CenterPanel());
- }
-
- public void showCenterPanel(JPanel panel) {
- container.add(panel, BorderLayout.CENTER);
- }
-
- private class StatusPanel extends JPanel {
- private static final long serialVersionUID = -5777179157927719004L;
-
- private StatusPanel() {
- this.setBorder(BorderFactory.createLineBorder(Color.black));
- JLabel label = new JLabel("Wilkommen");
- this.add(label);
- }
- }
-
- private class MenuBar extends JMenuBar {
- private static final long serialVersionUID = 7457449847994117214L;
-
- private MenuBar() {
- JMenu menu = new JMenu("Datei");
- JMenuItem quit = new JMenuItem("Beenden");
- quit.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- JPanel panel = new JPanel();
- panel.add(new JLabel("Hallo, das ist ein Begrüßungstext"));
- menu.add(panel);
- menu.add(quit);
- this.add(menu);
-
- JMenu configurator = new JMenu("Konfigurator");
- JMenuItem listPizzas = new JMenuItem("Zeige definierte Pizzen");
- JMenuItem createPizza = new JMenuItem("Konfiguriere Pizza");
- createPizza.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- container.setVisible(!container.isVisible());
- }
- });
- configurator.add(listPizzas);
- configurator.add(createPizza);
- this.add(configurator);
-
- JMenu management = new JMenu("Verwaltung");
- JMenuItem listStaff = new JMenuItem("Liste der Mitarbeiter");
- management.add(listStaff);
- this.add(management);
-
- JMenu customer = new JMenu("Kunden");
- JMenuItem listCustomer = new JMenuItem("Liste der Kunden");
- JMenuItem manageCustomer = new JMenuItem("Kunde bearbeiten");
- customer.add(listCustomer);
- customer.add(manageCustomer);
- this.add(customer);
-
- JMenu order = new JMenu("Bestellung");
- JMenuItem listOders = new JMenuItem("Liste der Bestellungen");
- order.add(listOders);
- this.add(order);
- }
- }
-
- private class CenterPanel extends JPanel {
- private static final long serialVersionUID = 3527260169526726295L;
- private JLabel priceLabel = new JLabel();
- private int price = 200;
-
- private CenterPanel() {
- this.setLayout(new GridLayout(5, 2));
- this.add(wrap(new JLabel("Name:")));
- JTextField name = new JTextField(20);
- this.add(wrap(name));
- this.add(wrap(new JLabel("Größe:")));
- String[] availPizzaSizes = new String[EnumSet.allOf(PizzaSize.class).size()];
- int i = 0;
- for (PizzaSize size : EnumSet.allOf(PizzaSize.class)) {
- availPizzaSizes[i++] = size.getName();
- }
- JList pizzaSize = new JList(availPizzaSizes);
- this.add(wrap(pizzaSize));
- this.add(wrap(new JLabel("Belag:")));
- String[] availToppings = new String[EnumSet.allOf(Topping.class).size()];
- i = 0;
- for (Topping topping : EnumSet.allOf(Topping.class)) {
- availToppings[i++] = topping.getName();
- }
- JList toppings = new JList(availToppings);
- toppings.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- this.add(wrap(toppings));
- this.add(wrap(new JPanel()));
- this.add(wrap(priceLabel));
- JButton sendBtn = new JButton("Abschicken");
- sendBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- List pizzas = PizzaIOHandler.read(null);
- List toppingList = new ArrayList();
- for (int t : toppings.getSelectedIndices()) {
- toppingList.add(Topping.values()[t]);
- }
- pizzas.add(
- new Pizza(name.getText(), PizzaSize.values()[pizzaSize.getSelectedIndex()], toppingList));
- PizzaIOHandler.write(pizzas, null);
- }
- });
- this.add(wrap(sendBtn));
- this.add(wrap(new JButton("Ausdrucken")));
- setPrice(price);
- }
-
- public void setPrice(int price) {
- this.price = price;
- priceLabel.setText("Preis: " + price + " Cent");
- }
-
- private JPanel wrap(Component comp) {
- JPanel panel = new JPanel();
- panel.add(comp);
- return panel;
- }
- }
-}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Adresse.java
similarity index 91%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/model/Adresse.java
index fc4e9fb..37aeac0 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Adresse.java
@@ -1,4 +1,4 @@
-package app;
+package model;
public class Adresse {
private int id;
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KontaktDaten.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/KontaktDaten.java
similarity index 88%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/KontaktDaten.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/model/KontaktDaten.java
index dec829d..19d61e3 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/KontaktDaten.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/KontaktDaten.java
@@ -1,4 +1,4 @@
-package app;
+package model;
public class KontaktDaten {
private int id;
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Kunde.java
similarity index 56%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/model/Kunde.java
index 6051d61..802bb15 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Kunde.java
@@ -1,4 +1,7 @@
-package app;
+package model;
+
+import model.Adresse;
+import model.KontaktDaten;
public class Kunde {
private int id;
@@ -9,6 +12,12 @@ public class Kunde {
private Adresse address;
private Adresse shippingAddress;
+ public Kunde(int id, String lastName, String name) {
+ this.id = id;
+ this.lastName = lastName;
+ this.name = name;
+ }
+
public int getId() {
return id;
}
@@ -27,4 +36,12 @@ public class Kunde {
return lastName;
}
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Order.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Order.java
similarity index 98%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/Order.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/model/Order.java
index cef9f04..4b5b11c 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Order.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Order.java
@@ -1,4 +1,4 @@
-package app;
+package model;
import java.util.ArrayList;
import java.util.List;
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Pizza.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Pizza.java
similarity index 85%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/Pizza.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/model/Pizza.java
index 2c7df41..179710c 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Pizza.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Pizza.java
@@ -1,4 +1,4 @@
-package app;
+package model;
import java.util.ArrayList;
import java.util.List;
@@ -22,10 +22,18 @@ public class Pizza {
return this.size;
}
+ public void setSize(PizzaSize size) {
+ this.size = size;
+ }
+
public List getToppings() {
return this.toppings;
}
+ public void setToppings(List toppings) {
+ this.toppings = toppings;
+ }
+
public int getPrice() {
int price = size.getPrice();
for (int i = 0; i < toppings.size(); i++) {
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/PizzaSize.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/PizzaSize.java
similarity index 96%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/PizzaSize.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/model/PizzaSize.java
index 2b6fa9c..1bfdb51 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/PizzaSize.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/PizzaSize.java
@@ -1,4 +1,4 @@
-package app;
+package model;
public enum PizzaSize {
SMALL(400, "klein"), MEDIUM(500, "mittel"), LARGE(600, "groß"), FAMILY(1000, "extra groß");
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Topping.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Topping.java
similarity index 96%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/Topping.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/model/Topping.java
index 397e1e3..0f06b81 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/Topping.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/model/Topping.java
@@ -1,4 +1,4 @@
-package app;
+package model;
public enum Topping {
CHEESE(50, "Käse"), TOMATO(25, "Tomate"), HAM(80, "Schinken"), MUSHROOM(40, "Champignon");
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/App.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/App.java
similarity index 57%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/App.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/services/App.java
index c1ff1eb..35efb65 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/App.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/App.java
@@ -1,7 +1,9 @@
-package app;
+package services;
+
+import view.MyPizzaShop;
public class App {
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) {
MyPizzaShop myPizzaShop = new MyPizzaShop();
myPizzaShop.setVisible(true);
}
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/services/KundenService.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/KundenService.java
new file mode 100644
index 0000000..1b245ad
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/KundenService.java
@@ -0,0 +1,82 @@
+package services;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import model.Kunde;
+import services.io.KundenIOHandler;
+
+public class KundenService {
+ private List kunden = new ArrayList();
+
+ public KundenService() {
+ this.kunden = getAll(null);
+ }
+
+ public void create(Kunde kunde) {
+ kunden.add(kunde);
+ }
+
+ public void update(int id, String name, String lastName) {
+ Kunde kunde = new Kunde(-1, "", "");
+ for (Kunde k : kunden)
+ if (k.getId() == id)
+ kunde = k;
+ kunde.setName(name);
+ kunde.setLastName(lastName);
+ }
+
+ public void delete(int id) {
+ Kunde kunde = new Kunde(-1, "", "");
+ for (Kunde k : kunden)
+ if (k.getId() == id)
+ kunde = k;
+ kunden.remove(kunde);
+ }
+
+ public Kunde read(int id) {
+ for (Kunde kunde : kunden) {
+ if (kunde.getId() == id)
+ return kunde;
+ }
+ return null;
+ }
+
+ public int getUnusedId() {
+ int id = 0;
+ for (Kunde k : kunden)
+ if (k.getId() >= id)
+ id = k.getId() + 1;
+ return id;
+ }
+
+ public Kunde read(String name, String lastName) {
+ for (Kunde kunde : kunden) {
+ if (kunde.getName() == name && kunde.getLastName() == lastName)
+ return kunde;
+ }
+ return null;
+ }
+
+ public Object[][] getTableData() {
+ Object[][] data = new Object[kunden.size()][];
+ int id = 0;
+ for (Kunde kunde : kunden) {
+ data[id] = new Object[] { kunde.getId(), kunde.getName(), kunde.getLastName(), "Location" };
+ id += 1;
+ }
+ return data;
+ }
+
+ public List getAll(String fileName) {
+ return KundenIOHandler.read(fileName);
+ }
+
+ public void saveAll(List kunden, String fileName) {
+ KundenIOHandler.write(kunden, fileName);
+ }
+
+ public void saveAllFromInternData() {
+ saveAll(kunden, null);
+ }
+}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/services/PizzaService.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/PizzaService.java
new file mode 100644
index 0000000..473d6cc
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/PizzaService.java
@@ -0,0 +1,71 @@
+package services;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import model.Pizza;
+import model.PizzaSize;
+import model.Topping;
+import services.io.PizzaIOHandler;
+
+public class PizzaService {
+ private List pizzas = new ArrayList();
+
+ public PizzaService() {
+ this.pizzas = getAll(null);
+ }
+
+ public void create(Pizza pizza) {
+ pizzas.add(pizza);
+ }
+
+ public void update(String name, PizzaSize pizzaSize, ArrayList toppings) {
+ Pizza pizza = new Pizza("", PizzaSize.SMALL, new ArrayList());
+ for (Pizza p : pizzas)
+ if (p.getName() == name)
+ pizza = p;
+ pizza.setSize(pizzaSize);
+ pizza.setToppings(toppings);
+ }
+
+ public void delete(String name) {
+ Pizza pizza = new Pizza("", PizzaSize.SMALL, new ArrayList());
+ for (Pizza p : pizzas)
+ if (p.getName() == name)
+ pizza = p;
+ pizzas.remove(pizza);
+ }
+
+ public Pizza read(String name) {
+ for (Pizza pizza : pizzas) {
+ if (pizza.getName() == name)
+ return pizza;
+ }
+ return null;
+ }
+
+ public Object[][] getTableData() {
+ Object[][] data = new Object[pizzas.size()][];
+ int id = 0;
+ for (Pizza pizza : pizzas) {
+ data[id] = new Object[] { pizza.getName(), pizza.getPrice(), pizza.getSize(),
+ Arrays.toString(pizza.getToppings().toArray()) };
+ id += 1;
+ }
+ return data;
+ }
+
+ public List getAll(String fileName) {
+ return PizzaIOHandler.read(fileName);
+ }
+
+ public void saveAll(List pizzas, String fileName) {
+ PizzaIOHandler.write(pizzas, fileName);
+ }
+
+ public void saveAllFromInternData() {
+ saveAll(pizzas, null);
+ }
+
+}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/services/io/KundenIOHandler.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/io/KundenIOHandler.java
new file mode 100644
index 0000000..fe71d66
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/io/KundenIOHandler.java
@@ -0,0 +1,47 @@
+package services.io;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import model.Kunde;
+
+public class KundenIOHandler {
+ public static List read(String fileName) {
+ if (fileName == null)
+ fileName = "kunden.txt";
+ List kunden = new ArrayList();
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(fileName));
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ String[] val = line.split("#");
+ kunden.add(new Kunde(Integer.parseInt(val[0]), val[1], val[2]));
+ }
+ reader.close();
+ System.out.println(kunden);
+ return kunden;
+ } catch (IOException ex) {
+ System.out.println("###ERROR### (IOException)");
+ }
+ return null;
+ }
+
+ public static void write(List kunden, String fileName) {
+ if (fileName == null)
+ fileName = "kunden.txt";
+ try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) {
+ for (Kunde kunde : kunden) {
+ String line = Integer.toString(kunde.getId());
+ line += "#" + kunde.getLastName() + "#" + kunde.getName();
+ writer.println(line);
+ }
+ } catch (IOException ex) {
+ System.out.println("###ERROR### (IOException)");
+ }
+ }
+}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/io/PizzaIOHandler.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/io/PizzaIOHandler.java
similarity index 90%
rename from de.hhn.ai.prog2.blatt3.pizzashop/src/app/io/PizzaIOHandler.java
rename to de.hhn.ai.prog2.blatt3.pizzashop/src/services/io/PizzaIOHandler.java
index 3696348..5f94974 100644
--- a/de.hhn.ai.prog2.blatt3.pizzashop/src/app/io/PizzaIOHandler.java
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/services/io/PizzaIOHandler.java
@@ -1,4 +1,4 @@
-package app.io;
+package services.io;
import java.io.BufferedReader;
import java.io.FileReader;
@@ -6,17 +6,16 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import app.Pizza;
-import app.PizzaSize;
-import app.Topping;
+import model.Pizza;
+import model.PizzaSize;
+import model.Topping;
public class PizzaIOHandler {
public static List read(String fileName) {
if (fileName == null)
- fileName = "pizza.txt";
+ fileName = "pizzas.txt";
List pizzas = new ArrayList();
try {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
@@ -40,7 +39,7 @@ public class PizzaIOHandler {
public static void write(List pizzas, String fileName) {
if (fileName == null)
- fileName = "pizza.txt";
+ fileName = "pizzas.txt";
try (PrintWriter writer = new PrintWriter(new FileWriter(fileName))) {
for (Pizza pizza : pizzas) {
String line = pizza.getName();
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/view/MyPizzaShop.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/view/MyPizzaShop.java
new file mode 100644
index 0000000..8848b8f
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/view/MyPizzaShop.java
@@ -0,0 +1,530 @@
+package view;
+
+import java.awt.BorderLayout;
+import java.awt.CardLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
+import javax.swing.WindowConstants;
+import javax.swing.table.DefaultTableModel;
+
+import model.Kunde;
+import model.Pizza;
+import model.PizzaSize;
+import model.Topping;
+import services.KundenService;
+import services.PizzaService;
+import view.util.ButtonColumn;
+
+public class MyPizzaShop extends JFrame {
+ private static final long serialVersionUID = -5421020006317002203L;
+
+ final static String DEFAULT = "Default";
+ final static String TODO = "Todo";
+ final static String CONFIGURATOR = "Configurator";
+ final static String PIZZALIST = "PizzaList";
+ final static String CUSTOMERLIST = "CustomerList";
+ final static String CUSTOMERDETAILS = "CustomerDetails";
+
+ private Container container;
+ private JPanel cards;
+ PizzaListPanel pizzaListPanel;
+ CustomerDetailsPanel customerDetailsPanel;
+ CustomerListPanel customerListPanel;
+
+ private String path;
+
+ public MyPizzaShop() {
+ super("My Pizza Shop");
+ this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ this.setSize(800, 600);
+ KundenService kundenService = new KundenService();
+ PizzaService pizzaService = new PizzaService();
+ container = this.getContentPane();
+ container.setLayout(new BorderLayout());
+ StatusPanel statusPanel = new StatusPanel();
+ container.add(statusPanel, BorderLayout.SOUTH);
+ JPanel defaultPanel = new DefaultPanel();
+ JPanel toDoPanel = new ToDoPanel();
+ JPanel configuratorPanel = new ConfiguratorPanel(pizzaService);
+ pizzaListPanel = new PizzaListPanel(pizzaService);
+ customerListPanel = new CustomerListPanel(kundenService);
+ customerDetailsPanel = new CustomerDetailsPanel(kundenService);
+
+ cards = new JPanel(new CardLayout());
+ cards.add(defaultPanel, DEFAULT);
+ cards.add(toDoPanel, TODO);
+ cards.add(configuratorPanel, CONFIGURATOR);
+ cards.add(pizzaListPanel, PIZZALIST);
+ cards.add(customerListPanel, CUSTOMERLIST);
+ cards.add(customerDetailsPanel, CUSTOMERDETAILS);
+
+ container.add(cards);
+
+ ((CardLayout) (cards.getLayout())).show(cards, DEFAULT);
+
+ this.setJMenuBar(new MenuBar(kundenService, pizzaService));
+ this.addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
+ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
+ if (JOptionPane.showConfirmDialog(null,
+ "Wollen Sie das Fenster wirklich schließen?\nAlle ungespeicherten Änderungen gehen verloren!",
+ "Fenster schließen?", JOptionPane.YES_NO_OPTION,
+ JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
+ System.exit(0);
+ }
+ }
+ });
+ }
+
+ private class StatusPanel extends JPanel {
+ private static final long serialVersionUID = -5777179157927719004L;
+
+ private StatusPanel() {
+ this.setBorder(BorderFactory.createLineBorder(Color.black));
+ JLabel label = new JLabel("Wilkommen");
+ this.add(label);
+ }
+ }
+
+ private class MenuBar extends JMenuBar {
+ private static final long serialVersionUID = 7457449847994117214L;
+ KundenService kundenService;
+ PizzaService pizzaService;
+
+ private MenuBar(KundenService kundenService, PizzaService pizzaService) {
+ this.kundenService = kundenService;
+ this.pizzaService = pizzaService;
+ JMenu menu = new JMenu("Datei");
+ JMenuItem open = new JMenuItem("Öffnen");
+ JMenuItem quit = new JMenuItem("Beenden");
+ open.addActionListener(e -> {
+ new OpenDialog();
+ });
+ quit.addActionListener(e -> System.exit(0));
+ JPanel panel = new JPanel();
+ panel.add(new JLabel("Hallo, das ist ein Begrüßungstext"));
+ menu.add(panel);
+ menu.add(open);
+ menu.add(quit);
+ this.add(menu);
+
+ JMenu configurator = new JMenu("Konfigurator");
+ JMenuItem listPizzas = new JMenuItem("Zeige definierte Pizzen");
+ CardLayout cl = (CardLayout) (cards.getLayout());
+ listPizzas.addActionListener(e -> cl.show(cards, TODO));
+ JMenuItem createPizza = new JMenuItem("Konfiguriere Pizza");
+ createPizza.addActionListener(e -> cl.show(cards, CONFIGURATOR));
+ JMenuItem savePizzaList = new JMenuItem("Liste Speichern");
+ savePizzaList.addActionListener(e -> this.pizzaService.saveAllFromInternData());
+ configurator.add(listPizzas);
+ configurator.add(createPizza);
+ configurator.add(savePizzaList);
+ this.add(configurator);
+
+ JMenu management = new JMenu("Verwaltung");
+ JMenuItem listStaff = new JMenuItem("Liste der Mitarbeiter");
+ listStaff.addActionListener(e -> cl.show(cards, TODO));
+ management.add(listStaff);
+ this.add(management);
+
+ JMenu customer = new JMenu("Kunden");
+ JMenuItem listCustomer = new JMenuItem("Liste der Kunden");
+ listCustomer.addActionListener(e -> {
+ customerListPanel.refresh();
+ cl.show(cards, CUSTOMERLIST);
+ });
+ JMenuItem manageCustomer = new JMenuItem("Kunde hinzufügen");
+ manageCustomer.addActionListener(e -> {
+ customerDetailsPanel.clear();
+ customerDetailsPanel.generateNewId();
+ cl.show(cards, CUSTOMERDETAILS);
+ });
+ JMenuItem saveCustomerList = new JMenuItem("Liste Speichern");
+ saveCustomerList.addActionListener(e -> {
+ this.kundenService.saveAllFromInternData();
+ });
+ customer.add(listCustomer);
+ customer.add(manageCustomer);
+ customer.add(saveCustomerList);
+ this.add(customer);
+
+ JMenu order = new JMenu("Bestellung");
+ JMenuItem listOders = new JMenuItem("Liste der Bestellungen");
+ listOders.addActionListener(e -> cl.show(cards, TODO));
+ order.add(listOders);
+ this.add(order);
+ }
+ }
+
+ private class OpenDialog extends JFileChooser {
+ private static final long serialVersionUID = 6958059890118659301L;
+
+ private OpenDialog() {
+ this.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ int returnVal = this.showOpenDialog(null);
+
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.getSelectedFile();
+ path = file.getAbsolutePath();
+ System.out.println("Path selected: " + file.getAbsolutePath());
+ } else {
+ System.out.println("Open command cancelled by user.");
+ }
+ }
+ }
+
+ private class DefaultPanel extends JPanel {
+
+ private static final long serialVersionUID = 7042604402647213661L;
+
+ private DefaultPanel() {
+ this.add(new JLabel("Herzlich Wilkommen bei 'MyPizzaShop'."));
+ this.add(new JLabel("Bitte wählen Sie eine Kategorie um fortzufahren."));
+ }
+ }
+
+ private class ToDoPanel extends JPanel {
+ private static final long serialVersionUID = 6822836519469016140L;
+
+ private ToDoPanel() {
+ this.add(new JLabel("To Do"));
+ }
+ }
+
+ private class CustomerListPanel extends JPanel {
+
+ private static final long serialVersionUID = 9065029635304808892L;
+ KundenService kundenService;
+ String[] columnNames = { "ID", "Name", "Vorname", "Ort", "", "", "" };
+ JTable table;
+
+ private CustomerListPanel(KundenService kundenService) {
+ this.kundenService = kundenService;
+ Object[][] data = this.kundenService.getTableData();
+
+ // Add Button Text to table data
+ for (int i = 0; i < data.length; i++) {
+ data[i] = new Object[] { data[i][0], data[i][1], data[i][2], data[i][3], "Anzeigen", "Ändern",
+ "Löschen" };
+ }
+ DefaultTableModel model = new DefaultTableModel(data, columnNames);
+ table = new JTable(model);
+
+ JScrollPane scrollPane = new JScrollPane(table);
+ table.setFillsViewportHeight(true);
+
+ this.setLayout(new BorderLayout());
+ JPanel bottomBar = new JPanel();
+ JButton addCustomerBtn = new JButton("Füge Kunde hinzu");
+ addCustomerBtn.addActionListener(e -> {
+ customerDetailsPanel.clear();
+ customerDetailsPanel.generateNewId();
+ ((CardLayout) (cards.getLayout())).show(cards, CUSTOMERDETAILS);
+ });
+ bottomBar.add(wrap(addCustomerBtn));
+ JButton printBtn = new JButton("Drucken");
+ printBtn.addActionListener(e -> {
+ System.out.println(Arrays.deepToString(kundenService.getTableData()));
+ });
+ bottomBar.add(wrap(printBtn));
+ this.add(table.getTableHeader(), BorderLayout.PAGE_START);
+ this.add(bottomBar, BorderLayout.AFTER_LAST_LINE);
+ this.add(scrollPane, BorderLayout.CENTER);
+ addTableButtons();
+ }
+
+ private void addTableButtons() {
+ AbstractAction show = new AbstractAction() {
+ private static final long serialVersionUID = 302149670181733310L;
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JTable table = (JTable) e.getSource();
+ int modelRow = Integer.valueOf(e.getActionCommand());
+ DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
+ customerDetailsPanel.preloadData(tableModel.getValueAt(modelRow, 0).toString(),
+ tableModel.getValueAt(modelRow, 1).toString(),
+ tableModel.getValueAt(modelRow, 2).toString());
+ customerDetailsPanel.setReadOnly(true);
+ ((CardLayout) (cards.getLayout())).show(cards, CUSTOMERDETAILS);
+ }
+ };
+ new ButtonColumn(table, show, 4);
+
+ AbstractAction edit = new AbstractAction() {
+ private static final long serialVersionUID = 302149670181733310L;
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JTable table = (JTable) e.getSource();
+ int modelRow = Integer.valueOf(e.getActionCommand());
+ DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
+ customerDetailsPanel.preloadData(tableModel.getValueAt(modelRow, 0).toString(),
+ tableModel.getValueAt(modelRow, 1).toString(),
+ tableModel.getValueAt(modelRow, 2).toString());
+ customerDetailsPanel.setReadOnly(false);
+ customerDetailsPanel.enableEditMode();
+ ((CardLayout) (cards.getLayout())).show(cards, CUSTOMERDETAILS);
+ }
+ };
+ new ButtonColumn(table, edit, 5);
+
+ AbstractAction delete = new AbstractAction() {
+ private static final long serialVersionUID = 302149670181733310L;
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JTable table = (JTable) e.getSource();
+ int modelRow = Integer.valueOf(e.getActionCommand());
+ DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
+ int answer = JOptionPane.showConfirmDialog(null,
+ "Den Nutzer '" + tableModel.getValueAt(modelRow, 1).toString() + " "
+ + tableModel.getValueAt(modelRow, 2).toString() + "' (ID: "
+ + tableModel.getValueAt(modelRow, 0).toString() + ") wirklich löschen?",
+ "Löschen", JOptionPane.YES_NO_OPTION);
+ if (answer == 0) {
+ kundenService.delete(Integer.parseInt(tableModel.getValueAt(modelRow, 0).toString()));
+ tableModel.removeRow(modelRow);
+ }
+ }
+ };
+ new ButtonColumn(table, delete, 6);
+ }
+
+ private void refresh() {
+ Object[][] data = this.kundenService.getTableData();
+
+ // Add Button Text to table data
+ for (int i = 0; i < data.length; i++) {
+ data[i] = new Object[] { data[i][0], data[i][1], data[i][2], data[i][3], "Anzeigen", "Ändern",
+ "Löschen" };
+ }
+ DefaultTableModel model = new DefaultTableModel(data, columnNames);
+ table.setModel(model);
+ addTableButtons();
+ }
+ }
+
+ private class CustomerDetailsPanel extends JPanel {
+
+ private static final long serialVersionUID = -5183867990205291443L;
+ KundenService kundenService;
+ JTextField id = new JTextField(20);
+ JTextField name = new JTextField(20);
+ JTextField lastName = new JTextField(20);
+ JButton saveBtn = new JButton("Speichern");
+ ActionListener saveAction = new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ kundenService.create(new Kunde(Integer.parseInt(id.getText()), lastName.getText(), name.getText()));
+ customerListPanel.refresh();
+ ((CardLayout) (cards.getLayout())).show(cards, CUSTOMERLIST);
+ }
+ };
+ ActionListener backAction = new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ customerListPanel.refresh();
+ ((CardLayout) (cards.getLayout())).show(cards, CUSTOMERLIST);
+ }
+ };
+ ActionListener editAction = new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ kundenService.update(Integer.parseInt(id.getText()), name.getText(), lastName.getText());
+ customerListPanel.refresh();
+ ((CardLayout) (cards.getLayout())).show(cards, CUSTOMERLIST);
+ }
+ };
+
+ private CustomerDetailsPanel(KundenService kundenService) {
+ this.kundenService = kundenService;
+ this.setLayout(new GridLayout(4, 2));
+ this.add(wrap(new JLabel("ID:")));
+ id.setEditable(false);
+ this.add(wrap(id));
+ this.add(wrap(new JLabel("Name:")));
+ this.add(wrap(name));
+ this.add(wrap(new JLabel("Nachname:")));
+ this.add(wrap(lastName));
+ saveBtn.addActionListener(saveAction);
+ this.add(wrap(saveBtn));
+ JButton printBtn = new JButton("Ausdrucken");
+ printBtn.addActionListener(e -> {
+ System.out.println(
+ "ID: " + id.getText() + " Name: " + name.getText() + " Nachname: " + lastName.getText());
+ });
+ this.add(wrap(printBtn));
+ }
+
+ private void preloadData(String id, String name, String lastName) {
+ this.id.setText(id);
+ this.name.setText(name);
+ this.lastName.setText(lastName);
+ }
+
+ private void clear() {
+ this.id.setText("");
+ this.name.setText("");
+ this.lastName.setText("");
+ this.setReadOnly(false);
+ }
+
+ private void setReadOnly(boolean readonly) {
+ this.name.setEditable(!readonly);
+ this.lastName.setEditable(!readonly);
+ this.saveBtn.setText(readonly ? "Zurück" : "Speichern");
+ this.saveBtn.removeActionListener(this.saveBtn.getActionListeners()[0]);
+ this.saveBtn.addActionListener(readonly ? this.backAction : this.saveAction);
+ }
+
+ private void generateNewId() {
+ this.id.setText(Integer.toString(kundenService.getUnusedId()));
+ }
+
+ private void enableEditMode() {
+ this.saveBtn.removeActionListener(this.saveBtn.getActionListeners()[0]);
+ this.saveBtn.addActionListener(this.editAction);
+ }
+ }
+
+ private class ConfiguratorPanel extends JPanel {
+ private static final long serialVersionUID = 3527260169526726295L;
+ private JLabel priceLabel = new JLabel();
+ private int price = 200;
+ PizzaService pizzaService;
+
+ private ConfiguratorPanel(PizzaService pizzaService) {
+ this.pizzaService = pizzaService;
+ this.setLayout(new GridLayout(5, 2));
+ this.add(wrap(new JLabel("Name:")));
+ JTextField name = new JTextField(20);
+ this.add(wrap(name));
+ this.add(wrap(new JLabel("Größe:")));
+ String[] availPizzaSizes = new String[EnumSet.allOf(PizzaSize.class).size()];
+ int i = 0;
+ for (PizzaSize size : EnumSet.allOf(PizzaSize.class)) {
+ availPizzaSizes[i++] = size.getName();
+ }
+ JList pizzaSize = new JList(availPizzaSizes);
+ this.add(wrap(pizzaSize));
+ this.add(wrap(new JLabel("Belag:")));
+ String[] availToppings = new String[EnumSet.allOf(Topping.class).size()];
+ i = 0;
+ for (Topping topping : EnumSet.allOf(Topping.class)) {
+ availToppings[i++] = topping.getName();
+ }
+ JList toppings = new JList(availToppings);
+ toppings.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+ this.add(wrap(toppings));
+ this.add(wrap(new JPanel()));
+ this.add(wrap(priceLabel));
+ JButton sendBtn = new JButton("Abschicken");
+ sendBtn.addActionListener(e -> {
+ if (name.getText() == "" || pizzaSize.getSelectedIndex() == -1
+ || toppings.getSelectedIndices().length == 0)
+ return;
+ // List pizzas = PizzaIOHandler.read(null);
+ List toppingList = new ArrayList();
+ for (int t : toppings.getSelectedIndices()) {
+ toppingList.add(Topping.values()[t]);
+ }
+ this.pizzaService.create(
+ new Pizza(name.getText(), PizzaSize.values()[pizzaSize.getSelectedIndex()], toppingList));
+ // PizzaIOHandler.write(pizzas, null);
+ pizzaListPanel.refresh();
+ ((CardLayout) (cards.getLayout())).show(cards, PIZZALIST);
+ });
+ JButton printBtn = new JButton("Ausdrucken");
+ printBtn.addActionListener(e -> {
+ System.out.println(Arrays.toString(pizzaService.getTableData()));
+ });
+ this.add(wrap(sendBtn));
+ this.add(wrap(printBtn));
+ setPrice(price);
+ }
+
+ public void setPrice(int price) {
+ this.price = price;
+ priceLabel.setText("Preis: " + price + " Cent");
+ }
+
+ }
+
+ private class PizzaListPanel extends JPanel {
+
+ private static final long serialVersionUID = 9065029635304808892L;
+ PizzaService pizzaService;
+ String[] columnNames = { "Name", "Preis", "Größe", "Toppings" };
+ JTable table;
+
+ private PizzaListPanel(PizzaService pizzaService) {
+ this.pizzaService = pizzaService;
+ Object[][] data = this.pizzaService.getTableData();
+ DefaultTableModel model = new DefaultTableModel(data, columnNames);
+ table = new JTable(model);
+
+ JScrollPane scrollPane = new JScrollPane(table);
+ table.setFillsViewportHeight(true);
+
+ this.setLayout(new BorderLayout());
+ JPanel bottomBar = new JPanel();
+ JButton addPizzaBtn = new JButton("Füge Pizza hinzu");
+ addPizzaBtn.addActionListener(e -> {
+ ((CardLayout) (cards.getLayout())).show(cards, CONFIGURATOR);
+ });
+ bottomBar.add(wrap(addPizzaBtn));
+ JButton printBtn = new JButton("Drucken");
+ printBtn.addActionListener(e -> {
+ System.out.println(Arrays.deepToString(pizzaService.getTableData()));
+ });
+ bottomBar.add(wrap(printBtn));
+ this.add(table.getTableHeader(), BorderLayout.PAGE_START);
+ this.add(bottomBar, BorderLayout.AFTER_LAST_LINE);
+ this.add(scrollPane, BorderLayout.CENTER);
+ }
+
+ private void refresh() {
+ Object[][] data = this.pizzaService.getTableData();
+ DefaultTableModel model = new DefaultTableModel(data, columnNames);
+ table.setModel(model);
+ }
+ }
+
+ private JPanel wrap(Component comp) {
+ JPanel panel = new JPanel();
+ panel.add(comp);
+ return panel;
+ }
+}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt3.pizzashop/src/view/util/ButtonColumn.java b/de.hhn.ai.prog2.blatt3.pizzashop/src/view/util/ButtonColumn.java
new file mode 100644
index 0000000..4f71703
--- /dev/null
+++ b/de.hhn.ai.prog2.blatt3.pizzashop/src/view/util/ButtonColumn.java
@@ -0,0 +1,196 @@
+package view.util;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.table.*;
+
+/**
+ * The ButtonColumn class provides a renderer and an editor that looks like a
+ * JButton. The renderer and editor will then be used for a specified column in
+ * the table. The TableModel will contain the String to be displayed on the
+ * button.
+ *
+ * The button can be invoked by a mouse click or by pressing the space bar when
+ * the cell has focus. Optionally a mnemonic can be set to invoke the button.
+ * When the button is invoked the provided Action is invoked. The source of the
+ * Action will be the table. The action command will contain the model row
+ * number of the button that was clicked.
+ *
+ */
+public class ButtonColumn extends AbstractCellEditor
+ implements TableCellRenderer, TableCellEditor, ActionListener, MouseListener {
+ private static final long serialVersionUID = 5829992577972549859L;
+ private JTable table;
+ private Action action;
+ private int mnemonic;
+ private Border originalBorder;
+ private Border focusBorder;
+
+ private JButton renderButton;
+ private JButton editButton;
+ private Object editorValue;
+ private boolean isButtonColumnEditor;
+
+ /**
+ * Create the ButtonColumn to be used as a renderer and editor. The renderer and
+ * editor will automatically be installed on the TableColumn of the specified
+ * column.
+ *
+ * @param table the table containing the button renderer/editor
+ * @param action the Action to be invoked when the button is invoked
+ * @param column the column to which the button renderer/editor is added
+ */
+ public ButtonColumn(JTable table, Action action, int column) {
+ this.table = table;
+ this.action = action;
+
+ renderButton = new JButton();
+ editButton = new JButton();
+ editButton.setFocusPainted(false);
+ editButton.addActionListener(this);
+ originalBorder = editButton.getBorder();
+ setFocusBorder(new LineBorder(Color.BLUE));
+
+ TableColumnModel columnModel = table.getColumnModel();
+ columnModel.getColumn(column).setCellRenderer(this);
+ columnModel.getColumn(column).setCellEditor(this);
+ table.addMouseListener(this);
+ }
+
+ /**
+ * Get foreground color of the button when the cell has focus
+ *
+ * @return the foreground color
+ */
+ public Border getFocusBorder() {
+ return focusBorder;
+ }
+
+ /**
+ * The foreground color of the button when the cell has focus
+ *
+ * @param focusBorder the foreground color
+ */
+ public void setFocusBorder(Border focusBorder) {
+ this.focusBorder = focusBorder;
+ editButton.setBorder(focusBorder);
+ }
+
+ public int getMnemonic() {
+ return mnemonic;
+ }
+
+ /**
+ * The mnemonic to activate the button when the cell has focus
+ *
+ * @param mnemonic the mnemonic
+ */
+ public void setMnemonic(int mnemonic) {
+ this.mnemonic = mnemonic;
+ renderButton.setMnemonic(mnemonic);
+ editButton.setMnemonic(mnemonic);
+ }
+
+ @Override
+ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
+ if (value == null) {
+ editButton.setText("");
+ editButton.setIcon(null);
+ } else if (value instanceof Icon) {
+ editButton.setText("");
+ editButton.setIcon((Icon) value);
+ } else {
+ editButton.setText(value.toString());
+ editButton.setIcon(null);
+ }
+
+ this.editorValue = value;
+ return editButton;
+ }
+
+ @Override
+ public Object getCellEditorValue() {
+ return editorValue;
+ }
+
+ //
+ // Implement TableCellRenderer interface
+ //
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
+ int row, int column) {
+ if (isSelected) {
+ renderButton.setForeground(table.getSelectionForeground());
+ renderButton.setBackground(table.getSelectionBackground());
+ } else {
+ renderButton.setForeground(table.getForeground());
+ renderButton.setBackground(UIManager.getColor("Button.background"));
+ }
+
+ if (hasFocus) {
+ renderButton.setBorder(focusBorder);
+ } else {
+ renderButton.setBorder(originalBorder);
+ }
+
+ // renderButton.setText( (value == null) ? "" : value.toString() );
+ if (value == null) {
+ renderButton.setText("");
+ renderButton.setIcon(null);
+ } else if (value instanceof Icon) {
+ renderButton.setText("");
+ renderButton.setIcon((Icon) value);
+ } else {
+ renderButton.setText(value.toString());
+ renderButton.setIcon(null);
+ }
+
+ return renderButton;
+ }
+
+ //
+ // Implement ActionListener interface
+ //
+ /*
+ * The button has been pressed. Stop editing and invoke the custom Action
+ */
+ public void actionPerformed(ActionEvent e) {
+ int row = table.convertRowIndexToModel(table.getEditingRow());
+ fireEditingStopped();
+
+ // Invoke the Action
+
+ ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, "" + row);
+ action.actionPerformed(event);
+ }
+
+ //
+ // Implement MouseListener interface
+ //
+ /*
+ * When the mouse is pressed the editor is invoked. If you then then drag the
+ * mouse to another cell before releasing it, the editor is still active. Make
+ * sure editing is stopped when the mouse is released.
+ */
+ public void mousePressed(MouseEvent e) {
+ if (table.isEditing() && table.getCellEditor() == this)
+ isButtonColumnEditor = true;
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if (isButtonColumnEditor && table.isEditing())
+ table.getCellEditor().stopCellEditing();
+
+ isButtonColumnEditor = false;
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+}
\ No newline at end of file
diff --git a/de.hhn.ai.prog2.blatt8.internationalisierung/.idea/workspace.xml b/de.hhn.ai.prog2.blatt8.internationalisierung/.idea/workspace.xml
index 621a0e9..f968faf 100644
--- a/de.hhn.ai.prog2.blatt8.internationalisierung/.idea/workspace.xml
+++ b/de.hhn.ai.prog2.blatt8.internationalisierung/.idea/workspace.xml
@@ -1,17 +1,7 @@
-
-
-
-
-
-
-
-
-
-
-
+
@@ -85,8 +75,8 @@
-
-
+
+
@@ -193,7 +183,7 @@
-
+
@@ -302,10 +292,12 @@
+
+
+
-
@@ -316,7 +308,7 @@
-
+
@@ -432,8 +424,8 @@
-
-
+
+