/Users/e1818782/NetBeansProjects/IA Stuff/RecipeDatabase_Nicolas/src/nicolas/GUIProto.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 /*
  7 EXTENSIBILITY LIST
  8 Implement Save/Load Capabilities
  9 Implement selection of recipes from display table. Display their statistics
 10 Implement method to copy-paste recipes directly from display table. Could inclu-
 11 -de a custom toString method so that teh client can extract recipes by name -
 12 -or otherwise
 13 
 14 */
 15 package nicolas;
 16 
 17 import java.awt.BorderLayout;
 18 import java.util.ArrayList;
 19 import javafx.scene.control.ComboBox;
 20 import javax.swing.ComboBoxModel;
 21 import javax.swing.DefaultComboBoxModel;
 22 import javax.swing.DefaultListModel;
 23 import javax.swing.JOptionPane;
 24 import javax.swing.ListModel;
 25 import jdk.nashorn.internal.scripts.JO;
 26 
 27 /**
 28  *
 29  * @author 18782
 30  */
 31 public class GUIProto extends javax.swing.JFrame {
 32 
 33     /**
 34      * Creates new form GUIProto    
 35      */
 36     public GUIProto() {
 37         initComponents();
 38         /////////Sample Recipe////////
 39      /*   ArrayList<Ingredients> sampleing=new ArrayList<>();
 40         sampleing.add(new Ingredients("Sample Ingredient", 24, "Tablespoons"));
 41         recipeList.add(new Recipe(10, "SampleRecipe", 100, 3, 20, "Sample Notes",sampleing) );
 42         System.out.println(recipeList.get(numRecipes).getName());
 43         numRecipes++;*/
 44         /////////Sample Recipe////////
 45         SaveLoad sli= new SaveLoad();
 46    recipeList= sli.loadRec();
 47 //        System.out.println(recipeList.get(0).getIng().get(0).getIngName());
 48            viewTable.setModel(new javax.swing.table.DefaultTableModel(
 49             new Object [][] {
 50                 {null, null, null, null},
 51                 {null, null, null, null},
 52                 {null, null, null, null},
 53                  {null, null, null, null},
 54                 {null, null, null, null},
 55                 {null, null, null, null},
 56                  {null, null, null, null},
 57                 {null, null, null, null},
 58                 {null, null, null, null},
 59                  {null, null, null, null},
 60                 {null, null, null, null},
 61                 {null, null, null, null},
 62                         {null, null, null, null},
 63                 {null, null, null, null},
 64                 {null, null, null, null},
 65                  {null, null, null, null},
 66                 {null, null, null, null},
 67                 {null, null, null, null},
 68                  {null, null, null, null},
 69                 {null, null, null, null},
 70                 {null, null, null, null},
 71                  {null, null, null, null},
 72                 {null, null, null, null},
 73                 {null, null, null, null},
 74 
 75                 {null, null, null, null}
 76             },
 77             new String [] {
 78                 "Name", "Servings", "Cost", "Calories"
 79             }));
 80         
 81         
 82     }
 83 
 84     /**
 85      * This method is called from within the constructor to initialize the form.
 86      * WARNING: Do NOT modify this code. The content of this method is always
 87      * regenerated by the Form Editor.
 88      */
 89     @SuppressWarnings("unchecked")
 90     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 91     private void initComponents() {
 92 
 93         ingGroup = new javax.swing.ButtonGroup();
 94         tabs = new javax.swing.JTabbedPane();
 95         inputPanel = new javax.swing.JPanel();
 96         nameLab = new javax.swing.JLabel();
 97         nameField = new javax.swing.JTextField();
 98         servingLab = new javax.swing.JLabel();
 99         servingField = new javax.swing.JTextField();
100         methodsLab = new javax.swing.JLabel();
101         methodsScroll = new javax.swing.JScrollPane();
102         methodsArea = new javax.swing.JTextArea();
103         submitBut = new javax.swing.JButton();
104         ingBut = new javax.swing.JButton();
105         jLabel1 = new javax.swing.JLabel();
106         sellPrice = new javax.swing.JTextField();
107         calLabel = new javax.swing.JLabel();
108         calBox = new javax.swing.JTextField();
109         viewPanel = new javax.swing.JPanel();
110         viewScroll = new javax.swing.JScrollPane();
111         viewTable = new javax.swing.JTable();
112         detailsBox = new javax.swing.JComboBox<>();
113         jLabel2 = new javax.swing.JLabel();
114         detailsBut = new javax.swing.JButton();
115         calcPanel = new javax.swing.JPanel();
116         recipeBox = new javax.swing.JComboBox<>();
117         costLab = new javax.swing.JLabel();
118         profitLab = new javax.swing.JLabel();
119         convBut = new javax.swing.JButton();
120         calcBut = new javax.swing.JButton();
121         servConverter = new javax.swing.JTextField();
122         jLabel3 = new javax.swing.JLabel();
123         saveBut = new javax.swing.JButton();
124         menuBar = new javax.swing.JMenuBar();
125         fileMenu = new javax.swing.JMenu();
126         exportRecipes = new javax.swing.JMenuItem();
127         exportMenu = new javax.swing.JMenuItem();
128         editMenu = new javax.swing.JMenu();
129         cutMenuItem = new javax.swing.JMenuItem();
130         copyMenuItem = new javax.swing.JMenuItem();
131         pasteMenuItem = new javax.swing.JMenuItem();
132         deleteMenuItem = new javax.swing.JMenuItem();
133         helpMenu = new javax.swing.JMenu();
134         contentsMenuItem = new javax.swing.JMenuItem();
135         aboutMenuItem = new javax.swing.JMenuItem();
136 
137         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
138 
139         tabs.addMouseListener(new java.awt.event.MouseAdapter() {
140             public void mouseReleased(java.awt.event.MouseEvent evt) {
141                 tabsMouseReleased(evt);
142             }
143             public void mouseClicked(java.awt.event.MouseEvent evt) {
144                 tabsMouseClicked(evt);
145             }
146         });
147 
148         nameLab.setText("Name:");
149 
150         servingLab.setText("Servings: ");
151 
152         methodsLab.setText("Method");
153 
154         methodsArea.setColumns(20);
155         methodsArea.setRows(5);
156         methodsScroll.setViewportView(methodsArea);
157 
158         submitBut.setText("Submit");
159         submitBut.addActionListener(new java.awt.event.ActionListener() {
160             public void actionPerformed(java.awt.event.ActionEvent evt) {
161                 submitButActionPerformed(evt);
162             }
163         });
164 
165         ingBut.setText("Add Ingredients");
166         ingBut.addActionListener(new java.awt.event.ActionListener() {
167             public void actionPerformed(java.awt.event.ActionEvent evt) {
168                 ingButActionPerformed(evt);
169             }
170         });
171 
172         jLabel1.setText("Selling Price");
173 
174         sellPrice.setText(" ");
175 
176         calLabel.setText("Calories");
177 
178         calBox.setText(" ");
179 
180         javax.swing.GroupLayout inputPanelLayout = new javax.swing.GroupLayout(inputPanel);
181         inputPanel.setLayout(inputPanelLayout);
182         inputPanelLayout.setHorizontalGroup(
183             inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184             .addGroup(inputPanelLayout.createSequentialGroup()
185                 .addContainerGap()
186                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187                     .addComponent(methodsScroll, javax.swing.GroupLayout.Alignment.TRAILING)
188                     .addGroup(inputPanelLayout.createSequentialGroup()
189                         .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
190                             .addGroup(inputPanelLayout.createSequentialGroup()
191                                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192                                     .addComponent(servingLab)
193                                     .addComponent(nameLab, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
194                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
195                                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
196                                     .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
197                                     .addComponent(servingField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
198                                 .addGap(41, 41, 41)
199                                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200                                     .addComponent(jLabel1)
201                                     .addComponent(sellPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
202                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
203                                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204                                     .addComponent(calLabel)
205                                     .addComponent(calBox, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
206                             .addGroup(inputPanelLayout.createSequentialGroup()
207                                 .addGap(304, 304, 304)
208                                 .addComponent(submitBut)
209                                 .addGap(0, 0, Short.MAX_VALUE)))
210                         .addContainerGap())))
211             .addGroup(inputPanelLayout.createSequentialGroup()
212                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
213                     .addGroup(inputPanelLayout.createSequentialGroup()
214                         .addGap(187, 187, 187)
215                         .addComponent(methodsLab))
216                     .addComponent(ingBut))
217                 .addGap(0, 217, Short.MAX_VALUE))
218         );
219         inputPanelLayout.setVerticalGroup(
220             inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221             .addGroup(inputPanelLayout.createSequentialGroup()
222                 .addGap(21, 21, 21)
223                 .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
224                     .addGroup(inputPanelLayout.createSequentialGroup()
225                         .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
226                             .addComponent(nameLab, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
227                             .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
228                             .addComponent(jLabel1))
229                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
230                         .addGroup(inputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
231                             .addComponent(servingLab)
232                             .addComponent(servingField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
233                             .addComponent(sellPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
234                     .addGroup(inputPanelLayout.createSequentialGroup()
235                         .addComponent(calLabel)
236                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
237                         .addComponent(calBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
238                 .addGap(18, 18, 18)
239                 .addComponent(methodsLab)
240                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
241                 .addComponent(methodsScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
242                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
243                 .addComponent(ingBut)
244                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
245                 .addComponent(submitBut)
246                 .addGap(50, 50, 50))
247         );
248 
249         tabs.addTab("Input Recipes", inputPanel);
250 
251         viewTable.setModel(new javax.swing.table.DefaultTableModel(
252             new Object [][] {
253                 {null, null, null, null},
254                 {null, null, null, null},
255                 {null, null, null, null},
256                 {null, null, null, null}
257             },
258             new String [] {
259                 "Title 1", "Title 2", "Title 3", "Title 4"
260             }
261         ));
262         viewTable.addMouseListener(new java.awt.event.MouseAdapter() {
263             public void mouseClicked(java.awt.event.MouseEvent evt) {
264                 viewTableMouseClicked(evt);
265             }
266         });
267         viewScroll.setViewportView(viewTable);
268 
269         detailsBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
270 
271         jLabel2.setText("Get Details:");
272 
273         detailsBut.setText("Details");
274         detailsBut.addActionListener(new java.awt.event.ActionListener() {
275             public void actionPerformed(java.awt.event.ActionEvent evt) {
276                 detailsButActionPerformed(evt);
277             }
278         });
279 
280         javax.swing.GroupLayout viewPanelLayout = new javax.swing.GroupLayout(viewPanel);
281         viewPanel.setLayout(viewPanelLayout);
282         viewPanelLayout.setHorizontalGroup(
283             viewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
284             .addGroup(viewPanelLayout.createSequentialGroup()
285                 .addContainerGap()
286                 .addGroup(viewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
287                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, viewPanelLayout.createSequentialGroup()
288                         .addGap(6, 6, 6)
289                         .addComponent(jLabel2)
290                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
291                         .addComponent(detailsBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
292                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
293                         .addComponent(detailsBut))
294                     .addComponent(viewScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE))
295                 .addContainerGap(15, Short.MAX_VALUE))
296         );
297         viewPanelLayout.setVerticalGroup(
298             viewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299             .addGroup(viewPanelLayout.createSequentialGroup()
300                 .addContainerGap()
301                 .addComponent(viewScroll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
302                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
303                 .addGroup(viewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
304                     .addComponent(detailsBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
305                     .addComponent(jLabel2)
306                     .addComponent(detailsBut))
307                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
308         );
309 
310         tabs.addTab("View Recipes", viewPanel);
311 
312         recipeBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Sample Recipe" }));
313         recipeBox.addMouseListener(new java.awt.event.MouseAdapter() {
314             public void mouseReleased(java.awt.event.MouseEvent evt) {
315                 recipeBoxMouseReleased(evt);
316             }
317         });
318 
319         costLab.setText("Cost:");
320 
321         profitLab.setText("Profit Margins:");
322 
323         convBut.setText("Convert");
324         convBut.addActionListener(new java.awt.event.ActionListener() {
325             public void actionPerformed(java.awt.event.ActionEvent evt) {
326                 convButActionPerformed(evt);
327             }
328         });
329 
330         calcBut.setText("Calculate");
331         calcBut.addActionListener(new java.awt.event.ActionListener() {
332             public void actionPerformed(java.awt.event.ActionEvent evt) {
333                 calcButActionPerformed(evt);
334             }
335         });
336 
337         jLabel3.setText("Enter Desired Servings:");
338 
339         javax.swing.GroupLayout calcPanelLayout = new javax.swing.GroupLayout(calcPanel);
340         calcPanel.setLayout(calcPanelLayout);
341         calcPanelLayout.setHorizontalGroup(
342             calcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
343             .addGroup(calcPanelLayout.createSequentialGroup()
344                 .addGroup(calcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
345                     .addGroup(calcPanelLayout.createSequentialGroup()
346                         .addComponent(recipeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
347                         .addGap(34, 34, 34)
348                         .addComponent(calcBut)
349                         .addGap(0, 163, Short.MAX_VALUE))
350                     .addGroup(calcPanelLayout.createSequentialGroup()
351                         .addContainerGap()
352                         .addGroup(calcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
353                             .addComponent(profitLab, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
354                             .addGroup(calcPanelLayout.createSequentialGroup()
355                                 .addGroup(calcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
356                                     .addComponent(costLab, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
357                                     .addComponent(convBut)
358                                     .addGroup(calcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
359                                         .addComponent(servConverter, javax.swing.GroupLayout.Alignment.LEADING)
360                                         .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
361                                 .addGap(0, 0, Short.MAX_VALUE)))))
362                 .addContainerGap())
363         );
364         calcPanelLayout.setVerticalGroup(
365             calcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
366             .addGroup(calcPanelLayout.createSequentialGroup()
367                 .addGap(19, 19, 19)
368                 .addGroup(calcPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
369                     .addComponent(recipeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
370                     .addComponent(calcBut))
371                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
372                 .addComponent(costLab)
373                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
374                 .addComponent(profitLab)
375                 .addGap(69, 69, 69)
376                 .addComponent(jLabel3)
377                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
378                 .addComponent(servConverter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
379                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
380                 .addComponent(convBut)
381                 .addContainerGap(211, Short.MAX_VALUE))
382         );
383 
384         tabs.addTab("Calculations", calcPanel);
385 
386         saveBut.setText("Save And Exit");
387         saveBut.addActionListener(new java.awt.event.ActionListener() {
388             public void actionPerformed(java.awt.event.ActionEvent evt) {
389                 saveButActionPerformed(evt);
390             }
391         });
392 
393         fileMenu.setMnemonic('f');
394         fileMenu.setText("File");
395 
396         exportRecipes.setMnemonic('o');
397         exportRecipes.setText("Export Recipes");
398         exportRecipes.addActionListener(new java.awt.event.ActionListener() {
399             public void actionPerformed(java.awt.event.ActionEvent evt) {
400                 exportRecipesActionPerformed(evt);
401             }
402         });
403         fileMenu.add(exportRecipes);
404 
405         exportMenu.setMnemonic('s');
406         exportMenu.setText("Export Menu");
407         exportMenu.addActionListener(new java.awt.event.ActionListener() {
408             public void actionPerformed(java.awt.event.ActionEvent evt) {
409                 exportMenuActionPerformed(evt);
410             }
411         });
412         fileMenu.add(exportMenu);
413 
414         menuBar.add(fileMenu);
415 
416         editMenu.setMnemonic('e');
417         editMenu.setText("Edit");
418 
419         cutMenuItem.setMnemonic('t');
420         cutMenuItem.setText("Cut");
421         editMenu.add(cutMenuItem);
422 
423         copyMenuItem.setMnemonic('y');
424         copyMenuItem.setText("Copy");
425         editMenu.add(copyMenuItem);
426 
427         pasteMenuItem.setMnemonic('p');
428         pasteMenuItem.setText("Paste");
429         editMenu.add(pasteMenuItem);
430 
431         deleteMenuItem.setMnemonic('d');
432         deleteMenuItem.setText("Delete");
433         editMenu.add(deleteMenuItem);
434 
435         menuBar.add(editMenu);
436 
437         helpMenu.setMnemonic('h');
438         helpMenu.setText("Help");
439 
440         contentsMenuItem.setMnemonic('c');
441         contentsMenuItem.setText("Contents");
442         helpMenu.add(contentsMenuItem);
443 
444         aboutMenuItem.setMnemonic('a');
445         aboutMenuItem.setText("About");
446         helpMenu.add(aboutMenuItem);
447 
448         menuBar.add(helpMenu);
449 
450         setJMenuBar(menuBar);
451 
452         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
453         getContentPane().setLayout(layout);
454         layout.setHorizontalGroup(
455             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
456             .addComponent(tabs)
457             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
458                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
459                 .addComponent(saveBut)
460                 .addGap(28, 28, 28))
461         );
462         layout.setVerticalGroup(
463             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
464             .addGroup(layout.createSequentialGroup()
465                 .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
466                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
467                 .addComponent(saveBut)
468                 .addContainerGap())
469         );
470 
471         pack();
472     }// </editor-fold>                        
473 
474     private void exportMenuActionPerformed(java.awt.event.ActionEvent evt) {                                           
475         // TODO add your handling code here:
476     }                                          
477 
478     private void exportRecipesActionPerformed(java.awt.event.ActionEvent evt) {                                              
479         // TODO add your handling code here:
480     }                                             
481 
482     private void convButActionPerformed(java.awt.event.ActionEvent evt) {                                        
483 int getDet=recipeBox.getSelectedIndex();
484 
485 
486        
487  double s= recipeList.get(getDet).getServings()*recipeList.get(getDet).getConversion(Double.parseDouble(servConverter.getText()));
488  String n= recipeList.get(getDet).getName();
489  double c=recipeList.get(getDet).getCost();
490  double cal=recipeList.get(getDet).getCalories();
491  
492  
493  String i="";
494  for (int z=0; z<recipeList.get(getDet).getIng().size();z++)
495  {
496      i+=recipeList.get(getDet).getIng().get(z).getIngName()+"     "+(recipeList.get(getDet).getIng().get(z).getQuantity()*recipeList.get(getDet).getConversion(Double.parseDouble(servConverter.getText())))+"    "+recipeList.get(getDet).getIng().get(z).getUnit()+"\n";
497  }
498  String m=recipeList.get(getDet).getMethod();
499 
500 
501  DetailsGUI dg = new DetailsGUI();
502  dg.setMethod(m);
503  dg.setName(n);
504  dg.setServings(s);
505  dg.setCalories(cal);
506  dg.setCost(c);
507  dg.setIngredients(i);
508  dg.setVisible(true);
509         // TODO add your handling code here:
510     }                                       
511 
512     private void ingButActionPerformed(java.awt.event.ActionEvent evt) {                                       
513         //Precondition: Ingredients havent been added
514         //Postcondition: Opens the ingredient builder
515         if(!hasSetIng)
516         {
517             recipeList.add(new Recipe());
518            currentPos++; 
519            hasSetIng=true;
520         }
521     
522                 IngredientsBuilder ib= new IngredientsBuilder(currentPos-1, recipeList);
523         ib.setVisible(true);
524         // TODO add your handling code here:
525     }                                      
526 
527     private void submitButActionPerformed(java.awt.event.ActionEvent evt) {                                          
528         //calories name price serving cost method ingredients
529         //Precondition: has filled in all attributes of a Recipe Object
530         //Add new recipe to the Recipe object and save to text file.
531         int calories;
532         String name=nameField.getText();
533         double price;
534 //         double servings=Double.parseDouble(servingField.getText());
535         double cost;//reliant on ing
536         String method= methodsArea.getText();
537 if(hasSetIng)//Series of If statemes error check to make sure the right data has been put in the right fields (no strings in doubles)
538 {
539     if(!nameField.getText().equals("")){
540         if(!servingField.getText().equals("")){
541             if(!servingField.getText().matches("[a-zA-Z]+")){
542                 if(!methodsArea.getText().equals("")){
543                      if(!sellPrice.getText().matches("[a-zA-Z]+"))
544             {
545                 recipeList.get(recipeList.size()-1).setPrice(Double.parseDouble(sellPrice.getText()));
546                 if(!calBox.getText().matches("[a-zA-Z]+"))
547             {
548                 
549                 recipeList.get(recipeList.size()-1).setCalories(Integer.parseInt(calBox.getText()));
550                 hasSetIng=false;
551     recipeList.get(recipeList.size()-1).setName(nameField.getText());
552         recipeList.get(recipeList.size()-1).setMethod(methodsArea.getText());
553             recipeList.get(recipeList.size()-1).setServings(Double.parseDouble(servingField.getText()));
554             nameField.setText("");
555             servingField.setText("");
556             methodsArea.setText("");
557             sellPrice.setText("");
558       calBox.setText("");
559             }
560       else
561                 JOptionPane.showMessageDialog(null, "Please only enter numbers in calories");
562             }
563       else
564                 JOptionPane.showMessageDialog(null, "Please only enter numbers in sell price");
565       
566     
567             
568                 }
569                 else
570                     JOptionPane.showMessageDialog(null, "Enter Method Please");
571             }
572             else
573                 JOptionPane.showMessageDialog(null, "Please only enter numbers in servings");
574         }
575         else
576             JOptionPane.showMessageDialog(null, "Enter Servings Please");
577     }
578     else
579         JOptionPane.showMessageDialog(null, "Enter Name Please");
580             
581    
582       
583 }
584 else
585     JOptionPane.showMessageDialog(null, "Enter ingredients please");
586 
587 
588         //   recipeList.add(new Recipe(ALLBITS, name, ERROR, HEIGHT, WIDTH, components, notes, ing))
589         // TODO add your handling code here:
590     }                                         
591 
592     private void tabsMouseClicked(java.awt.event.MouseEvent evt) {                                  
593 
594         // TODO add your handling code here:
595     }                                 
596 
597     private void tabsMouseReleased(java.awt.event.MouseEvent evt) {                                   
598   if(tabs.getSelectedIndex()==1)  
599   {
600     boxModel.removeAllElements();//reset the box
601       for(int count=0; count<recipeList.size();count++ ){
602       viewTable.setValueAt(recipeList.get(count).getName(), count, 0);//begin adding elements/parameters to their corresponding place
603         viewTable.setValueAt(recipeList.get(count).getServings(), count, 1);
604                 viewTable.setValueAt(recipeList.get(count).getCost(), count, 2);
605                      viewTable.setValueAt(recipeList.get(count).getCalories(), count, 3);
606                      
607                      boxModel.addElement(recipeList.get(count).getName());
608       }
609       detailsBox.setModel(boxModel);
610   }
611   if(tabs.getSelectedIndex()==2)
612   {
613         boxModel.removeAllElements();
614       for(int count=0; count<recipeList.size();count++ ){
615        boxModel.addElement(recipeList.get(count).getName());   
616       }
617       recipeBox.setModel(boxModel);//add new elelments to the recipe box
618   }
619         // TODO add your handling code here:
620     }                                  
621 
622     private void viewTableMouseClicked(java.awt.event.MouseEvent evt) {                                       
623 
624         // TODO add your handling code here:
625     }                                      
626 
627     private void detailsButActionPerformed(java.awt.event.ActionEvent evt) {                                           
628 int getDet=detailsBox.getSelectedIndex();
629 
630 
631         System.out.println(getDet);
632  double s= recipeList.get(getDet).getServings();//isolate the parameters
633  String n= recipeList.get(getDet).getName();
634  double c=recipeList.get(getDet).getCost();
635  double cal=recipeList.get(getDet).getCalories();
636  
637  
638  String i="";
639  for (int z=0; z<recipeList.get(getDet).getIng().size();z++)//reformat ingredients to be displayed
640  {
641      i+=recipeList.get(getDet).getIng().get(z).getIngName()+"     "+recipeList.get(getDet).getIng().get(z).getQuantity()+"    "+recipeList.get(getDet).getIng().get(z).getUnit()+"\n";
642  }
643  String m=recipeList.get(getDet).getMethod();
644 
645 
646  DetailsGUI dg = new DetailsGUI();//display recipe+details
647  dg.setMethod(m);
648  dg.setName(n);
649  dg.setServings(s);
650  dg.setCalories(cal);
651  dg.setCost(c);
652  dg.setIngredients(i);
653         dg.setVisible(true);
654 
655 
656         // TODO add your handling code here:
657     }                                          
658 
659     private void recipeBoxMouseReleased(java.awt.event.MouseEvent evt) {                                        
660         // TODO add your handling code here:
661     }                                       
662 
663     private void calcButActionPerformed(java.awt.event.ActionEvent evt) {                                        
664 costLab.setText("Cost: "+recipeList.get(recipeBox.getSelectedIndex()).getCost());
665 profitLab.setText("Profit Margins: "+recipeList.get(recipeBox.getSelectedIndex()).getPMargin());
666         // TODO add your handling code here:
667     }                                       
668 
669     private void saveButActionPerformed(java.awt.event.ActionEvent evt) {                                        
670 SaveLoad sl= new SaveLoad(recipeList);
671 sl.saveRecipes();
672         System.exit(0);
673         // TODO add your handling code here:
674     }                                       
675 
676     /**
677      * @param args the command line arguments
678      */
679     public static void main(String args[]) {
680         /* Set the Nimbus look and feel */
681         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
682         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
683          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
684          */
685         try {
686             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
687                 if ("Nimbus".equals(info.getName())) {
688                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
689                     break;
690                 }
691             }
692         } catch (ClassNotFoundException ex) {
693             java.util.logging.Logger.getLogger(GUIProto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
694         } catch (InstantiationException ex) {
695             java.util.logging.Logger.getLogger(GUIProto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
696         } catch (IllegalAccessException ex) {
697             java.util.logging.Logger.getLogger(GUIProto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
698         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
699             java.util.logging.Logger.getLogger(GUIProto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
700         }
701         //</editor-fold>
702 
703         /* Create and display the form */
704         java.awt.EventQueue.invokeLater(new Runnable() {
705             public void run() {
706                 new GUIProto().setVisible(true);
707             }
708         });
709     }
710 
711     // Variables declaration - do not modify                     
712     private javax.swing.JMenuItem aboutMenuItem;
713     private javax.swing.JTextField calBox;
714     private javax.swing.JLabel calLabel;
715     private javax.swing.JButton calcBut;
716     private javax.swing.JPanel calcPanel;
717     private javax.swing.JMenuItem contentsMenuItem;
718     private javax.swing.JButton convBut;
719     private javax.swing.JMenuItem copyMenuItem;
720     private javax.swing.JLabel costLab;
721     private javax.swing.JMenuItem cutMenuItem;
722     private javax.swing.JMenuItem deleteMenuItem;
723     private javax.swing.JComboBox<String> detailsBox;
724     private javax.swing.JButton detailsBut;
725     private javax.swing.JMenu editMenu;
726     private javax.swing.JMenuItem exportMenu;
727     private javax.swing.JMenuItem exportRecipes;
728     private javax.swing.JMenu fileMenu;
729     private javax.swing.JMenu helpMenu;
730     private javax.swing.JButton ingBut;
731     private javax.swing.ButtonGroup ingGroup;
732     private javax.swing.JPanel inputPanel;
733     private javax.swing.JLabel jLabel1;
734     private javax.swing.JLabel jLabel2;
735     private javax.swing.JLabel jLabel3;
736     private javax.swing.JMenuBar menuBar;
737     private javax.swing.JTextArea methodsArea;
738     private javax.swing.JLabel methodsLab;
739     private javax.swing.JScrollPane methodsScroll;
740     private javax.swing.JTextField nameField;
741     private javax.swing.JLabel nameLab;
742     private javax.swing.JMenuItem pasteMenuItem;
743     private javax.swing.JLabel profitLab;
744     private javax.swing.JComboBox<String> recipeBox;
745     private javax.swing.JButton saveBut;
746     private javax.swing.JTextField sellPrice;
747     private javax.swing.JTextField servConverter;
748     private javax.swing.JTextField servingField;
749     private javax.swing.JLabel servingLab;
750     private javax.swing.JButton submitBut;
751     private javax.swing.JTabbedPane tabs;
752     private javax.swing.JPanel viewPanel;
753     private javax.swing.JScrollPane viewScroll;
754     private javax.swing.JTable viewTable;
755     // End of variables declaration                   
756 ArrayList<Recipe> recipeList= new ArrayList<>();
757     DefaultListModel setIngModel=new DefaultListModel();
758     DefaultComboBoxModel<String> boxModel=new DefaultComboBoxModel<>();
759     int numRecipes=0;
760     boolean hasSetIng=false;
761     int currentPos=recipeList.size();
762 }
763