From 770b837d20bc9aae353c55b4d79d649cc019b236 Mon Sep 17 00:00:00 2001 From: Gregor Riegler Date: Wed, 24 Apr 2013 17:26:24 +0200 Subject: [PATCH] Pizzeria GUI implemented --- .classpath | 2 +- README.md | 3 + run Group.launch | 16 ++ run Pizzeria.launch | 15 ++ .../sbc/valesriegler/common/TableModel.java | 47 ++++ .../tuwien/sbc/valesriegler/group/Group.java | 12 +- .../sbc/valesriegler/group/GroupAgent.java | 4 +- .../sbc/valesriegler/group/MinimalGroup.java | 24 ++ .../group/gui/GroupCreationPanel.java | 10 + .../valesriegler/group/gui/GroupFrame.java | 52 +++-- .../group/gui/GroupOverviewModel.java | 78 +------ .../valesriegler/pizzeria/PizzeriaAgent.java | 32 +++ .../sbc/valesriegler/pizzeria/gui/Order.java | 94 ++++++++ .../valesriegler/pizzeria/gui/PizzaOrder.java | 37 +++ .../pizzeria/gui/PizzeriaFrame.java | 219 ++++++++++++++++++ .../sbc/valesriegler/pizzeria/gui/Table.java | 36 +++ .../gui/tablemodels/GroupsOverviewModel.java | 30 +++ .../gui/tablemodels/OrdersOverviewModel.java | 49 ++++ .../gui/tablemodels/PizzasOfOrderModel.java | 53 +++++ .../tablemodels/TableModelOfSingleOrder.java | 19 ++ .../gui/tablemodels/TablesOverviewModel.java | 48 ++++ .../gui/tablemodels/WaitersOfOrderModel.java | 33 +++ 22 files changed, 816 insertions(+), 97 deletions(-) create mode 100644 run Group.launch create mode 100644 run Pizzeria.launch create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Order.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzaOrder.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java create mode 100644 src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java diff --git a/.classpath b/.classpath index 96fa85c..8dee4f3 100644 --- a/.classpath +++ b/.classpath @@ -27,6 +27,6 @@ - + diff --git a/README.md b/README.md index 6b1ec12..2f71a22 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ Space Based Computing SS 2013 ================== ### How to start the Group GUI mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.group.GroupAgent" + +### How to start the Pizzeria GUI + mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.pizzeria.PizzeriaAgent" ### How to start a Waiter with Id 1 mvn exec:java -Dexec.mainClass="at.ac.tuwien.sbc.valesriegler.jms.waiter.Waiter" -Dexec.args="1" diff --git a/run Group.launch b/run Group.launch new file mode 100644 index 0000000..fadfd2a --- /dev/null +++ b/run Group.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/run Pizzeria.launch b/run Pizzeria.launch new file mode 100644 index 0000000..a31fc91 --- /dev/null +++ b/run Pizzeria.launch @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java new file mode 100644 index 0000000..729a9dd --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/common/TableModel.java @@ -0,0 +1,47 @@ +package at.ac.tuwien.sbc.valesriegler.common; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +/** + * Common base class of table models used in Group GUI and Pizzeria GUI. + * + * @author Gregor Riegler + * + */ +public abstract class TableModel extends AbstractTableModel { + protected static final String UNHANDLEDCOLUMN = "Unhandled column"; + + protected final List items = new ArrayList(); + + public void addItems(List newItems) { + items.addAll(newItems); + + fireTableDataChanged(); + } + + public void setItems(List newItems) { + items.clear(); + addItems(newItems); + } + + @Override + public int getRowCount() { + return items.size(); + } + + @Override + public String getColumnName(int column) { + return getColumns()[column]; + } + + @Override + public int getColumnCount() { + return getColumns().length; + } + + protected abstract String[] getColumns(); + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java index d407046..f95187a 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/Group.java @@ -6,23 +6,22 @@ import java.util.List; import at.ac.tuwien.sbc.valesriegler.common.PizzaType; public class Group { - private int id; - private int size; + private MinimalGroup minimalGroup = new MinimalGroup(); private List pizzas = new ArrayList(); private GroupState state = GroupState.WAITING; public int getId() { - return id; + return minimalGroup.getId(); } public void setId(int id) { - this.id = id; + this.minimalGroup.setId(id); } public int getSize() { - return size; + return this.minimalGroup.getSize(); } public void setSize(int size) { - this.size = size; + this.minimalGroup.setSize(size); } public List getPizzas() { return pizzas; @@ -36,5 +35,4 @@ public class Group { public void setState(GroupState state) { this.state = state; } - } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java index c7fdcf5..75bdfb8 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/GroupAgent.java @@ -5,7 +5,9 @@ import javax.swing.SwingUtilities; import at.ac.tuwien.sbc.valesriegler.group.gui.GroupFrame; /** - * + * The Main class of the Group component. + *

