From aabcbf5385787755ed42b69ba0a6e05845568a22 Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Thu, 25 Apr 2013 11:44:19 +0200 Subject: [PATCH] Ask for number of tables on start of the Pizzeria GUI --- .gitignore | 1 + .../valesriegler/group/gui/GroupFrame.java | 7 ++- .../pizzeria/gui/PizzeriaFrame.java | 44 ++++++++++--------- .../gui/tablemodels/OrdersOverviewModel.java | 4 -- .../gui/tablemodels/TablesOverviewModel.java | 27 ++++++++++-- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 175d85b..3066c64 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ #gen/* #bin/* target/* +/target diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java index 3e4ffe3..84156a2 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupFrame.java @@ -27,7 +27,7 @@ import at.ac.tuwien.sbc.valesriegler.group.Group; * */ public class GroupFrame extends JFrame { - private AtomicInteger idSource = new AtomicInteger(1); + private int idCounter = 1; private GroupOverviewModel groupModel; @@ -124,17 +124,16 @@ public class GroupFrame extends JFrame { creationPanel.repaint(); createGroups(gc); - - JOptionPane.showMessageDialog(null,"Groups were created!"); } private void createGroups(GroupCreationRequest gc) { List newGroups = new ArrayList<>(); for(int i=0; i */ public class PizzeriaFrame extends JFrame { + private static final String WRONG_INPUT = "Wrong input"; + private static final String THE_NUMBER_MUST_BE_GREATER_OR_EQUAL_TO_1 = "The number must be greater or equal to 1"; + private static final String YOUR_INPUT_CANNOT_BE_PARSED_AS_A_NUMBER = "Your input cannot be parsed as a number!"; + private static final String PLEASE_INPUT_THE_NUMBER_OF_TABLES_TO_CREATE = "Please input the number of tables to create"; private static String WAITER_IDS_CAPTION = "Waiter-IDs of order %d"; private static String PIZZAS_CAPTION = "Pizzas of order %d"; private static String FREE_TABLES = "There are currently %d free table(s)"; @@ -68,35 +73,34 @@ public class PizzeriaFrame extends JFrame { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } + private int getNumberOfTables() { + int numberOfTables; + String numberOfTablesInput = JOptionPane.showInputDialog(PLEASE_INPUT_THE_NUMBER_OF_TABLES_TO_CREATE); + try { + numberOfTables = Integer.parseInt(numberOfTablesInput); + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(this, YOUR_INPUT_CANNOT_BE_PARSED_AS_A_NUMBER, WRONG_INPUT, JOptionPane.ERROR_MESSAGE); + return getNumberOfTables(); + } + + if(numberOfTables < 1) { + JOptionPane.showMessageDialog(this, THE_NUMBER_MUST_BE_GREATER_OR_EQUAL_TO_1, WRONG_INPUT, JOptionPane.ERROR_MESSAGE); + return getNumberOfTables(); + } + + return numberOfTables; + } + private void initModels() { List orders = getOrdersTestData(); - List tables = getTablesTestData(); ordersModel = new OrdersOverviewModel(orders); groupModel = new GroupsOverviewModel(); - tablesModel = new TablesOverviewModel(tables); + tablesModel = new TablesOverviewModel(getNumberOfTables()); waitersModel = new WaitersOfOrderModel(); pizzasModel = new PizzasOfOrderModel(); } - - - private List
getTablesTestData() { - List
tables = new ArrayList<>(); - Table table1 = new Table(); - Table table2 = new Table(); - table1.setId(1); - table2.setId(2); - table1.setGroupId(4); - table2.setGroupId(3); - table1.setStatus(TableStatus.OCCUPIED); - table2.setStatus(TableStatus.FREE); - tables.add(table1); - tables.add(table2); - - return tables; - } - private void initOrdersDetails(JPanel wrapper, JTable ordersTable) { JPanel detailWrapper = new JPanel(); GridLayout wrapperLayout = new GridLayout(2, 1); diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java index 7352648..abdbfae 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java @@ -18,10 +18,6 @@ public class OrdersOverviewModel extends TableModel { public OrdersOverviewModel(List defaultOrders) { setItems(defaultOrders); - - - - } @Override diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java index 00750c2..67c1311 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java @@ -1,5 +1,6 @@ package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; +import java.util.ArrayList; import java.util.List; import at.ac.tuwien.sbc.valesriegler.common.TableModel; @@ -13,11 +14,13 @@ public class TablesOverviewModel extends TableModel
{ private static final String[] COLUMNS = new String[] { TABLE_ID, STATUS, GROUP_ID }; + private int idCounter = 1; - public TablesOverviewModel(List
tables) { - setItems(tables); + public TablesOverviewModel(int numberOfTables) { + createFreeTables(numberOfTables); } - + + @Override protected String[] getColumns() { return COLUMNS; @@ -44,5 +47,23 @@ public class TablesOverviewModel extends TableModel
{ } return i; } + + + private void createFreeTables(int numberOfTables) { + List
tables = new ArrayList
(); + for(int i=0; i