/*
 * Decompiled with CFR 0_123.
 */
package com.zakscode.FormulaManager;

import com.zakscode.FormulaManager.Component;
import com.zakscode.FormulaManager.ComponentQuantity;
import com.zakscode.FormulaManager.Configuration;
import com.zakscode.FormulaManager.Export;
import com.zakscode.FormulaManager.FTPManager;
import com.zakscode.FormulaManager.FileManager;
import com.zakscode.FormulaManager.Formula;
import com.zakscode.FormulaManager.Main;
import com.zakscode.FormulaManager.Vendor;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.RowSorter;
import javax.swing.SpringLayout;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import javax.swing.text.Document;

class Frame
extends JFrame {
    private final JFrame frame;
    private static final long serialVersionUID = 4919234897555589295L;
    private JTable table;
    private DefaultTableModel dtm;
    private final JRadioButtonMenuItem viewVendor;
    private final JRadioButtonMenuItem viewComponent;
    private final JRadioButtonMenuItem viewFormula;
    private final JRadioButtonMenuItem viewUserVendor;
    private final JRadioButtonMenuItem viewUserComponent;
    private final JRadioButtonMenuItem viewUserFormula;

    public Frame(int resX, int resY) {
        super("Formula Manager");
        this.frame = this;
        this.setSize(resX, resY);
        this.setLocationRelativeTo(null);
        this.setIconImage(Main.icon.getImage());
        UIManager.put("TextField.background", Color.WHITE);
        UIManager.put("TextField.foreground", Color.BLACK);
        UIManager.put("TextField.disabledBackground", Color.WHITE);
        UIManager.put("TextField.disabledForeground", Color.BLACK);
        UIManager.put("TextArea.background", Color.WHITE);
        UIManager.put("TextArea.foreground", Color.BLACK);
        UIManager.put("TextArea.disabledBackground", Color.WHITE);
        UIManager.put("TextArea.disabledForeground", Color.BLACK);
        UIManager.put("ComboBox.background", Color.WHITE);
        UIManager.put("ComboBox.foreground", Color.BLACK);
        UIManager.put("ComboBox.disabledBackground", Color.WHITE);
        UIManager.put("ComboBox.disabledForeground", Color.BLACK);
        JMenuBar menuBar = new JMenuBar();
        JMenu viewMenu = new JMenu("View");
        ButtonGroup bg = new ButtonGroup();
        this.viewVendor = new JRadioButtonMenuItem(new AbstractAction("Vendors"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Object[][] rowData = Main.vendors.toArray();
                Object[] columnNames = new Object[]{"Name", "Phone", "Email", "Website", "Date"};
                Frame.this.dtm = new DefaultTableModel(rowData, columnNames);
                Frame.this.table.setModel(Frame.this.dtm);
                Frame.this.table.getRowSorter().toggleSortOrder(0);
            }
        });
        bg.add(this.viewVendor);
        viewMenu.add(this.viewVendor);
        this.viewComponent = new JRadioButtonMenuItem(new AbstractAction("Components"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Object[][] rowData = Main.components.toArray();
                Object[] arrobject = new Object[5];
                arrobject[0] = "Part Number";
                arrobject[1] = "Vendor";
                arrobject[2] = "Description";
                arrobject[3] = "Cost (per " + (Main.metric ? "kg" : "lb") + "): ";
                arrobject[4] = "Date";
                Object[] columnNames = arrobject;
                Frame.this.dtm = new DefaultTableModel(rowData, columnNames);
                Frame.this.table.setModel(Frame.this.dtm);
                DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
                rightRenderer.setHorizontalAlignment(4);
                Frame.this.table.getColumnModel().getColumn(3).setCellRenderer(rightRenderer);
                Frame.this.table.getRowSorter().toggleSortOrder(0);
            }
        });
        bg.add(this.viewComponent);
        viewMenu.add(this.viewComponent);
        this.viewFormula = new JRadioButtonMenuItem(new AbstractAction("Formulas"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Object[][] rowData = Main.formulas.toArray();
                Object[] columnNames = new Object[]{"Name", "Description", "Date", "Apr/Rej", "Apr/Rej Date"};
                Frame.this.dtm = new DefaultTableModel(rowData, columnNames);
                Frame.this.table.setModel(Frame.this.dtm);
                DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
                rightRenderer.setHorizontalAlignment(0);
                Frame.this.table.getColumnModel().getColumn(3).setCellRenderer(rightRenderer);
                Frame.this.table.getRowSorter().toggleSortOrder(0);
            }
        });
        bg.add(this.viewFormula);
        this.viewFormula.setSelected(true);
        viewMenu.add(this.viewFormula);
        viewMenu.addSeparator();
        this.viewUserVendor = new JRadioButtonMenuItem(new AbstractAction("User Vendors"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Object[][] rowData = Main.userVendors.toArray();
                Object[] columnNames = new Object[]{"Name", "Phone", "Email", "Website", "Date"};
                Frame.this.dtm = new DefaultTableModel(rowData, columnNames);
                Frame.this.table.setModel(Frame.this.dtm);
                Frame.this.table.getRowSorter().toggleSortOrder(0);
            }
        });
        bg.add(this.viewUserVendor);
        viewMenu.add(this.viewUserVendor);
        this.viewUserComponent = new JRadioButtonMenuItem(new AbstractAction("User Components"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Object[][] rowData = Main.userComponents.toArray();
                Object[] arrobject = new Object[5];
                arrobject[0] = "Part Number";
                arrobject[1] = "Vendor";
                arrobject[2] = "Description";
                arrobject[3] = "Cost (per " + (Main.metric ? "kg" : "lb") + "): ";
                arrobject[4] = "Date";
                Object[] columnNames = arrobject;
                Frame.this.dtm = new DefaultTableModel(rowData, columnNames);
                Frame.this.table.setModel(Frame.this.dtm);
                DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
                rightRenderer.setHorizontalAlignment(4);
                Frame.this.table.getColumnModel().getColumn(3).setCellRenderer(rightRenderer);
                Frame.this.table.getRowSorter().toggleSortOrder(0);
            }
        });
        bg.add(this.viewUserComponent);
        viewMenu.add(this.viewUserComponent);
        this.viewUserFormula = new JRadioButtonMenuItem(new AbstractAction("User Formulas"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Object[][] rowData = Main.userFormulas.toArray();
                Object[] columnNames = new Object[]{"Name", "Description", "Date", "Apr/Rej", "Apr/Rej Date"};
                Frame.this.dtm = new DefaultTableModel(rowData, columnNames);
                Frame.this.table.setModel(Frame.this.dtm);
                DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
                rightRenderer.setHorizontalAlignment(0);
                Frame.this.table.getColumnModel().getColumn(3).setCellRenderer(rightRenderer);
                Frame.this.table.getRowSorter().toggleSortOrder(0);
            }
        });
        bg.add(this.viewUserFormula);
        viewMenu.add(this.viewUserFormula);
        JMenu fileMenu = new JMenu("File");
        menuBar.add(fileMenu);
        JMenu newMenu = new JMenu("New");
        fileMenu.add(newMenu);
        JMenuItem newWindow = new JMenuItem(new AbstractAction("Window"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                Main.newWindow();
            }
        });
        newWindow.setAccelerator(KeyStroke.getKeyStroke(78, 2));
        newMenu.add(newWindow);
        newMenu.addSeparator();
        JMenuItem newVendor = new JMenuItem(new AbstractAction("Vendor"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                Frame.this.vendorEditor();
            }
        });
        newVendor.setAccelerator(KeyStroke.getKeyStroke(72, 2));
        newMenu.add(newVendor);
        JMenuItem newComponent = new JMenuItem(new AbstractAction("Component"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                Frame.this.componentEditor();
            }
        });
        newComponent.setAccelerator(KeyStroke.getKeyStroke(71, 2));
        newMenu.add(newComponent);
        JMenuItem newFormula = new JMenuItem(new AbstractAction("Formula"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                Frame.this.formulaEditor();
            }
        });
        newFormula.setAccelerator(KeyStroke.getKeyStroke(70, 2));
        newMenu.add(newFormula);
        fileMenu.addSeparator();
        JMenuItem update = new JMenuItem(new AbstractAction("Update"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Main.downloadData(false, true);
                Frame.this.reloadView();
            }
        });
        fileMenu.add(update);
        JMenuItem upload = new JMenuItem(new AbstractAction("Upload"){

            @Override
            public void actionPerformed(ActionEvent e) {
                FTPManager ftp = new FTPManager(Main.conf.getProperty("URL"), Integer.parseInt(Main.conf.getProperty("port")), Main.conf.getProperty("username"), Main.conf.getProperty("password"));
                ftp.writeFiles();
            }
        });
        fileMenu.add(upload);
        fileMenu.addSeparator();
        JMenuItem print = new JMenuItem(new AbstractAction("Print"){

            @Override
            public void actionPerformed(ActionEvent e) {
                if (Frame.this.viewVendor.isSelected()) {
                    Export.printPDF(Export.HTMLToPDF(Export.vendorsToHTML(Main.vendors)));
                } else if (Frame.this.viewUserVendor.isSelected()) {
                    Export.printPDF(Export.HTMLToPDF(Export.vendorsToHTML(Main.userVendors)));
                } else if (Frame.this.viewComponent.isSelected()) {
                    Export.printPDF(Export.HTMLToPDF(Export.componentsToHTML(Main.components)));
                } else if (Frame.this.viewUserComponent.isSelected()) {
                    Export.printPDF(Export.HTMLToPDF(Export.componentsToHTML(Main.userComponents)));
                } else if (Frame.this.viewFormula.isSelected()) {
                    Export.printPDF(Export.HTMLToPDF(Export.formulasToHTML(Main.formulas)));
                } else if (Frame.this.viewUserFormula.isSelected()) {
                    Export.printPDF(Export.HTMLToPDF(Export.formulasToHTML(Main.userFormulas)));
                }
            }
        });
        fileMenu.add(print);
        fileMenu.addSeparator();
        JMenuItem exit = new JMenuItem(new AbstractAction("Exit"){

            @Override
            public void actionPerformed(ActionEvent e) {
                Main.close(Frame.this.frame);
            }
        });
        fileMenu.add(exit);
        JMenu editMenu = new JMenu("Edit");
        final JCheckBoxMenuItem editMetric = new JCheckBoxMenuItem("Metric");
        editMetric.setSelected(Main.metric);
        editMenu.add(editMetric);
        editMetric.addActionListener(new AbstractAction(){

            @Override
            public void actionPerformed(ActionEvent e) {
                Main.metric = editMetric.isSelected();
                Frame.this.reloadView();
            }
        });
        final JCheckBoxMenuItem editLargeUnits = new JCheckBoxMenuItem("kg/lb");
        editLargeUnits.setSelected(Main.largeUnits);
        editLargeUnits.addActionListener(new AbstractAction(){

            @Override
            public void actionPerformed(ActionEvent e) {
                Main.largeUnits = editLargeUnits.isSelected();
                Frame.this.reloadView();
            }
        });
        editMenu.add(editLargeUnits);
        editMenu.addSeparator();
        if (Boolean.parseBoolean(Main.conf.getProperty("allow-publish"))) {
            JMenuItem editPublish = new JMenuItem("Publish Item");
            editPublish.addActionListener(new AbstractAction(){

                @Override
                public void actionPerformed(ActionEvent e) {
                    int[] lines = Frame.this.table.getSelectedRows();
                    if (lines.length > 0) {
                        int i;
                        for (i = 0; i < lines.length; ++i) {
                            lines[i] = Frame.this.table.convertRowIndexToModel(lines[i]);
                        }
                        Arrays.sort(lines);
                        if (Frame.this.viewUserVendor.isSelected()) {
                            for (i = lines.length - 1; i >= 0; --i) {
                                Main.vendors.put(Frame.this.dtm.getValueAt(lines[i], 0).toString(), Main.userVendors.get(Frame.this.dtm.getValueAt(lines[i], 0)));
                            }
                        } else if (Frame.this.viewUserComponent.isSelected()) {
                            for (i = lines.length - 1; i >= 0; --i) {
                                Main.components.put(Frame.this.dtm.getValueAt(lines[i], 0).toString(), Main.userComponents.get(Frame.this.dtm.getValueAt(lines[i], 0)));
                            }
                        } else if (Frame.this.viewUserFormula.isSelected()) {
                            for (i = lines.length - 1; i >= 0; --i) {
                                Main.formulas.put(Frame.this.dtm.getValueAt(lines[i], 0).toString(), Main.userFormulas.get(Frame.this.dtm.getValueAt(lines[i], 0)));
                            }
                        }
                    }
                    Main.saveAll();
                }
            });
            editMenu.add(editPublish);
            editMenu.addSeparator();
        }
        final JCheckBoxMenuItem editItem = new JCheckBoxMenuItem("Edit Item");
        editItem.addActionListener(new AbstractAction(){

            @Override
            public void actionPerformed(ActionEvent e) {
                if (editItem.isSelected()) {
                    for (int i = 0; i < Frame.this.dtm.getRowCount(); ++i) {
                        if (Frame.this.viewVendor.isSelected()) {
                            Main.vendors.put(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), new Vendor(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), String.valueOf(Frame.this.dtm.getValueAt(i, 1)), String.valueOf(Frame.this.dtm.getValueAt(i, 2)), String.valueOf(Frame.this.dtm.getValueAt(i, 3))));
                            continue;
                        }
                        if (Frame.this.viewUserVendor.isSelected()) {
                            Main.userVendors.put(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), new Vendor(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), String.valueOf(Frame.this.dtm.getValueAt(i, 1)), String.valueOf(Frame.this.dtm.getValueAt(i, 2)), String.valueOf(Frame.this.dtm.getValueAt(i, 3))));
                            continue;
                        }
                        if (Frame.this.viewComponent.isSelected()) {
                            Main.components.put(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), new Component(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), String.valueOf(Frame.this.dtm.getValueAt(i, 1)), String.valueOf(Frame.this.dtm.getValueAt(i, 2)), Double.parseDouble(String.valueOf(Frame.this.dtm.getValueAt(i, 3)).substring(1))));
                            continue;
                        }
                        if (Frame.this.viewUserComponent.isSelected()) {
                            Main.userComponents.put(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), new Component(String.valueOf(Frame.this.dtm.getValueAt(i, 0)), String.valueOf(Frame.this.dtm.getValueAt(i, 1)), String.valueOf(Frame.this.dtm.getValueAt(i, 2)), Double.parseDouble(String.valueOf(Frame.this.dtm.getValueAt(i, 3)).substring(1))));
                            continue;
                        }
                        if (Frame.this.viewFormula.isSelected()) {
                            ((Formula)Main.formulas.get(String.valueOf(Frame.this.dtm.getValueAt(i, 0)))).setName(String.valueOf(Frame.this.dtm.getValueAt(i, 0)));
                            ((Formula)Main.formulas.get(String.valueOf(Frame.this.dtm.getValueAt(i, 0)))).setDescription(String.valueOf(Frame.this.dtm.getValueAt(i, 1)));
                            continue;
                        }
                        if (!Frame.this.viewUserFormula.isSelected()) continue;
                        ((Formula)Main.userFormulas.get(String.valueOf(Frame.this.dtm.getValueAt(i, 0)))).setName(String.valueOf(Frame.this.dtm.getValueAt(i, 0)));
                        ((Formula)Main.userFormulas.get(String.valueOf(Frame.this.dtm.getValueAt(i, 0)))).setDescription(String.valueOf(Frame.this.dtm.getValueAt(i, 1)));
                    }
                }
                Main.saveAll();
            }
        });
        editItem.setAccelerator(KeyStroke.getKeyStroke(69, 2));
        editMenu.add(editItem);
        JMenuItem editCopy = new JMenuItem(new AbstractAction("Copy Item"){

            @Override
            public void actionPerformed(ActionEvent e) {
                int[] lines = Frame.this.table.getSelectedRows();
                if (lines.length > 0) {
                    int i;
                    for (i = 0; i < lines.length; ++i) {
                        lines[i] = Frame.this.table.convertRowIndexToModel(lines[i]);
                    }
                    Arrays.sort(lines);
                    for (i = lines.length - 1; i >= 0; --i) {
                        if (Frame.this.viewVendor.isSelected()) {
                            Frame.this.vendorEditor((Vendor)Main.vendors.get(Frame.this.dtm.getValueAt(lines[i], 0).toString()), true);
                            continue;
                        }
                        if (Frame.this.viewUserVendor.isSelected()) {
                            Frame.this.vendorEditor((Vendor)Main.userVendors.get(Frame.this.dtm.getValueAt(lines[i], 0).toString()), true);
                            continue;
                        }
                        if (Frame.this.viewComponent.isSelected()) {
                            Frame.this.componentEditor((Component)Main.components.get(Frame.this.dtm.getValueAt(lines[i], 0).toString()), true);
                            continue;
                        }
                        if (Frame.this.viewUserComponent.isSelected()) {
                            Frame.this.componentEditor((Component)Main.userComponents.get(Frame.this.dtm.getValueAt(lines[i], 0).toString()), true);
                            continue;
                        }
                        if (Frame.this.viewFormula.isSelected()) {
                            Frame.this.formulaEditor((Formula)Main.formulas.get(Frame.this.dtm.getValueAt(lines[i], 0).toString()), true);
                            continue;
                        }
                        if (!Frame.this.viewUserFormula.isSelected()) continue;
                        Frame.this.formulaEditor((Formula)Main.userFormulas.get(Frame.this.dtm.getValueAt(lines[i], 0).toString()), true);
                    }
                }
            }
        });
        editCopy.setAccelerator(KeyStroke.getKeyStroke(67, 2));
        editMenu.add(editCopy);
        JMenuItem editDel = new JMenuItem(new AbstractAction("Delete Item"){

            @Override
            public void actionPerformed(ActionEvent e) {
                int[] lines = Frame.this.table.getSelectedRows();
                if (lines.length > 0) {
                    int i;
                    for (i = 0; i < lines.length; ++i) {
                        lines[i] = Frame.this.table.convertRowIndexToModel(lines[i]);
                    }
                    Arrays.sort(lines);
                    if (Frame.this.viewVendor.isSelected()) {
                        for (i = lines.length - 1; i >= 0; --i) {
                            int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete: " + Frame.this.dtm.getValueAt(lines[i], 0), "Confirm Delete", 0, 2);
                            if (option != 0) continue;
                            Main.vendors.remove(Frame.this.dtm.getValueAt(lines[i], 0));
                            Frame.this.dtm.removeRow(lines[i]);
                        }
                    } else if (Frame.this.viewUserVendor.isSelected()) {
                        for (i = lines.length - 1; i >= 0; --i) {
                            int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete: " + Frame.this.dtm.getValueAt(lines[i], 0), "Confirm Delete", 0, 2);
                            if (option != 0) continue;
                            Main.userVendors.remove(Frame.this.dtm.getValueAt(lines[i], 0));
                            Frame.this.dtm.removeRow(lines[i]);
                        }
                    } else if (Frame.this.viewComponent.isSelected()) {
                        for (i = lines.length - 1; i >= 0; --i) {
                            int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete: " + Frame.this.dtm.getValueAt(lines[i], 0), "Confirm Delete", 0, 2);
                            if (option != 0) continue;
                            Main.components.remove(Frame.this.dtm.getValueAt(lines[i], 0));
                            Frame.this.dtm.removeRow(lines[i]);
                        }
                    } else if (Frame.this.viewUserComponent.isSelected()) {
                        for (i = lines.length - 1; i >= 0; --i) {
                            int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete: " + Frame.this.dtm.getValueAt(lines[i], 0), "Confirm Delete", 0, 2);
                            if (option != 0) continue;
                            Main.userComponents.remove(Frame.this.dtm.getValueAt(lines[i], 0));
                            Frame.this.dtm.removeRow(lines[i]);
                        }
                    } else if (Frame.this.viewFormula.isSelected()) {
                        for (i = lines.length - 1; i >= 0; --i) {
                            int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete: " + Frame.this.dtm.getValueAt(lines[i], 0), "Confirm Delete", 0, 2);
                            if (option != 0) continue;
                            Main.formulas.remove(Frame.this.dtm.getValueAt(lines[i], 0));
                            Frame.this.dtm.removeRow(lines[i]);
                        }
                    } else if (Frame.this.viewUserFormula.isSelected()) {
                        for (i = lines.length - 1; i >= 0; --i) {
                            int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete: " + Frame.this.dtm.getValueAt(lines[i], 0), "Confirm Delete", 0, 2);
                            if (option != 0) continue;
                            Main.userFormulas.remove(Frame.this.dtm.getValueAt(lines[i], 0));
                            Frame.this.dtm.removeRow(lines[i]);
                        }
                    }
                }
                Main.saveAll();
                Frame.this.reloadView();
            }
        });
        editDel.setAccelerator(KeyStroke.getKeyStroke(68, 2));
        editMenu.add(editDel);
        menuBar.add(editMenu);
        menuBar.add(viewMenu);
        JMenu helpMenu = new JMenu("Help");
        JMenuItem about = new JMenuItem("About");
        about.addActionListener(new AbstractAction(){

            @Override
            public void actionPerformed(ActionEvent e) {
                JFrame aboutFrame = new JFrame("About");
                aboutFrame.setLocationRelativeTo(null);
                aboutFrame.setIconImage(Main.icon.getImage());
                aboutFrame.setDefaultCloseOperation(2);
                aboutFrame.add(new JLabel(new ImageIcon(Main.baseDir + "splash.png")));
                aboutFrame.pack();
                aboutFrame.setVisible(true);
            }
        });
        helpMenu.add(about);
        menuBar.add(helpMenu);
        final JTextField searchBar = new JTextField("Search...");
        searchBar.addFocusListener(new FocusListener(){

            @Override
            public void focusGained(FocusEvent e) {
                if (searchBar.getText().equals("Search...")) {
                    searchBar.setText("");
                }
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (searchBar.getText().length() == 0) {
                    searchBar.setText("Search...");
                }
            }
        });
        searchBar.setPreferredSize(new Dimension(200, 20));
        searchBar.setMaximumSize(new Dimension(200, 20));
        menuBar.add(Box.createHorizontalGlue());
        menuBar.add(searchBar);
        this.setJMenuBar(menuBar);
        this.table = new JTable(){

            @Override
            public boolean isCellEditable(int row, int column) {
                return !(Frame.this.viewUserComponent.isSelected() && column == 2 || Frame.this.viewComponent.isSelected() && column == 2 || !editItem.isSelected());
            }
        };
        this.table.setFillsViewportHeight(true);
        this.table.setAutoCreateRowSorter(true);
        JScrollPane scrollPane = new JScrollPane(this.table);
        this.table.addMouseListener(new MouseAdapter(){

            @Override
            public void mousePressed(MouseEvent me) {
                JTable table = (JTable)me.getSource();
                Point p = me.getPoint();
                try {
                    int row = table.convertRowIndexToModel(table.rowAtPoint(p));
                    if (me.getClickCount() == 2 && !editItem.isSelected()) {
                        if (Frame.this.viewVendor.isSelected()) {
                            Frame.this.vendorEditor((Vendor)Main.vendors.get(Frame.this.dtm.getValueAt(row, 0)), false);
                        } else if (Frame.this.viewUserVendor.isSelected()) {
                            Frame.this.vendorEditor((Vendor)Main.userVendors.get(Frame.this.dtm.getValueAt(row, 0)), false);
                        } else if (Frame.this.viewComponent.isSelected()) {
                            Frame.this.componentEditor((Component)Main.components.get(Frame.this.dtm.getValueAt(row, 0)), false);
                        } else if (Frame.this.viewUserComponent.isSelected()) {
                            Frame.this.componentEditor((Component)Main.userComponents.get(Frame.this.dtm.getValueAt(row, 0)), false);
                        } else if (Frame.this.viewFormula.isSelected()) {
                            Frame.this.formulaEditor((Formula)Main.formulas.get(Frame.this.dtm.getValueAt(row, 0)), false);
                        } else if (Frame.this.viewUserFormula.isSelected()) {
                            Frame.this.formulaEditor((Formula)Main.userFormulas.get(Frame.this.dtm.getValueAt(row, 0)), false);
                        }
                    }
                }
                catch (Exception exception) {
                    // empty catch block
                }
            }
        });
        this.add(scrollPane);
        searchBar.getDocument().addDocumentListener(new DocumentListener(){

            @Override
            public void changedUpdate(DocumentEvent e) {
                this.updated();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                this.updated();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                this.updated();
            }

            public void updated() {
                if (searchBar.hasFocus() && searchBar.getText().length() > 0) {
                    for (int i = Frame.access$000((Frame)Frame.this).getRowCount() - 1; i >= 0; --i) {
                        Frame.this.dtm.removeRow(i);
                    }
                    if (Frame.this.viewVendor.isSelected()) {
                        Main.vendors.keySet().stream().filter(arg_0 -> .lambda$updated$0(searchBar, arg_0)).forEach(key -> {
                            Frame.this.dtm.addRow(((Vendor)Main.vendors.get(key)).toArray());
                        }
                        );
                    } else if (Frame.this.viewUserVendor.isSelected()) {
                        Main.userVendors.keySet().stream().filter(arg_0 -> .lambda$updated$2(searchBar, arg_0)).forEach(key -> {
                            Frame.this.dtm.addRow(((Vendor)Main.userVendors.get(key)).toArray());
                        }
                        );
                    } else if (Frame.this.viewComponent.isSelected()) {
                        Main.components.keySet().stream().filter(arg_0 -> .lambda$updated$4(searchBar, arg_0)).forEach(key -> {
                            Frame.this.dtm.addRow(((Component)Main.components.get(key)).toArray());
                        }
                        );
                    } else if (Frame.this.viewUserComponent.isSelected()) {
                        Main.userComponents.keySet().stream().filter(arg_0 -> .lambda$updated$6(searchBar, arg_0)).forEach(key -> {
                            Frame.this.dtm.addRow(((Component)Main.userComponents.get(key)).toArray());
                        }
                        );
                    } else if (Frame.this.viewFormula.isSelected()) {
                        Main.formulas.keySet().stream().filter(arg_0 -> .lambda$updated$8(searchBar, arg_0)).forEach(key -> {
                            Frame.this.dtm.addRow(((Formula)Main.formulas.get(key)).toArray());
                        }
                        );
                    } else if (Frame.this.viewUserFormula.isSelected()) {
                        Main.userFormulas.keySet().stream().filter(arg_0 -> .lambda$updated$10(searchBar, arg_0)).forEach(key -> {
                            Frame.this.dtm.addRow(((Formula)Main.userFormulas.get(key)).toArray());
                        }
                        );
                    }
                } else {
                    Frame.this.reloadView();
                }
            }

            private static /* synthetic */ boolean lambda$updated$10(JTextField searchBar2, String key) {
                return key.toLowerCase().contains(searchBar2.getText());
            }

            private static /* synthetic */ boolean lambda$updated$8(JTextField searchBar2, String key) {
                return key.toLowerCase().contains(searchBar2.getText());
            }

            private static /* synthetic */ boolean lambda$updated$6(JTextField searchBar2, String key) {
                return key.toLowerCase().contains(searchBar2.getText());
            }

            private static /* synthetic */ boolean lambda$updated$4(JTextField searchBar2, String key) {
                return key.toLowerCase().contains(searchBar2.getText());
            }

            private static /* synthetic */ boolean lambda$updated$2(JTextField searchBar2, String key) {
                return key.toLowerCase().contains(searchBar2.getText());
            }

            private static /* synthetic */ boolean lambda$updated$0(JTextField searchBar2, String key) {
                return key.toLowerCase().contains(searchBar2.getText());
            }
        });
        this.setVisible(true);
        this.viewFormula.doClick();
        this.addWindowListener(new WindowAdapter(){

            @Override
            public void windowClosing(WindowEvent e) {
                Main.close(Frame.this.frame);
            }
        });
        this.requestFocus();
    }

    private void vendorEditor() {
        this.vendorEditor(null, true);
    }

    private void vendorEditor(final Vendor v, final boolean edit) {
        final JFrame editor = new JFrame(v != null ? v.getName() : "New Vendor");
        editor.setSize(400, 207);
        editor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 207));
        editor.setIconImage(Main.icon.getImage());
        editor.setLocationRelativeTo(null);
        Container contentPane = editor.getContentPane();
        SpringLayout layout = new SpringLayout();
        contentPane.setLayout(layout);
        JLabel nameLabel = new JLabel("Name: ", 4);
        contentPane.add(nameLabel);
        layout.putConstraint("West", (java.awt.Component)nameLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)nameLabel, 5, "North", (java.awt.Component)contentPane);
        final JTextField nameField = new JTextField(v != null ? v.getName() : null, 15);
        nameField.setEditable(edit);
        nameField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
        contentPane.add(nameField);
        layout.putConstraint("West", (java.awt.Component)nameField, 5, "East", (java.awt.Component)nameLabel);
        layout.putConstraint("North", (java.awt.Component)nameField, 5, "North", (java.awt.Component)contentPane);
        JLabel phoneLabel = new JLabel("Phone: ", 4);
        contentPane.add(phoneLabel);
        layout.putConstraint("West", (java.awt.Component)phoneLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)phoneLabel, 5, "South", (java.awt.Component)nameField);
        final JTextField phoneField = new JTextField(v != null ? v.getPhone() : null);
        phoneField.setEditable(edit);
        phoneField.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(phoneField);
        layout.putConstraint("West", (java.awt.Component)phoneField, 0, "West", (java.awt.Component)nameField);
        layout.putConstraint("East", (java.awt.Component)phoneField, 0, "East", (java.awt.Component)nameField);
        layout.putConstraint("North", (java.awt.Component)phoneField, 5, "South", (java.awt.Component)nameField);
        JLabel emailLabel = new JLabel("Email: ", 4);
        contentPane.add(emailLabel);
        layout.putConstraint("West", (java.awt.Component)emailLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)emailLabel, 5, "South", (java.awt.Component)phoneField);
        final JTextField emailField = new JTextField(v != null ? v.getEmail() : null);
        emailField.setEditable(edit);
        emailField.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(emailField);
        layout.putConstraint("West", (java.awt.Component)emailField, 0, "West", (java.awt.Component)nameField);
        layout.putConstraint("East", (java.awt.Component)emailField, 0, "East", (java.awt.Component)nameField);
        layout.putConstraint("North", (java.awt.Component)emailField, 5, "South", (java.awt.Component)phoneField);
        JLabel websiteLabel = new JLabel("Website: ", 4);
        contentPane.add(websiteLabel);
        layout.putConstraint("West", (java.awt.Component)websiteLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)websiteLabel, 5, "South", (java.awt.Component)emailField);
        final JTextField websiteField = new JTextField(v != null ? v.getWebsite() : null);
        websiteField.setEditable(edit);
        websiteField.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(websiteField);
        layout.putConstraint("West", (java.awt.Component)websiteField, 5, "East", (java.awt.Component)websiteLabel);
        layout.putConstraint("East", (java.awt.Component)websiteField, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)websiteField, 5, "South", (java.awt.Component)emailField);
        JButton saveButton = new JButton(new AbstractAction(edit ? "Save" : "Edit"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (!edit) {
                    editor.dispose();
                    Frame.this.vendorEditor(v, true);
                } else {
                    Main.userVendors.put(nameField.getText(), new Vendor(nameField.getText(), phoneField.getText(), emailField.getText(), websiteField.getText()));
                    Main.saveAll();
                }
                editor.dispose();
                Frame.this.reloadView();
            }
        });
        saveButton.setMaximumSize(new Dimension(editor.getWidth(), 20));
        editor.getRootPane().setDefaultButton(saveButton);
        contentPane.add(saveButton);
        layout.putConstraint("West", (java.awt.Component)saveButton, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)saveButton, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)saveButton, 5, "South", (java.awt.Component)websiteField);
        JButton cancelButton = new JButton(new AbstractAction(edit ? "Cancel" : "Close"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                editor.dispose();
            }
        });
        cancelButton.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(cancelButton);
        layout.putConstraint("West", (java.awt.Component)cancelButton, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)cancelButton, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)cancelButton, 5, "South", (java.awt.Component)saveButton);
        layout.putConstraint("East", (java.awt.Component)contentPane, 5, "East", (java.awt.Component)nameField);
        editor.setVisible(true);
    }

    private void componentEditor() {
        this.componentEditor(null, true);
    }

    private void componentEditor(final Component c, final boolean edit) {
        final JFrame editor = new JFrame(c != null ? c.getPartNum() : "New Component");
        editor.setSize(400, 260);
        editor.setIconImage(Main.icon.getImage());
        editor.setLocationRelativeTo(null);
        Container contentPane = editor.getContentPane();
        SpringLayout layout = new SpringLayout();
        contentPane.setLayout(layout);
        JLabel partLabel = new JLabel("Part Number: ", 4);
        contentPane.add(partLabel);
        layout.putConstraint("West", (java.awt.Component)partLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)partLabel, 5, "North", (java.awt.Component)contentPane);
        final JTextField partField = new JTextField(c != null ? c.getPartNum() : null, 15);
        partField.setEditable(edit);
        partField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
        contentPane.add(partField);
        layout.putConstraint("West", (java.awt.Component)partField, 5, "East", (java.awt.Component)partLabel);
        layout.putConstraint("North", (java.awt.Component)partField, 5, "North", (java.awt.Component)contentPane);
        JLabel vendorLabel = new JLabel("Vendor: ", 4);
        contentPane.add(vendorLabel);
        layout.putConstraint("West", (java.awt.Component)vendorLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)vendorLabel, 5, "South", (java.awt.Component)partField);
        final JComboBox<Object> vendorCombo = new JComboBox<Object>();
        for (Map.Entry e : Main.vendors.entrySet()) {
            vendorCombo.addItem(e.getKey());
        }
        for (Map.Entry e : Main.userVendors.entrySet()) {
            vendorCombo.addItem(e.getKey());
        }
        vendorCombo.setMaximumSize(new Dimension(editor.getWidth(), 20));
        if (c != null) {
            if (Main.vendors.get(c.getVendor()) != null || Main.userVendors.get(c.getVendor()) != null) {
                vendorCombo.setSelectedItem(c.getVendor());
            } else {
                vendorCombo.addItem("ERROR");
                vendorCombo.setSelectedIndex(vendorCombo.getItemCount() - 1);
            }
        }
        vendorCombo.setEnabled(edit);
        contentPane.add(vendorCombo);
        layout.putConstraint("West", vendorCombo, 0, "West", (java.awt.Component)partField);
        layout.putConstraint("East", vendorCombo, 0, "East", (java.awt.Component)partField);
        layout.putConstraint("North", vendorCombo, 5, "South", (java.awt.Component)partField);
        JLabel costLabel = new JLabel("Cost (per " + (Main.metric ? "kg" : "lb") + "): ", 4);
        contentPane.add(costLabel);
        layout.putConstraint("West", (java.awt.Component)costLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)costLabel, 5, "South", vendorCombo);
        final JTextField costField = new JTextField(c != null ? new DecimalFormat("$0.00").format(c.getCost()) : null);
        costField.setMaximumSize(new Dimension(editor.getWidth(), 20));
        costField.setEditable(edit);
        contentPane.add(costField);
        layout.putConstraint("West", (java.awt.Component)costField, 0, "West", (java.awt.Component)partField);
        layout.putConstraint("East", (java.awt.Component)costField, 0, "East", (java.awt.Component)partField);
        layout.putConstraint("North", (java.awt.Component)costField, 5, "South", vendorCombo);
        JLabel descriptionLabel = new JLabel("Description: ", 4);
        contentPane.add(descriptionLabel);
        layout.putConstraint("West", (java.awt.Component)descriptionLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)descriptionLabel, 5, "South", (java.awt.Component)costField);
        final JTextArea descriptionArea = new JTextArea(c != null ? c.getDescription() : null, 4, 13);
        JScrollPane descriptionPane = new JScrollPane(descriptionArea);
        descriptionArea.setEditable(edit);
        descriptionArea.setLineWrap(true);
        contentPane.add(descriptionPane);
        layout.putConstraint("West", (java.awt.Component)descriptionPane, 0, "West", (java.awt.Component)partField);
        layout.putConstraint("East", (java.awt.Component)descriptionPane, 0, "East", (java.awt.Component)partField);
        layout.putConstraint("North", (java.awt.Component)descriptionPane, 5, "South", (java.awt.Component)costField);
        JButton saveButton = new JButton(new AbstractAction(edit ? "Save" : "Edit"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (!edit) {
                    editor.dispose();
                    Frame.this.componentEditor(c, true);
                } else {
                    double cost = Double.parseDouble(costField.getText().contains("$") ? costField.getText().replace("$", "") : costField.getText());
                    cost = Main.metric ? cost : cost * 2.2;
                    Main.userComponents.put(partField.getText(), new Component(partField.getText(), vendorCombo.getSelectedItem().toString(), descriptionArea.getText(), cost));
                    Main.saveAll();
                }
                editor.dispose();
                if (Frame.this.viewUserComponent.isSelected()) {
                    Frame.this.viewUserComponent.doClick();
                }
            }
        });
        saveButton.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(saveButton);
        editor.getRootPane().setDefaultButton(saveButton);
        layout.putConstraint("West", (java.awt.Component)saveButton, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)saveButton, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)saveButton, 5, "South", (java.awt.Component)descriptionPane);
        JButton cancelButton = new JButton(new AbstractAction(edit ? "Cancel " : "Close"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                editor.dispose();
            }
        });
        cancelButton.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(cancelButton);
        layout.putConstraint("West", (java.awt.Component)cancelButton, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)cancelButton, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)cancelButton, 5, "South", (java.awt.Component)saveButton);
        layout.putConstraint("East", (java.awt.Component)contentPane, 5, "East", (java.awt.Component)partField);
        layout.putConstraint("South", (java.awt.Component)contentPane, 5, "South", (java.awt.Component)cancelButton);
        editor.setVisible(true);
    }

    private void formulaEditor() {
        this.formulaEditor(null, true);
    }

    private void formulaEditor(final Formula f, final boolean edit) {
        double tempCost;
        final JFrame editor = new JFrame(f != null ? f.getName() : "New Formula");
        editor.setIconImage(Main.icon.getImage());
        editor.setSize(400, 410);
        editor.setLocationRelativeTo(null);
        final HashMap<String, Double> originalVal = new HashMap<String, Double>();
        Container contentPane = editor.getContentPane();
        SpringLayout layout = new SpringLayout();
        contentPane.setLayout(layout);
        JLabel nameLabel = new JLabel("Name: ", 4);
        contentPane.add(nameLabel);
        layout.putConstraint("West", (java.awt.Component)nameLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)nameLabel, 5, "North", (java.awt.Component)contentPane);
        final JTextField nameField = new JTextField(f != null ? f.getName() : null);
        nameField.setEditable(edit);
        nameField.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(nameField);
        layout.putConstraint("West", (java.awt.Component)nameField, 5, "East", (java.awt.Component)nameLabel);
        layout.putConstraint("East", (java.awt.Component)nameField, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)nameField, 5, "North", (java.awt.Component)contentPane);
        JPanel aprRejPanel = new JPanel();
        ButtonGroup br = new ButtonGroup();
        aprRejPanel.add(new JLabel("Apr/Rej: ", 4));
        final JRadioButton apr = new JRadioButton("Approved");
        apr.setEnabled(edit);
        br.add(apr);
        aprRejPanel.add(apr);
        final JRadioButton rej = new JRadioButton("Rejected");
        rej.setEnabled(edit);
        if (f != null) {
            apr.setSelected(f.getApproved());
            rej.setSelected(f.getRejected());
        }
        br.add(rej);
        aprRejPanel.add(rej);
        contentPane.add(aprRejPanel);
        layout.putConstraint("West", (java.awt.Component)aprRejPanel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)aprRejPanel, 5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)aprRejPanel, 5, "South", (java.awt.Component)nameField);
        JLabel descriptionLabel = new JLabel("Description: ");
        contentPane.add(descriptionLabel);
        layout.putConstraint("West", (java.awt.Component)descriptionLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)descriptionLabel, 5, "South", (java.awt.Component)aprRejPanel);
        final JTextArea descriptionArea = new JTextArea(f != null ? f.getDescription() : null, 4, 13);
        JScrollPane descriptionPane = new JScrollPane(descriptionArea);
        descriptionArea.setEditable(edit);
        descriptionArea.setLineWrap(true);
        contentPane.add(descriptionPane);
        layout.putConstraint("West", (java.awt.Component)descriptionPane, 5, "East", (java.awt.Component)descriptionLabel);
        layout.putConstraint("East", (java.awt.Component)descriptionPane, 0, "East", (java.awt.Component)nameField);
        layout.putConstraint("North", (java.awt.Component)descriptionPane, 5, "South", (java.awt.Component)aprRejPanel);
        JLabel formulaLabel = new JLabel("Formula: ");
        contentPane.add(formulaLabel);
        layout.putConstraint("West", (java.awt.Component)formulaLabel, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)formulaLabel, 18, "South", (java.awt.Component)descriptionPane);
        final JTable table = new JTable(){

            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        table.setFillsViewportHeight(true);
        table.setAutoCreateRowSorter(true);
        JScrollPane tableScrollPane = new JScrollPane(table);
        tableScrollPane.setPreferredSize(new Dimension(390, 100));
        contentPane.add(tableScrollPane);
        Object[] arrobject = new Object[3];
        arrobject[0] = "Component";
        arrobject[1] = "Quantity (" + (Main.largeUnits ? (Main.metric ? "kg" : "lb") : (Main.metric ? "g" : "oz")) + ")";
        arrobject[2] = "Price";
        final DefaultTableModel dtm = new DefaultTableModel((Object[][])null, arrobject);
        table.setModel(dtm);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(4);
        table.getColumnModel().getColumn(1).setCellRenderer(rightRenderer);
        table.getColumnModel().getColumn(2).setCellRenderer(rightRenderer);
        if (f != null) {
            for (ComponentQuantity cq : f) {
                double tempQ = cq.getQuantity() / (Main.metric ? 1.0 : 28.3495231);
                tempQ /= (double)(Main.largeUnits ? (Main.metric ? 1000 : 16) : 1);
                originalVal.put(cq.getComponent(), cq.getQuantity());
                if (Main.components.get(cq.getComponent()) != null) {
                    tempCost = tempQ * ((Component)Main.components.get(cq.getComponent())).getCost() / (double)(Main.largeUnits ? 1 : (Main.metric ? 1000 : 16));
                    dtm.addRow(new Object[]{cq.getComponent(), new DecimalFormat("0.0#").format(tempQ), new DecimalFormat("$0.00").format(tempCost)});
                    continue;
                }
                if (Main.userComponents.get(cq.getComponent()) == null) continue;
                tempCost = tempQ * ((Component)Main.userComponents.get(cq.getComponent())).getCost() / (double)(Main.largeUnits ? 1 : (Main.metric ? 1000 : 16));
                dtm.addRow(new Object[]{cq.getComponent(), new DecimalFormat("0.0#").format(tempQ), new DecimalFormat("$0.00").format(tempCost)});
            }
        }
        JButton removeButton = new JButton(new AbstractAction("Remove"){

            @Override
            public void actionPerformed(ActionEvent e) {
                int[] lines = table.getSelectedRows();
                if (lines.length > 0) {
                    for (int i = lines.length - 1; i >= 0; --i) {
                        lines[i] = table.convertRowIndexToModel(lines[i]);
                        originalVal.remove(dtm.getValueAt(lines[i], 0));
                        dtm.removeRow(lines[i]);
                    }
                }
            }
        });
        removeButton.setEnabled(edit);
        contentPane.add(removeButton);
        layout.putConstraint("East", (java.awt.Component)removeButton, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)removeButton, 15, "South", (java.awt.Component)descriptionPane);
        JButton addButton = new JButton(new AbstractAction("Add"){

            @Override
            public void actionPerformed(ActionEvent e) {
                final JFrame cqFrame = new JFrame("Add component");
                cqFrame.setSize(200, 160);
                cqFrame.setIconImage(Main.icon.getImage());
                cqFrame.setLocationRelativeTo(null);
                Container container = cqFrame.getContentPane();
                SpringLayout sLayout = new SpringLayout();
                container.setLayout(sLayout);
                JLabel compLabel = new JLabel("Component: ");
                container.add(compLabel);
                sLayout.putConstraint("West", (java.awt.Component)compLabel, 5, "West", (java.awt.Component)container);
                sLayout.putConstraint("North", (java.awt.Component)compLabel, 5, "North", (java.awt.Component)container);
                ArrayList items = Main.components.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toCollection(ArrayList::new));
                items.addAll(Main.userComponents.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toList()));
                Collections.sort(items);
                final JComboBox componentCombo = new JComboBox();
                items.forEach(componentCombo::addItem);
                container.add(componentCombo);
                sLayout.putConstraint("West", componentCombo, 5, "East", (java.awt.Component)compLabel);
                sLayout.putConstraint("North", componentCombo, 5, "North", (java.awt.Component)container);
                sLayout.putConstraint("East", componentCombo, -5, "East", (java.awt.Component)container);
                JLabel amountLabel = new JLabel("Quantity (" + (Main.largeUnits ? (Main.metric ? "kg" : "lb") : (Main.metric ? "g" : "oz")) + "): ");
                container.add(amountLabel);
                sLayout.putConstraint("West", (java.awt.Component)amountLabel, 5, "West", (java.awt.Component)container);
                sLayout.putConstraint("North", (java.awt.Component)amountLabel, 5, "South", componentCombo);
                final JTextField amountField = new JTextField();
                container.add(amountField);
                sLayout.putConstraint("West", (java.awt.Component)amountField, 0, "West", componentCombo);
                sLayout.putConstraint("North", (java.awt.Component)amountField, 5, "South", componentCombo);
                sLayout.putConstraint("East", (java.awt.Component)amountField, 0, "East", componentCombo);
                JButton sButton = new JButton(new AbstractAction("Save"){

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        originalVal.put(componentCombo.getSelectedItem().toString(), Double.parseDouble(amountField.getText()));
                        if (Main.components.get(componentCombo.getSelectedItem().toString()) != null) {
                            Object[] arrobject = new Object[3];
                            arrobject[0] = componentCombo.getSelectedItem();
                            arrobject[1] = amountField.getText();
                            arrobject[2] = new DecimalFormat("$0.00").format(Double.parseDouble(String.valueOf(amountField.getText())) * ((Component)Main.components.get(componentCombo.getSelectedItem())).getCost() / (double)(Main.metric ? 1000 : 16));
                            dtm.addRow(arrobject);
                        } else {
                            Object[] arrobject = new Object[3];
                            arrobject[0] = componentCombo.getSelectedItem();
                            arrobject[1] = amountField.getText();
                            arrobject[2] = new DecimalFormat("$0.00").format(Double.parseDouble(String.valueOf(amountField.getText())) * ((Component)Main.userComponents.get(componentCombo.getSelectedItem())).getCost() / (double)(Main.metric ? 1000 : 16));
                            dtm.addRow(arrobject);
                        }
                        cqFrame.dispose();
                    }
                });
                container.add(sButton);
                sLayout.putConstraint("West", (java.awt.Component)sButton, 5, "West", (java.awt.Component)container);
                sLayout.putConstraint("North", (java.awt.Component)sButton, 5, "South", (java.awt.Component)amountField);
                sLayout.putConstraint("East", (java.awt.Component)sButton, -5, "East", (java.awt.Component)container);
                JButton cButton = new JButton(new AbstractAction("Cancel"){

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        cqFrame.dispose();
                    }
                });
                container.add(cButton);
                sLayout.putConstraint("West", (java.awt.Component)cButton, 5, "West", (java.awt.Component)container);
                sLayout.putConstraint("North", (java.awt.Component)cButton, 5, "South", (java.awt.Component)sButton);
                sLayout.putConstraint("East", (java.awt.Component)cButton, -5, "East", (java.awt.Component)container);
                cqFrame.setVisible(true);
            }

        });
        addButton.setEnabled(edit);
        contentPane.add(addButton);
        layout.putConstraint("East", (java.awt.Component)addButton, -5, "West", (java.awt.Component)removeButton);
        layout.putConstraint("North", (java.awt.Component)addButton, 15, "South", (java.awt.Component)descriptionPane);
        layout.putConstraint("West", (java.awt.Component)tableScrollPane, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)tableScrollPane, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)tableScrollPane, 5, "South", (java.awt.Component)removeButton);
        double tempYield = 0.0;
        tempCost = 0.0;
        for (int i = 0; i < dtm.getRowCount(); ++i) {
            tempYield += Double.parseDouble(dtm.getValueAt(i, 1).toString());
            tempCost += Double.parseDouble(dtm.getValueAt(i, 2).toString().substring(1));
        }
        final JLabel costLabel = new JLabel("Cost: " + new DecimalFormat("$0.00").format(tempCost));
        contentPane.add(costLabel);
        layout.putConstraint("East", (java.awt.Component)costLabel, -10, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)costLabel, 5, "South", (java.awt.Component)tableScrollPane);
        final JTextField yieldField = new JTextField(new DecimalFormat("0.0#").format(tempYield));
        yieldField.setDisabledTextColor(Color.BLACK);
        yieldField.setPreferredSize(new Dimension(50, 20));
        yieldField.getDocument().addDocumentListener(new DocumentListener(){

            @Override
            public void changedUpdate(DocumentEvent e) {
                this.updated();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                this.updated();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                this.updated();
            }

            public void updated() {
                try {
                    if (yieldField.hasFocus() && Double.parseDouble(yieldField.getText()) > 0.0) {
                        int i;
                        double yield = Double.parseDouble(yieldField.getText()) * (double)(Main.largeUnits ? (Main.metric ? 1000 : 16) : (Main.metric ? 1 : 1));
                        double originalYield = 0.0;
                        for (String key : originalVal.keySet()) {
                            originalYield += ((Double)originalVal.get(key)).doubleValue();
                        }
                        double tempCostTotal = 0.0;
                        int count = dtm.getRowCount();
                        for (i = 0; i < count; ++i) {
                            String tempName = dtm.getValueAt(i, 0).toString();
                            double tempQuantity = (Double)originalVal.get(tempName);
                            double tempCost = Main.components.containsKey(tempName) ? tempQuantity / originalYield * yield * ((Component)Main.components.get(tempName)).getCost() / (double)(Main.metric ? 1000 : 16) : tempQuantity / originalYield * yield * ((Component)Main.userComponents.get(tempName)).getCost() / (double)(Main.metric ? 1000 : 16);
                            double newQuantity = tempQuantity / originalYield * yield / (double)(Main.largeUnits ? (Main.metric ? 1000 : 16) : 1);
                            dtm.addRow(new Object[]{tempName, new DecimalFormat("0.0#").format(newQuantity), new DecimalFormat("$0.00").format(tempCost)});
                            tempCostTotal += tempCost;
                        }
                        costLabel.setText("Cost: " + new DecimalFormat("$0.00").format(tempCostTotal));
                        for (i = dtm.getRowCount() / 2 - 1; i >= 0; --i) {
                            dtm.removeRow(i);
                        }
                    }
                }
                catch (NumberFormatException yield) {
                    // empty catch block
                }
            }
        });
        contentPane.add(yieldField);
        layout.putConstraint("East", (java.awt.Component)yieldField, -10, "West", (java.awt.Component)costLabel);
        layout.putConstraint("North", (java.awt.Component)yieldField, 3, "South", (java.awt.Component)tableScrollPane);
        JLabel yieldLabel = new JLabel("Yield (" + (Main.largeUnits ? (Main.metric ? "kg" : "lb") : (Main.metric ? "g" : "oz")) + "): ");
        contentPane.add(yieldLabel);
        layout.putConstraint("East", (java.awt.Component)yieldLabel, -5, "West", (java.awt.Component)yieldField);
        layout.putConstraint("North", (java.awt.Component)yieldLabel, 5, "South", (java.awt.Component)tableScrollPane);
        dtm.addTableModelListener(e -> {
            if (!yieldField.hasFocus()) {
                double tempYield1 = 0.0;
                double tempCost1 = 0.0;
                for (int i = 0; i < dtm.getRowCount(); ++i) {
                    tempYield1 += Double.parseDouble(dtm.getValueAt(i, 1).toString());
                    tempCost1 += Double.parseDouble(dtm.getValueAt(i, 2).toString().substring(1));
                }
                yieldField.setText(String.valueOf(tempYield1));
                costLabel.setText("Cost: " + new DecimalFormat("$0.00").format(tempCost1));
            }
        }
        );
        JButton saveButton = new JButton(new AbstractAction(edit ? "Save" : "Edit"){

            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (!edit) {
                    editor.dispose();
                    Frame.this.formulaEditor(f, true);
                } else {
                    Main.userFormulas.put(nameField.getText(), new Formula(nameField.getText(), descriptionArea.getText()));
                    if (apr.isSelected() || rej.isSelected()) {
                        ((Formula)Main.userFormulas.get(nameField.getText())).setApproved(apr.isSelected());
                        ((Formula)Main.userFormulas.get(nameField.getText())).setRejected(rej.isSelected());
                    }
                    for (int i = 0; i < dtm.getRowCount(); ++i) {
                        double tempC = Double.parseDouble(dtm.getValueAt(i, 1).toString()) * (double)(Main.largeUnits ? (Main.metric ? 1000 : 16) : 1);
                        ((Formula)Main.userFormulas.get(nameField.getText())).add(new ComponentQuantity(dtm.getValueAt(i, 0).toString(), tempC *= Main.metric ? 1.0 : 28.3495231));
                    }
                    Main.saveAll();
                }
                editor.dispose();
                if (Frame.this.viewUserFormula.isSelected()) {
                    Frame.this.viewUserFormula.doClick();
                }
            }
        });
        saveButton.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(saveButton);
        editor.getRootPane().setDefaultButton(saveButton);
        layout.putConstraint("West", (java.awt.Component)saveButton, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)saveButton, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)saveButton, 5, "South", (java.awt.Component)yieldLabel);
        JButton cancelButton = new JButton(new AbstractAction(edit ? "Cancel " : "Close"){
            private static final long serialVersionUID = 1;

            @Override
            public void actionPerformed(ActionEvent arg0) {
                editor.dispose();
            }
        });
        cancelButton.setMaximumSize(new Dimension(editor.getWidth(), 20));
        contentPane.add(cancelButton);
        layout.putConstraint("West", (java.awt.Component)cancelButton, 5, "West", (java.awt.Component)contentPane);
        layout.putConstraint("East", (java.awt.Component)cancelButton, -5, "East", (java.awt.Component)contentPane);
        layout.putConstraint("North", (java.awt.Component)cancelButton, 5, "South", (java.awt.Component)saveButton);
        editor.setVisible(true);
    }

    private void reloadView() {
        if (this.viewVendor.isSelected()) {
            this.viewVendor.doClick();
        } else if (this.viewUserVendor.isSelected()) {
            this.viewUserVendor.doClick();
        } else if (this.viewComponent.isSelected()) {
            this.viewComponent.doClick();
        } else if (this.viewUserComponent.isSelected()) {
            this.viewUserComponent.doClick();
        } else if (this.viewFormula.isSelected()) {
            this.viewFormula.doClick();
        } else if (this.viewUserFormula.isSelected()) {
            this.viewUserFormula.doClick();
        }
    }

}