+ * Start the communication and the group GUI: * * @author Gregor Riegler * diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java new file mode 100644 index 0000000..1e4a317 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/MinimalGroup.java @@ -0,0 +1,24 @@ +package at.ac.tuwien.sbc.valesriegler.group; + +/** + * A group bean which only has an id and a size. + * + * @author Gregor Riegler + */ +public class MinimalGroup { + private int id; + private int size; + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public int getSize() { + return size; + } + public void setSize(int size) { + this.size = size; + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java index c8cadc5..3183ab9 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupCreationPanel.java @@ -16,6 +16,16 @@ import javax.swing.SpinnerNumberModel; import at.ac.tuwien.sbc.valesriegler.common.PizzaType; import at.ac.tuwien.sbc.valesriegler.group.gui.GroupFrame.GroupCreationHandler; +/** + * Panel which allows the selection of pizzas and the number of groups to create + *

+ * Features a Create- and Cancel-Button which call the respective methods of the + * {@link GroupCreationHandler} set by {@link #setCreateAndCancelHandler(GroupCreationHandler)} + * + * @author Gregor Riegler + * + */ +@SuppressWarnings("serial") public class GroupCreationPanel extends JPanel { private GroupCreationHandler handler; 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 9f73cc3..3e4ffe3 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 @@ -30,17 +30,17 @@ public class GroupFrame extends JFrame { private AtomicInteger idSource = new AtomicInteger(1); private GroupOverviewModel groupModel; - protected GroupCreationPanel groupCreationPanel; - private static JPanel creationPanel; - private static JPanel chooseGroupSizePanel; public GroupFrame() { - super("Group Creator"); + super("Groups"); JPanel wrapper = new JPanel(); GridLayout wrapperLayout = new GridLayout(2, 1); wrapper.setLayout(wrapperLayout); + // Create Wizard-like panel for the creation of groups initGroupCreation(wrapper); + + // Create the panel for the group overview table initGroupOverview(wrapper); setContentPane(wrapper); @@ -48,24 +48,25 @@ public class GroupFrame extends JFrame { } private void initGroupCreation(JPanel wrapper) { - creationPanel = new JPanel(); - chooseGroupSizePanel = new JPanel(); + final JPanel creationPanel = new JPanel(); + final JPanel chooseGroupSizePanel = new JPanel(); JLabel creationLabel = new JLabel("How many members should the group have?"); JButton next = new JButton("Next"); SpinnerNumberModel model = new SpinnerNumberModel(1,1,4,1); final JSpinner spinner = new JSpinner(model); - - next.addActionListener(new ActionListener() { - + + // When 'next' is clicked the second, final panel of the Group Creation Wizard should be shown + next.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int numberMembers = (int) spinner.getValue(); + final GroupCreationPanel groupCreationPanel = new GroupCreationPanel(numberMembers); + GroupCreationHandler groupCreationHandler = new GroupCreationHandler(creationPanel, chooseGroupSizePanel, groupCreationPanel); - groupCreationPanel = new GroupCreationPanel(numberMembers); - groupCreationPanel.setCreateAndCancelHandler(new GroupCreationHandler()); + groupCreationPanel.setCreateAndCancelHandler(groupCreationHandler); + groupCreationHandler.showGroupCreationDetailPanel(); - chooseGroupSizePanel.setVisible(false); - creationPanel.add(groupCreationPanel); + } }); @@ -95,7 +96,28 @@ public class GroupFrame extends JFrame { } + /** + * Handles the Wizard-like creation of groups. + *

+ * Give an instance of this class as a callback to the Panel from which + * a group creation request should be issued + */ class GroupCreationHandler { + private JPanel creationPanel; + private JPanel chooseGroupSizePanel; + private JPanel groupCreationPanel; + + public GroupCreationHandler(JPanel creationPanel, JPanel chooseGroupSizePanel, JPanel groupCreationPanel) { + this.creationPanel = creationPanel; + this.chooseGroupSizePanel = chooseGroupSizePanel; + this.groupCreationPanel = groupCreationPanel; + } + + public void showGroupCreationDetailPanel() { + chooseGroupSizePanel.setVisible(false); + creationPanel.add(groupCreationPanel); + } + public void handleGroupCreation(GroupCreationRequest gc) { chooseGroupSizePanel.setVisible(true); creationPanel.remove(groupCreationPanel); @@ -114,9 +136,9 @@ public class GroupFrame extends JFrame { group.setSize(gc.size); group.setPizzas(gc.pizzaTypes); - groupModel.addGroup(group); + newGroups.add(group); } - + groupModel.addItems(newGroups); } public void handleCancel() { diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java index 9a014d2..1696fa9 100644 --- a/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/group/gui/GroupOverviewModel.java @@ -5,95 +5,32 @@ import java.util.HashMap; import java.util.List; import java.util.Set; -import javax.swing.table.AbstractTableModel; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.ac.tuwien.sbc.valesriegler.common.PizzaType; +import at.ac.tuwien.sbc.valesriegler.common.TableModel; import at.ac.tuwien.sbc.valesriegler.group.Group; -import at.ac.tuwien.sbc.valesriegler.group.GroupState; -import at.ac.tuwien.sbc.valesriegler.jms.cook.Cook; -public class GroupOverviewModel extends AbstractTableModel { +public class GroupOverviewModel extends TableModel { private static final Logger log = LoggerFactory.getLogger(GroupOverviewModel.class); private static final String STATE = "State"; private static final String PIZZAS = "Pizzas"; private static final String SIZE = "Size"; private static final String ID = "ID"; - private static final String UNHANDLEDCOLUMN = "Unhandled column"; private static final String[] COLUMNS = new String[] { ID, SIZE, PIZZAS, STATE }; - private List groups = new ArrayList(); - - public GroupOverviewModel() { - insertTestData(); - } - - private void insertTestData() { - Group group1 = new Group(); - group1.setId(1); - group1.setSize(3); - group1.setState(GroupState.EATING); - - Group group2 = new Group(); - group2.setId(2); - group2.setSize(1); - group2.setState(GroupState.GONE); - - Group group3 = new Group(); - group3.setId(3); - group3.setSize(2); - group3.setState(GroupState.EATING); - - ArrayList pizzas1 = new ArrayList(); - pizzas1.add(PizzaType.MARGHERITA); - pizzas1.add(PizzaType.CARDINALE); - pizzas1.add(PizzaType.CARDINALE); - - ArrayList pizzas2 = new ArrayList(); - pizzas2.add(PizzaType.MARGHERITA); - pizzas2.add(PizzaType.MARGHERITA); - pizzas2.add(PizzaType.CARDINALE); - - ArrayList pizzas3 = new ArrayList(); - pizzas3.add(PizzaType.MARGHERITA); - pizzas3.add(PizzaType.SALAMI); - pizzas3.add(PizzaType.CARDINALE); - - group1.setPizzas(pizzas1); - group2.setPizzas(pizzas2); - group3.setPizzas(pizzas3); - - groups.add(group1); - groups.add(group2); - groups.add(group3); - - fireTableDataChanged(); - } - - @Override - public int getRowCount() { - return groups.size(); + protected String[] getColumns() { + return COLUMNS; } - @Override - public String getColumnName(int column) { - return COLUMNS[column]; - } - - @Override - public int getColumnCount() { - return COLUMNS.length; - } - @Override public Object getValueAt(int rowIndex, int columnIndex) { - Group group = groups.get(rowIndex); + Group group = items.get(rowIndex); String wantedColumn = COLUMNS[columnIndex]; switch(wantedColumn) { case ID : @@ -139,10 +76,5 @@ public class GroupOverviewModel extends AbstractTableModel { return sb.toString(); } - public void addGroup(Group group) { - groups.add(group); - - fireTableDataChanged(); - } } diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java new file mode 100644 index 0000000..a221c69 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/PizzeriaAgent.java @@ -0,0 +1,32 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria; + +import javax.swing.SwingUtilities; + +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzeriaFrame; +/** + * The Main class of the Pizzeria compoment. + *

+ * Start the communication and the Pizzeria GUI + * + * @author Gregor Riegler + * + */ +public class PizzeriaAgent { + + public static void main(String[] args) { + // TODO initiate communication + + SwingUtilities.invokeLater(new PizzeriaGUI()); + + } + + static class PizzeriaGUI implements Runnable { + @Override + public void run() { + PizzeriaFrame frame = new PizzeriaFrame(); + frame.pack(); + frame.setVisible(true); + } + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Order.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Order.java new file mode 100644 index 0000000..2ef2dc7 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Order.java @@ -0,0 +1,94 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; + +import java.util.List; + +public class Order { + private int id; + private int tableId; + private int groupId; + private OrderStatus status; + + private int waiterIdOfTableAssignment; + private int waiterIdOfOrder; + private int waiterIdOfServing; + private int waiterIdOfPayment; + + private List pizzaOrders; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getTableId() { + return tableId; + } + + public void setTableId(int tableId) { + this.tableId = tableId; + } + + public int getGroupId() { + return groupId; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + public OrderStatus getStatus() { + return status; + } + + public void setStatus(OrderStatus status) { + this.status = status; + } + + public int getWaiterIdOfTableAssignment() { + return waiterIdOfTableAssignment; + } + + public void setWaiterIdOfTableAssignment(int waiterIdOfTableAssignment) { + this.waiterIdOfTableAssignment = waiterIdOfTableAssignment; + } + + public int getWaiterIdOfOrder() { + return waiterIdOfOrder; + } + + public void setWaiterIdOfOrder(int waiterIdOfOrder) { + this.waiterIdOfOrder = waiterIdOfOrder; + } + + public int getWaiterIdOfServing() { + return waiterIdOfServing; + } + + public void setWaiterIdOfServing(int waiterIdOfServing) { + this.waiterIdOfServing = waiterIdOfServing; + } + + public int getWaiterIdOfPayment() { + return waiterIdOfPayment; + } + + public void setWaiterIdOfPayment(int waiterIdOfPayment) { + this.waiterIdOfPayment = waiterIdOfPayment; + } + + public List getPizzaOrders() { + return pizzaOrders; + } + + public void setPizzaOrders(List pizzaOrders) { + this.pizzaOrders = pizzaOrders; + } + + enum OrderStatus { + ORDERED, PAID, DELIVERED + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzaOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzaOrder.java new file mode 100644 index 0000000..852865e --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzaOrder.java @@ -0,0 +1,37 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; + +import at.ac.tuwien.sbc.valesriegler.common.PizzaType; + +public class PizzaOrder { + private PizzaType pizzaType; + private int cookId; + private PizzaOrderStatus status; + + public PizzaType getPizzaType() { + return pizzaType; + } + + public void setPizzaType(PizzaType pizzaType) { + this.pizzaType = pizzaType; + } + + public int getCookId() { + return cookId; + } + + public void setCookId(int cookId) { + this.cookId = cookId; + } + + public PizzaOrderStatus getStatus() { + return status; + } + + public void setStatus(PizzaOrderStatus status) { + this.status = status; + } + + public enum PizzaOrderStatus { + ORDERED, IN_PREPARATION, DONE + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java new file mode 100644 index 0000000..9efb952 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/PizzeriaFrame.java @@ -0,0 +1,219 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; + +import java.awt.GridLayout; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.border.TitledBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; + +import at.ac.tuwien.sbc.valesriegler.common.PizzaType; +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzaOrder.PizzaOrderStatus; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table.TableStatus; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.GroupsOverviewModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.OrdersOverviewModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.PizzasOfOrderModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.TablesOverviewModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels.WaitersOfOrderModel; + +/** + * + * @author Gregor Riegler + */ +public class PizzeriaFrame extends JFrame { + 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)"; + + private OrdersOverviewModel ordersModel; + private GroupsOverviewModel groupModel; + private TablesOverviewModel tablesModel; + private WaitersOfOrderModel waitersModel; + private PizzasOfOrderModel pizzasModel; + + + public PizzeriaFrame() { + super("Pizzeria"); + + initModels(); + + JPanel wrapper = new JPanel(); + GridLayout wrapperLayout = new GridLayout(2, 2); + wrapper.setLayout(wrapperLayout); + + // Create the tables overview + initTablesOverview(wrapper); + + // Create the waiting groups table overview + initWaitingGroupsOverview(wrapper); + + //Create the overview table of the orders + JTable ordersTable = initOrdersOverview(wrapper); + + // Create the order detail tables + initOrdersDetails(wrapper, ordersTable); + + setContentPane(wrapper); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + private void initModels() { + List orders = getOrdersTestData(); + List tables = getTablesTestData(); + + ordersModel = new OrdersOverviewModel(orders); + groupModel = new GroupsOverviewModel(); + tablesModel = new TablesOverviewModel(tables); + 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); + detailWrapper.setLayout(wrapperLayout); + + final JPanel waitersPanel = new JPanel(); + final JPanel pizzasPanel = new JPanel(); + createTableInTitledPanel(waitersPanel, waitersModel, ""); + createTableInTitledPanel(pizzasPanel, pizzasModel, ""); + + /** + * Update the displayed order in the waiter and pizza detail tables when an order + * gets selected in the orders table + */ + ordersTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + ListSelectionModel lsm = (ListSelectionModel)e.getSource(); + int minIndex = lsm.getMinSelectionIndex(); + + Order currentOrder = ordersModel.getOrderOfRow(minIndex); + waitersPanel.setBorder(new TitledBorder(String.format(WAITER_IDS_CAPTION,currentOrder.getId()))); + pizzasPanel.setBorder(new TitledBorder(String.format(PIZZAS_CAPTION,currentOrder.getId()))); + waitersModel.setCurrentOrder(currentOrder); + pizzasModel.setCurrentOrder(currentOrder); + + waitersPanel.setVisible(true); + pizzasPanel.setVisible(true); + } + }); + + detailWrapper.add(waitersPanel); + detailWrapper.add(pizzasPanel); + waitersPanel.setVisible(false); + pizzasPanel.setVisible(false); + + wrapper.add(detailWrapper); + + } + + private JTable initOrdersOverview(JPanel wrapper) { + JPanel tablePanel = new JPanel(); + JTable orderTable = createTableInTitledPanel(tablePanel, ordersModel, "Orders"); + + wrapper.add(tablePanel); + + return orderTable; + } + + private void initWaitingGroupsOverview(JPanel wrapper) { + JPanel tablePanel = new JPanel(); + createTableInTitledPanel(tablePanel, groupModel, "Groups"); + + wrapper.add(tablePanel); + } + + private void initTablesOverview(JPanel wrapper) { + JPanel tablePanel = new JPanel(); + final JLabel freeTablesLabel = new JLabel(getNumberOfFreeTables()); + tablePanel.add(freeTablesLabel); + createTableInTitledPanel(tablePanel, tablesModel, "Tables"); + + tablesModel.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + freeTablesLabel.setText(getNumberOfFreeTables()); + } + }); + + + wrapper.add(tablePanel); + } + + + private JTable createTableInTitledPanel(JPanel wrapperPanel, TableModel model, String title) { + JTable table = new JTable(model); + JScrollPane scrollPane = new JScrollPane(table); + + wrapperPanel.setBorder(new TitledBorder(title)); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + wrapperPanel.add(scrollPane); + + return table; + } + + private List getOrdersTestData() { + List orders = new ArrayList<>(); + Order order1 = new Order(); + Order order2 = new Order(); + Order order3 = new Order(); + Order order4 = new Order(); + + order1.setId(1); + order2.setId(2); + order3.setId(3); + order4.setId(4); + + order1.setWaiterIdOfOrder(4); + order2.setWaiterIdOfServing(2); + + List pizzas = new ArrayList<>(); + PizzaOrder pizzaOrder1 = new PizzaOrder(); + pizzaOrder1.setPizzaType(PizzaType.CARDINALE); + pizzaOrder1.setStatus(PizzaOrderStatus.DONE); + pizzaOrder1.setCookId(3); + pizzas.add(pizzaOrder1); + order1.setPizzaOrders(pizzas); + + orders.add(order1); + orders.add(order2); + orders.add(order3); + orders.add(order4); + return orders; + } + + private String getNumberOfFreeTables() { + return String.format(FREE_TABLES, tablesModel.getNumberOfFreeTables()); + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java new file mode 100644 index 0000000..5ee0531 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/Table.java @@ -0,0 +1,36 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui; + +public class Table { + + private int id; + private TableStatus status; + private int groupId; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public TableStatus getStatus() { + return status; + } + + public void setStatus(TableStatus status) { + this.status = status; + } + + public int getGroupId() { + return groupId; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + public enum TableStatus { + FREE, OCCUPIED; + } +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java new file mode 100644 index 0000000..86ab447 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/GroupsOverviewModel.java @@ -0,0 +1,30 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; + +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.group.MinimalGroup; + +public class GroupsOverviewModel extends TableModel { + private static final String ID = "ID"; + private static final String SIZE = "Size"; + + private static final String[] COLUMNS = new String[] { + ID, SIZE + }; + + @Override + protected String[] getColumns() { + return COLUMNS; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + MinimalGroup group = items.get(rowIndex); + String wantedColumn = COLUMNS[columnIndex]; + switch(wantedColumn) { + case ID : return group.getId(); + case SIZE : return group.getSize(); + default : throw new RuntimeException(UNHANDLEDCOLUMN); + } + } + +} 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 new file mode 100644 index 0000000..7352648 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/OrdersOverviewModel.java @@ -0,0 +1,49 @@ +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; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; + +public class OrdersOverviewModel extends TableModel { + private static final String ID = "Order ID"; + private static final String TABLE_ID = "Table ID"; + private static final String GROUP_ID = "Group ID"; + private static final String STATUS = "Status"; + + private static final String[] COLUMNS = new String[] { + ID, TABLE_ID, GROUP_ID, STATUS + }; + + public OrdersOverviewModel(List defaultOrders) { + setItems(defaultOrders); + + + + + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + Order order = items.get(rowIndex); + String wantedColumn = COLUMNS[columnIndex]; + switch(wantedColumn) { + case ID : return order.getId(); + case TABLE_ID : return order.getTableId(); + case GROUP_ID : return order.getGroupId(); + case STATUS : return order.getStatus(); + default : throw new RuntimeException(UNHANDLEDCOLUMN); + } + } + + public Order getOrderOfRow(int rowIndex) { + return items.get(rowIndex); + } + + @Override + protected String[] getColumns() { + return COLUMNS; + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java new file mode 100644 index 0000000..10405eb --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/PizzasOfOrderModel.java @@ -0,0 +1,53 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; + +import java.util.List; + +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.PizzaOrder; + +public class PizzasOfOrderModel extends TableModel { + private static final String TYPE = "Type"; + private static final String STATUS = "Status"; + private static final String COOK = "Cook"; + + private static final String[] COLUMNS = new String[] { + TYPE, STATUS, COOK + }; + + private Order currentOrder; + + public void setCurrentOrder(Order currentOrder) { + this.currentOrder = currentOrder; + + fireTableDataChanged(); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + if(rowIndex > 0) return null; + + List pizzaOrders = currentOrder.getPizzaOrders(); + if(pizzaOrders == null) return null; + + PizzaOrder pizzaOrder = pizzaOrders.get(rowIndex); + String wantedColumn = COLUMNS[columnIndex]; + switch(wantedColumn) { + case TYPE : return pizzaOrder.getPizzaType(); + case STATUS : return pizzaOrder.getStatus(); + case COOK : return pizzaOrder.getCookId(); + default : throw new RuntimeException(UNHANDLEDCOLUMN); + } + } + + @Override + protected String[] getColumns() { + return COLUMNS; + } + + @Override + public int getRowCount() { + return currentOrder == null ? 0 : 1; + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java new file mode 100644 index 0000000..2fa3549 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TableModelOfSingleOrder.java @@ -0,0 +1,19 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; + +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; + +public abstract class TableModelOfSingleOrder extends TableModel { + protected Order currentOrder; + + public void setCurrentOrder(Order currentOrder) { + this.currentOrder = currentOrder; + + fireTableDataChanged(); + } + + @Override + public int getRowCount() { + return currentOrder == null ? 0 : 1; + } +} 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 new file mode 100644 index 0000000..00750c2 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/TablesOverviewModel.java @@ -0,0 +1,48 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; + +import java.util.List; + +import at.ac.tuwien.sbc.valesriegler.common.TableModel; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table; +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Table.TableStatus; + +public class TablesOverviewModel extends TableModel
{ + private static final String TABLE_ID = "ID"; + private static final String STATUS = "Status"; + private static final String GROUP_ID = "Group ID"; + private static final String[] COLUMNS = new String[] { + TABLE_ID, STATUS, GROUP_ID + }; + + public TablesOverviewModel(List
tables) { + setItems(tables); + } + + @Override + protected String[] getColumns() { + return COLUMNS; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + Table table = items.get(rowIndex); + String wantedColumn = COLUMNS[columnIndex]; + switch(wantedColumn) { + case TABLE_ID : return table.getId(); + case STATUS : return table.getStatus(); + case GROUP_ID : return table.getGroupId(); + default : throw new RuntimeException(UNHANDLEDCOLUMN); + } + } + + public int getNumberOfFreeTables() { + int i=0; + for(Table table : items) { + if(table.getStatus() == TableStatus.FREE) { + i = i+1; + } + } + return i; + } + +} diff --git a/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java new file mode 100644 index 0000000..3b80a98 --- /dev/null +++ b/src/main/java/at/ac/tuwien/sbc/valesriegler/pizzeria/gui/tablemodels/WaitersOfOrderModel.java @@ -0,0 +1,33 @@ +package at.ac.tuwien.sbc.valesriegler.pizzeria.gui.tablemodels; + +import at.ac.tuwien.sbc.valesriegler.pizzeria.gui.Order; + +public class WaitersOfOrderModel extends TableModelOfSingleOrder { + private static final String TABLE_ASSIGNMENT = "Table Assignment"; + private static final String ORDER = "Order"; + private static final String SERVING = "Serving"; + private static final String PAYMENT = "Payment"; + private static final String[] COLUMNS = new String[] { + TABLE_ASSIGNMENT, ORDER, SERVING, PAYMENT + }; + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + if(rowIndex > 0) return null; + + String wantedColumn = COLUMNS[columnIndex]; + switch(wantedColumn) { + case TABLE_ASSIGNMENT : return currentOrder.getWaiterIdOfTableAssignment(); + case ORDER : return currentOrder.getWaiterIdOfOrder(); + case SERVING : return currentOrder.getWaiterIdOfServing(); + case PAYMENT : return currentOrder.getWaiterIdOfPayment(); + default : throw new RuntimeException(UNHANDLEDCOLUMN); + } + } + + @Override + protected String[] getColumns() { + return COLUMNS; + } + +} -- 2.43.0