@Override
 public void actionPerformed(ActionEvent ae) {
   if (ae.getSource().equals(openItem)) {
     File f = null;
     if (null == (f = SpeedyGrader.getInstance().getFilesLoc())) {
       f = new File(System.getProperty("user.home"));
     }
     JFileChooser chooser = new JFileChooser(f);
     chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     int ret = chooser.showOpenDialog(this);
     if (ret == JFileChooser.APPROVE_OPTION) {
       newFolderSelected(chooser.getSelectedFile());
     }
   } else if (ae.getSource().equals(inputItem)) {
     new InputDialog();
   } else if (ae.getSource().equals(saveItem)) {
     for (EditorPanel ep : editorPanels) {
       ep.save();
     }
     SpeedyGrader.getInstance().startComplieAndRun();
   } else if (ae.getSource().equals(refreshItem)) {
     newFolderSelected(null);
   } else if (ae.getSource().equals(githubItem)) {
     String url = "https://github.com/MitchellSlavik/SpeedyGrader";
     Desktop d = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
     if (d != null && d.isSupported(Action.BROWSE)) {
       try {
         d.browse(URI.create(url));
       } catch (IOException e) {
         e.printStackTrace();
       }
     } else {
       JOptionPane.showMessageDialog(
           this,
           "We were unable to open a web browser. The url has been copied to your clipboard.",
           "Unable to preform operation",
           JOptionPane.ERROR_MESSAGE);
       StringSelection selection = new StringSelection(url);
       Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
       clipboard.setContents(selection, selection);
     }
   } else if (ae.getSource().equals(aboutItem)) {
     new AboutDialog();
   } else if (ae.getSource().equals(installItem)) {
     new InstallDialog();
   } else if (ae.getSource().equals(upgradeItem)) {
     new AutoUpdater();
   } else if (ae.getSource().equals(editorSplitToggle)) {
     splitEditorPane.setOrientation(
         editorSplitToggle.isSelected() ? JSplitPane.VERTICAL_SPLIT : JSplitPane.HORIZONTAL_SPLIT);
     this.validate();
     this.repaint();
   }
 }
  public void newFolderSelected(File dir) {
    tabbedPane.removeAll();
    editorPanels.clear();
    consoleTextArea.setText("");
    filesListModel.clear();

    for (SourceFile sf : SpeedyGrader.getInstance().getSourceFiles(dir)) {
      filesListModel.addElement(sf);
    }

    splitMainPane.setDividerLocation(.2);
    this.revalidate();
    this.repaint();
  }
  @Override
  public void valueChanged(ListSelectionEvent lse) {
    if (!lse.getValueIsAdjusting()) {
      boolean needsSave = false;
      for (EditorPanel ep : editorPanels) {
        if (ep.needsSave()) {
          needsSave = true;
        }
      }
      if (needsSave) {
        int i =
            JOptionPane.showConfirmDialog(
                this,
                "Would you like to save before switching files?",
                "Save?",
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        switch (i) {
          case JOptionPane.YES_OPTION:
            for (EditorPanel ep : editorPanels) {
              ep.save();
            }
            break;
          case JOptionPane.NO_OPTION:
            break;
          case JOptionPane.CANCEL_OPTION:
          case JOptionPane.CLOSED_OPTION:
            return;
        }
      }
      tabbedPane.removeAll();
      editorPanels.clear();

      if (filesList.getSelectedValue() != null) {
        for (Entry<String, File> ents : filesList.getSelectedValue().getFileList().entrySet()) {
          EditorPanel ep = new EditorPanel(ents.getValue(), textFont);
          tabbedPane.addTab(ents.getKey(), ep);
          editorPanels.add(ep);
        }

        SpeedyGrader.getInstance().startComplieAndRun();
      }
    }
  }
  public AboutDialog() {
    super(SpeedyGrader.getInstance().getGUI(), "About SpeedyGrader");

    mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());

    licensePanel = new JTextPane();
    licensePanel.setEditable(false);
    licensePanel.setFont(SpeedyGrader.getInstance().getGUI().getTextFont());

    String licensesStr = "";
    ArrayList<InputStream> licenseStreams = new ArrayList<InputStream>();

    for (String s : licenses) {
      try {
        licenseStreams.add(AboutDialog.class.getResourceAsStream("/" + s + ".License.txt"));
      } catch (Exception e) {
        try {
          licenseStreams.add(new FileInputStream("licenses" + File.separator + s + ".License.txt"));
        } catch (FileNotFoundException e1) {
          System.out.println("Could not find licenses!");
        }
      }
    }

    int i = 0;
    for (InputStream is : licenseStreams) {
      licensesStr += licenses[i++] + " License:\n";
      BufferedReader br = new BufferedReader(new InputStreamReader(is));
      String line;
      try {
        while ((line = br.readLine()) != null) {
          licensesStr += line + "\n";
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (!licenseStreams.get(licenseStreams.size() - 1).equals(is)) {
        licensesStr += "\n\n\n";
      }
    }

    licensePanel.setText(licensesStr);
    licensePanel.setCaretPosition(0);

    mainPanel.add(new JScrollPane(licensePanel), BorderLayout.CENTER);

    topPanel = new JPanel();

    JLabel label =
        new JLabel(
            "<html><div style='text-align: center;'>Created by: Mitchell Slavik<br/>Email: [email protected]</html>",
            JLabel.CENTER);
    label.setFont(SpeedyGrader.getInstance().getGUI().getTextFont());
    topPanel.add(label, BorderLayout.CENTER);

    mainPanel.add(topPanel, BorderLayout.NORTH);

    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setContentPane(mainPanel);
    this.setModalityType(ModalityType.APPLICATION_MODAL);
    this.setSize(850, 500);
    this.setResizable(false);
    this.setLocationRelativeTo(SpeedyGrader.getInstance().getGUI());
    this.setVisible(true);
  }