-
Notifications
You must be signed in to change notification settings - Fork 1
/
RecipesGUI.java
389 lines (355 loc) · 17 KB
/
RecipesGUI.java
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*
RecipesGUI
The RecipesGUI has a bottom banner that allows the user to navigate to other pages.
The Fridge button navigates the user to the FridgeGUI
The Pantry button navigates the user to the PantryGUI
The Dashboard button navigates the user to the DashboardGUI
The Recipes button is disabled since the user is already in the RecipesGUI
The Household button navigates the user to the HouseholdGUI
The Shopping List button navigates the user to the ShoppingListGUI
The RecipesGUI shows the user the recipes that can be made from the Account's
pantry and fridge
When the view recipe button is clicked, the user will be navigated to the ViewRecipeGUI
*/
/**
*
* @author joahp
*/
public class RecipesGUI extends javax.swing.JFrame
{
/**
* Creates new form DashboardGUI
*/
private Account account;
private Member member;
private javax.swing.DefaultListModel<String> itemModel;
public RecipesGUI()
{
initComponents();
botBanRecipesButton.setEnabled(false);
}
public RecipesGUI(Account acc, Member mem)
{
initComponents();
botBanRecipesButton.setEnabled(false);
errorLabel.setVisible(false);
account = acc;
member = mem;
itemModel = new javax.swing.DefaultListModel<String>();
recipeJList.setModel(itemModel);
populateItemModel();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents()
{
body = new javax.swing.JPanel();
title = new javax.swing.JLabel();
itemsLabel = new javax.swing.JLabel();
botBanPanel = new javax.swing.JPanel();
botBanFridgeButton = new javax.swing.JButton();
botBanPantryButton = new javax.swing.JButton();
botBanDashboardButton = new javax.swing.JButton();
botBanRecipesButton = new javax.swing.JButton();
botBanHHButton = new javax.swing.JButton();
errorLabel = new javax.swing.JLabel();
botBanSLButton = new javax.swing.JButton();
itemScrollPane = new javax.swing.JScrollPane();
recipeJList = new javax.swing.JList<>();
viewRecipeButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
title.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
title.setText("Recipes");
title.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
itemsLabel.setText("Items:");
botBanFridgeButton.setText("Fridge");
botBanFridgeButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
botBanFridgeButtonActionPerformed(evt);
}
});
botBanPantryButton.setText("Pantry");
botBanPantryButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
botBanPantryButtonActionPerformed(evt);
}
});
botBanDashboardButton.setText("Dashboard");
botBanDashboardButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
botBanDashboardButtonActionPerformed(evt);
}
});
botBanRecipesButton.setText("Recipes");
botBanRecipesButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
botBanRecipesButtonActionPerformed(evt);
}
});
botBanHHButton.setText("Household");
botBanHHButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
botBanHHButtonActionPerformed(evt);
}
});
errorLabel.setForeground(new java.awt.Color(255, 0, 0));
errorLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
errorLabel.setText("Invalid Selection");
botBanSLButton.setText("Shopping List");
botBanSLButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
botBanSLButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout botBanPanelLayout = new javax.swing.GroupLayout(botBanPanel);
botBanPanel.setLayout(botBanPanelLayout);
botBanPanelLayout.setHorizontalGroup(
botBanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, botBanPanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(73, 73, 73))
.addGroup(botBanPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(botBanFridgeButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(botBanPantryButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(botBanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(botBanDashboardButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(botBanSLButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(botBanRecipesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(botBanHHButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(22, 22, 22))
);
botBanPanelLayout.setVerticalGroup(
botBanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, botBanPanelLayout.createSequentialGroup()
.addComponent(errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
.addGroup(botBanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(botBanFridgeButton)
.addComponent(botBanPantryButton)
.addComponent(botBanDashboardButton)
.addComponent(botBanRecipesButton)
.addComponent(botBanHHButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(botBanSLButton)
.addGap(16, 16, 16))
);
recipeJList.setModel(new javax.swing.AbstractListModel<String>()
{
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
recipeJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
recipeJList.addMouseWheelListener(new java.awt.event.MouseWheelListener()
{
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt)
{
recipeJListMouseWheelMoved(evt);
}
});
itemScrollPane.setViewportView(recipeJList);
viewRecipeButton.setText("View Recipe");
viewRecipeButton.setPreferredSize(new java.awt.Dimension(45, 23));
viewRecipeButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
viewRecipeButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout bodyLayout = new javax.swing.GroupLayout(body);
body.setLayout(bodyLayout);
bodyLayout.setHorizontalGroup(
bodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(title, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(bodyLayout.createSequentialGroup()
.addComponent(botBanPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(bodyLayout.createSequentialGroup()
.addGroup(bodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(bodyLayout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(itemsLabel))
.addGroup(bodyLayout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(bodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(itemScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
.addComponent(viewRecipeButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
bodyLayout.setVerticalGroup(
bodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(bodyLayout.createSequentialGroup()
.addContainerGap()
.addComponent(title)
.addGap(18, 18, 18)
.addComponent(itemsLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(itemScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(viewRecipeButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(botBanPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(body, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(body, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void recipeJListMouseWheelMoved(java.awt.event.MouseWheelEvent evt)//GEN-FIRST:event_recipeJListMouseWheelMoved
{//GEN-HEADEREND:event_recipeJListMouseWheelMoved
//intentionally left blank
}//GEN-LAST:event_recipeJListMouseWheelMoved
//switch to ShoppingListGUI when the shopping list button is clicked
private void botBanSLButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botBanSLButtonActionPerformed
{//GEN-HEADEREND:event_botBanSLButtonActionPerformed
this.dispose();
ShoppingListGUI sl = new ShoppingListGUI(account, member);
sl.setVisible(true);
}//GEN-LAST:event_botBanSLButtonActionPerformed
//switch to FridgeGUI when the fridge button is clicked
private void botBanFridgeButtonActionPerformed(java.awt.event.ActionEvent evt)
{
this.dispose();
FridgeGUI fridge = new FridgeGUI(account, member);
fridge.setVisible(true);
}
//switch to PantryGUI when the pantry button is clicked
private void botBanPantryButtonActionPerformed(java.awt.event.ActionEvent evt)
{
this.dispose();
PantryGUI pantry = new PantryGUI(account, member);
pantry.setVisible(true);
}
//switch to DashboardGUI when the dashboard button is clicked
private void botBanDashboardButtonActionPerformed(java.awt.event.ActionEvent evt)
{
this.dispose();
DashboardGUI dashboard = new DashboardGUI(account, member);
dashboard.setVisible(true);
}
//switch to RecipesGUI when the recipes button is clicked
private void botBanRecipesButtonActionPerformed(java.awt.event.ActionEvent evt)
{
this.dispose();
RecipesGUI recipes = new RecipesGUI(account, member);
recipes.setVisible(true);
}
//switch to HouseholdGUI when the household button is clicked
private void botBanHHButtonActionPerformed(java.awt.event.ActionEvent evt)
{
this.dispose();
HouseholdGUI hh = new HouseholdGUI(account, member);
hh.setVisible(true);
}
//switch to AddItemGUI when the add an item button is clicked
private void viewRecipeButtonActionPerformed(java.awt.event.ActionEvent evt)
{
//get the name of the recipe to be viewed
String recipeName = recipeJList.getSelectedValue();
//if no recipe was selected, tell user
if (recipeName == null)
{
errorLabel.setText("There is no recipe selected");
errorLabel.setVisible(true);
}
//there is a recipe that was selected
else
{
RecipeDBH rdbh;
try
{
rdbh = new RecipeDBH();
}
catch (Exception ex)
{
this.dispose();
LogInGUI logIn = new LogInGUI(account, member);
logIn.setVisible(true);
return;
}
this.dispose();
ViewRecipeGUI viewRecipe = new ViewRecipeGUI(account, member,
rdbh.search(recipeName));
viewRecipe.setVisible(true);
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel body;
private javax.swing.JButton botBanDashboardButton;
private javax.swing.JButton botBanFridgeButton;
private javax.swing.JButton botBanHHButton;
private javax.swing.JPanel botBanPanel;
private javax.swing.JButton botBanPantryButton;
private javax.swing.JButton botBanRecipesButton;
private javax.swing.JButton botBanSLButton;
private javax.swing.JLabel errorLabel;
private javax.swing.JScrollPane itemScrollPane;
private javax.swing.JLabel itemsLabel;
private javax.swing.JList<String> recipeJList;
private javax.swing.JLabel title;
private javax.swing.JButton viewRecipeButton;
// End of variables declaration//GEN-END:variables
//fill the list with available recipes
private void populateItemModel()
{
DatabaseHandler dbh = null;
RecipeDBH rdbh = null;
//try to make the RecipeDBH
try
{
dbh = new DatabaseHandler(account.getHouseholdCode());
rdbh = new RecipeDBH();
}
//catch error
//return user to LogInGUI
catch (Exception ex)
{
this.dispose();
LogInGUI logIn = new LogInGUI(account, member);
logIn.setVisible(true);
return;
}
//get available recipes from RecipeDBH
Recipe[] recipes = rdbh.getRecipes(dbh.getPantry(),
dbh.getFridge());
//add non-null recipe's names to the GUI list
for (Recipe r : recipes)
{
if (r != null)
{
itemModel.addElement(r.getName());
}
}
}
}