-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveItemMenu.java
More file actions
147 lines (131 loc) · 5.23 KB
/
RemoveItemMenu.java
File metadata and controls
147 lines (131 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Jason Jasper
// David Martin-Vaquero
// Jared Mclaren
// Regine Villongco
// Chemen Wong
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import javax.swing.*;
import javax.swing.border.*;
/**
* IS 380 Final Project - Restaurant Point of Sale program.
* @author Jason Jasper, David Martin-Vaquero, Jared Mclaren, Regine Villongco, Chemen Wong
* @version 0.1.0
*
* This is the RemoveItem GUI component. This will allow the user to select items from a list supplied by Order
* which will be deleted from the order once the OK button is pressed.
*
*/
public class RemoveItemMenu extends JFrame {
private int tableNumber;
private String[] itemArray;
/**
Constructor for remove item menu.
@param A table number.
*/
public RemoveItemMenu(int tableNum) {
tableNumber = tableNum;
constructItemArray();
initComponents();
setTitle("Table "+tableNumber+" Select item(s) to remove.");
}
/**
Method for creating an item array.
*/
private void constructItemArray() {
itemArray = RestaurantPOS.tableArray[tableNumber-1].getItemList();
}
/**
Method for cancel button's action.
@param ActionEvent object generated.
*/
private void cancelButtonActionPerformed(ActionEvent e) {
this.dispose();
}
/**
Method for ok button's action.
@param ActionEvent object generated.
*/
private void okButtonActionPerformed(ActionEvent e) {
int[] itemArray = itemList.getSelectedIndices();
System.out.println("Deleting item indices: " + Arrays.toString(itemArray));
int itemCount = 0; //This is necessary to avoid out of bound indices.
for (int i=0; i<itemArray.length; i++) { //Loop through each index in array and remove.
RestaurantPOS.tableArray[tableNumber-1].subFoodItemsFromOrder(itemArray[i]-itemCount); //Remove item at readjusted index.
itemCount++;
}
JOptionPane.showMessageDialog(null,itemArray.length+" item(s) removed.",
"Items Removed", JOptionPane.INFORMATION_MESSAGE);
this.dispose();
}
/**
Method for creating panels, buttons, and lists.
*/
private void initComponents() {
dialogPane = new JPanel();
contentPanel = new JPanel();
itemScrollPane1 = new JScrollPane();
itemList = new JList(itemArray);
buttonBar = new JPanel();
okButton = new JButton();
cancelButton = new JButton();
//======== this ========
setTitle("Select Item(s) To Remove");
var contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
//======== dialogPane ========
{
dialogPane.setLayout(new BorderLayout());
//======== contentPanel ========
{
contentPanel.setLayout(new BorderLayout());
//======== itemScrollPane1 ========
{
itemScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//---- itemList ----
itemList.setFont(new Font("Tahoma", Font.PLAIN, 18));
itemScrollPane1.setViewportView(itemList);
}
contentPanel.add(itemScrollPane1, BorderLayout.CENTER);
}
// Add to content panel to dialog pane.
dialogPane.add(contentPanel, BorderLayout.CENTER);
//======== buttonBar ========
{
buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
buttonBar.setLayout(new GridBagLayout());
((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};
//---- okButton ----
okButton.setText("OK");
okButton.setFont(new Font("Tahoma", Font.PLAIN, 16));
okButton.addActionListener(e -> okButtonActionPerformed(e));
buttonBar.add(okButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
//---- cancelButton ----
cancelButton.setText("Cancel");
cancelButton.setFont(new Font("Tahoma", Font.PLAIN, 16));
cancelButton.addActionListener(e -> cancelButtonActionPerformed(e));
buttonBar.add(cancelButton, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
}
// Add buttons to dialog pane.
dialogPane.add(buttonBar, BorderLayout.SOUTH);
}
// Add to content pane.
contentPane.add(dialogPane, BorderLayout.CENTER);
setSize(400, 375);
setLocationRelativeTo(getOwner());
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
private JPanel dialogPane;
private JPanel contentPanel;
private JScrollPane itemScrollPane1;
private JList itemList;
private JPanel buttonBar;
private JButton okButton;
private JButton cancelButton;
}