private void initUi() {
        JMenuBar menuBar = new JMenuBar();
        JMenu factMenu = new JMenu("Facts");
        JMenu ruleMenu = new JMenu("Rules");
        menuBar.add(factMenu);
        menuBar.add(ruleMenu);      
        
        //-------------
        // ADD FACT
        //-------------
        JMenuItem addFactMenuItem = new JMenuItem("Add fact");
        factMenu.add(addFactMenuItem);
        // Add the listener to open the add fact dialog
        addFactMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                final JDialog addFactDialog = new JDialog();
                addFactDialog.setResizable(false);
                addFactDialog.setTitle("Add Fact");
                addFactDialog.getContentPane().setLayout(new BoxLayout(addFactDialog.getContentPane(), BoxLayout.PAGE_AXIS));
                final JTextField nameText = new JTextField("Name");
                final JTextField textText = new JTextField("Text");
                addFactDialog.add(nameText);
                addFactDialog.add(textText);
                JButton addButton = new JButton("Add");
                addButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent me) {
                        int num = 0;
                        da.insertNewFact(nameText.getText(), textText.getText());
                        addFactDialog.dispose();
                    }
                });
                JButton cancelButton = new JButton("Cancel");
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent me) {
                        addFactDialog.dispose();
                    }
                });
                JPanel panel = new JPanel();
                panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
                panel.add(addButton);
                panel.add(cancelButton);
                addFactDialog.add(panel);
                addFactDialog.pack();
                addFactDialog.setLocationRelativeTo(null);
                addFactDialog.setVisible(true);
            }
        });
        
        //---------------
        // REMOVE FACT
        //---------------
        JMenuItem removeFactMenuItem = new JMenuItem("Downvote fact");
        factMenu.add(removeFactMenuItem);
        // Add the listener to open the remove fact dialog
        removeFactMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                final JDialog removeFactDialog = new JDialog();
                removeFactDialog.setResizable(false);
                removeFactDialog.setTitle("Downvote Fact");
                removeFactDialog.getContentPane().setLayout(new BoxLayout(removeFactDialog.getContentPane(), BoxLayout.PAGE_AXIS));
                // List of facts in the database
                final DefaultListModel removeFactsModel = new DefaultListModel();
                copyInto(removeFactsModel, loadFactsToDownvote());
                final JList removeFactsList = new JList(removeFactsModel);
                removeFactsList.setCellRenderer(new SelectableListItemRenderer());
                JScrollPane removeFactsScroll = new JScrollPane(removeFactsList);
                removeFactsScroll.setPreferredSize(new Dimension(200, 300));
                
                JButton removeButton = new JButton("Downvote");
                removeButton.setPreferredSize(new Dimension(100, 50));
                removeButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent me) {
                        // Get the selected fact
                        Fact fact = (Fact) removeFactsList.getSelectedValue();
                        da.removeFact(fact.getId());
                        removeFactDialog.dispose();
                    }
                });
                JButton cancelButton = new JButton("Cancel");
                cancelButton.setPreferredSize(new Dimension(100, 50));
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent me) {
                        removeFactDialog.dispose();
                    }                    
                });                
                JPanel buttonPanel = new JPanel();
                buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
                buttonPanel.add(removeButton);
                buttonPanel.add(cancelButton);
                removeFactDialog.add(removeFactsScroll);
                removeFactDialog.add(buttonPanel);
                removeFactDialog.pack();
                removeFactDialog.setLocationRelativeTo(null);
                removeFactDialog.setVisible(true);
            }
        });
        
        //-----------
        // ADD RULE
        //-----------
        JMenuItem addRuleMenuItem = new JMenuItem("Add rule");
        ruleMenu.add(addRuleMenuItem);
        // Add the listener to open the add rule dialog
        addRuleMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                final JDialog addRuleDialog = new JDialog();
                addRuleDialog.setResizable(false);
                addRuleDialog.setTitle("Add Rule");                
                addRuleDialog.getContentPane().setLayout(new BoxLayout(addRuleDialog.getContentPane(), BoxLayout.PAGE_AXIS));
                
                ArrayList<Fact> facts = loadFacts();
                
                final DefaultListModel factsListModel = new DefaultListModel();
                copyInto(factsListModel, getNonAnswers(facts));
                final JList selectFactsList = new JList(factsListModel);
                selectFactsList.setCellRenderer(new SelectableListItemRenderer());
                JScrollPane selectFactsScroll = new JScrollPane(selectFactsList);
                selectFactsScroll.setPreferredSize(new Dimension(200, 300));
                JLabel factsListLabel = new JLabel("Facts");
                JPanel factsListPanel = new JPanel();
                factsListPanel.setLayout(new BoxLayout(factsListPanel, BoxLayout.PAGE_AXIS));
                factsListPanel.add(factsListLabel);
                factsListPanel.add(selectFactsScroll);
                
                final DefaultListModel answersListModel = new DefaultListModel();
                copyInto(answersListModel, getAnswers(facts));
                final JList selectAnswerList = new JList(answersListModel);
                selectAnswerList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                selectAnswerList.setCellRenderer(new SelectableListItemRenderer());
                JScrollPane selectAnswerScroll = new JScrollPane(selectAnswerList);
                selectAnswerScroll.setPreferredSize(new Dimension(200, 300));
                JLabel answersListLabel = new JLabel("Answers");
                JPanel answersListPanel = new JPanel();
                answersListPanel.setLayout(new BoxLayout(answersListPanel, BoxLayout.PAGE_AXIS));
                answersListPanel.add(answersListLabel);
                answersListPanel.add(selectAnswerScroll);
                
                JPanel listPanel = new JPanel();
                listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.LINE_AXIS));
                listPanel.add(factsListPanel);
                listPanel.add(answersListPanel);
                
                JButton addButton = new JButton("Add");
                addButton.setPreferredSize(new Dimension(100, 50));
                addButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent me) {
                        // Get selected facts
                        ArrayList<Fact> facts = (ArrayList<Fact>) selectFactsList.getSelectedValuesList();                        
                        // Get selected answer
                        Fact answer = (Fact) selectAnswerList.getSelectedValue();
                        // Insert the new rule to the database
                        da.insertNewRule(facts, answer);
                        addRuleDialog.dispose();
                    }
                });
                JButton cancelButton = new JButton("Cancel");
                cancelButton.setPreferredSize(new Dimension(100, 50));
                cancelButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent me) {
                        addRuleDialog.dispose();
                    }                    
                }); 
                JPanel buttonPanel = new JPanel();
                buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
                buttonPanel.add(cancelButton);
                buttonPanel.add(addButton);
                
                addRuleDialog.add(listPanel);
                addRuleDialog.add(buttonPanel);
                addRuleDialog.pack();
                addRuleDialog.setLocationRelativeTo(null);
                addRuleDialog.setVisible(true);
            }
        });
        
        //--------------
        // REMOVE RULE
        //--------------
        JMenuItem removeRuleMenuItem = new JMenuItem("Remove rule");
        //ruleMenu.add(removeRuleMenuItem);
        // Add the listener to open the remove rule dialog
        removeRuleMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                final JDialog removeRuleDialog = new JDialog();
                removeRuleDialog.setTitle("Remove Rule");
                
                removeRuleDialog.setLocationRelativeTo(null);
                removeRuleDialog.setVisible(true);
            }
        });
        
        setLayout(new GridLayout(1, 4));
        
        // This is the UI containing the list of facts for the user to select.
        JPanel factPanel = new JPanel();
        factPanel.setLayout(new BoxLayout(factPanel, BoxLayout.PAGE_AXIS));
        JLabel factLabel = new JLabel("Facts");
        copyInto(factModel, getNonAnswers(Facts).toArray());
        factList = new JList(factModel);
        factList.setCellRenderer(new SelectableListItemRenderer());
        JScrollPane factsList = new JScrollPane(factList);
        factsList.setPreferredSize(new Dimension(200, 500));
        factPanel.add(factLabel);
        factPanel.add(factsList);
        
        // This list shows the selected facts
        JPanel userFactPanel = new JPanel();
        userFactPanel.setLayout(new BoxLayout(userFactPanel, BoxLayout.PAGE_AXIS));
        JLabel userFactLabel = new JLabel("Known Facts");
        copyInto(userFactModel, UserFacts.toArray());
        userFactList = new JList(userFactModel);
        userFactList.setCellRenderer(new SelectableListItemRenderer());
        JScrollPane userFacts = new JScrollPane(userFactList);
        userFacts.setPreferredSize(new Dimension(200, 500));
        userFactPanel.add(userFactLabel);
        userFactPanel.add(userFacts);
        
        // This list is the working memory of the inference engine  
        JPanel workingMemoryPanel = new JPanel();
        workingMemoryPanel.setLayout(new BoxLayout(workingMemoryPanel, BoxLayout.PAGE_AXIS));
        JLabel workingMemoryLabel = new JLabel("Working Memory");
        copyInto(workingMemoryModel, engine.getWorkingMemory().toArray());
        workingMemoryList = new JList(workingMemoryModel);
        workingMemoryList.setCellRenderer(new ListItemRenderer());
        JScrollPane workingMemory = new JScrollPane(workingMemoryList);
        workingMemory.setPreferredSize(new Dimension(200, 500));
        workingMemoryPanel.add(workingMemoryLabel);
        workingMemoryPanel.add(workingMemory);
        
        // This is the list of the answer(s)
        JPanel answerPanel = new JPanel();
        answerPanel.setLayout(new BoxLayout(answerPanel, BoxLayout.PAGE_AXIS));
        JLabel answerLabel = new JLabel("Answer");
        copyInto(answerMemoryModel, new ArrayList<Conditional>().toArray());
        answerMemoryList = new JList(answerMemoryModel);
        answerMemoryList.setCellRenderer(new ListItemRenderer());
        JScrollPane answers = new JScrollPane(answerMemoryList);
        answers.setPreferredSize(new Dimension(200, 500));
        answerPanel.add(answerLabel);
        answerPanel.add(answers);
        
        // Listener to take an element from the facts list and place it in the
        // working memory list thing.
        factList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                Object element = (Fact) factList.getSelectedValue();
                if (element != null) {
                    DefaultListModel dm = (DefaultListModel) factList.getModel();
                    dm.removeElement(element);
                    dm = (DefaultListModel) userFactList.getModel();
                    dm.addElement(element);                   
                }
                resetRules();
                engine = new InferenceEngine(getConditionals());
                updateWorkingMemory();
                updateAnswers();
            }            
        });
        
        // Remove a fact from the working memory list thing and place it back
        // in the list of choosable facts.
        userFactList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                Object element = (Fact) userFactList.getSelectedValue();
                if (element != null) {
                    DefaultListModel dm = (DefaultListModel) userFactList.getModel();
                    dm.removeElement(element);
                    dm = (DefaultListModel) factList.getModel();
                    dm.addElement(element);
                    //sort(dm);
                }      
                resetRules();
                engine = new InferenceEngine(getConditionals());
                updateWorkingMemory();
                updateAnswers();
            }            
        });        
        
        // Add these UI elements to the 
        setJMenuBar(menuBar);
        add(factPanel);
        add(userFactPanel);
        add(workingMemoryPanel);
        add(answerPanel);
        // Pack 'em tight so that the window fits them
        pack();
        // Do some other stuff so that it's all good
        setTitle("A.R.K.S.");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }