// Path: tmc-plugin-intellij/src/main/java/fi/helsinki/cs/tmc/intellij/services/errors/ErrorMessageService.java
// public class ErrorMessageService {
// 
//     /**
//      * Notification group used by IntelliJ to group TMC notifications.
//      */
//     public static final NotificationGroup TMC_NOTIFICATION = new NotificationGroup(
//             "TMC Error Messages",
//             NotificationDisplayType.STICKY_BALLOON,
//             true
//     );
// 
//     private static final Logger logger = LoggerFactory.getLogger(ErrorMessageService.class);
// 
//     public void showInfoBalloon(String message) {
//         showBalloonNotification(message, NotificationType.INFORMATION);
//     }
// 
//     public void showExercisesAreUpToDate(Course course) {
//         ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(
//                 "All exercises for " + course.toString() + " are up to date.",
//                 "All Exercises Are up to Date.",
//                 Messages.getInformationIcon()
//         ));
//     }
// 
//     public void showPopupWithDetails(String message,
//                                      String title,
//                                      String details,
//                                      NotificationType notificationType) {
//         Project currentProject = new ObjectFinder().findCurrentProject();
//         Icon icon = iconForNotificationType(notificationType);
// 
//         ApplicationManager.getApplication().invokeLater(() -> Messages.showDialog(
//                 currentProject,
//                 message,
//                 title,
//                 details,
//                 new String[] { Messages.OK_BUTTON },
//                 0,
//                 0,
//                 icon
//         ));
//     }
// 
//     /**
//      * Shows a human readable error message to the user as a popup or a notification balloon.
//      *
//      * @param coreException The cause of the error.
//      * @param showAsPopup if the error message will be a pop up or not.
//      */
//     public void showHumanReadableErrorMessage(TmcCoreException coreException, boolean showAsPopup) {
//         logger.info("Showing human readable TmcCoreException. {} @ErrorMessageService", coreException);
//         PresentableErrorMessage content = PresentableErrorMessage.forTmcException(coreException);
//         showNotification(content.getMessage(), content.getMessageType(), showAsPopup);
//     }
// 
//     /**
//      * Shows an error message to the user as a popup or a notification balloon.
//      *
//      * @param exception The cause of the error, prepended to the description.
//      * @param errorDescription Additional description of the error.
//      * @param showAsPopup if the error message will be a pop up or not.
//      */
//     public void showErrorMessageWithExceptionDetails(Exception exception,
//                                                      String errorDescription,
//                                                      boolean showAsPopup) {
//         logger.info("Showing Exception. {} @ErrorMessageService", exception);
//         String message = exception + ". \n" + errorDescription;
//         showNotification(message, NotificationType.ERROR, showAsPopup);
//     }
// 
//     public void showErrorMessagePopup(String errorMessage) {
//         logger.info("Showing error message: {}. @ErrorMessageService", errorMessage);
//         showNotification(errorMessage, NotificationType.ERROR, true);
//     }
// 
//     private void showNotification(String message, NotificationType type, boolean showAsPopup) {
//         if (showAsPopup) {
//             showPopup(message, type);
//         } else {
//             showBalloonNotification(message, type);
//         }
//     }
// 
//     private void showBalloonNotification(String message, NotificationType type) {
//         Notification notification = TMC_NOTIFICATION.createNotification(message, type);
//         Project currentProject = new ObjectFinder().findCurrentProject();
// 
//         ApplicationManager.getApplication().invokeLater(() -> Notifications.Bus.notify(notification, currentProject));
//     }
// 
//     private void showPopup(String message, NotificationType notificationType) {
//         Project currentProject = new ObjectFinder().findCurrentProject();
//         Icon icon = iconForNotificationType(notificationType);
// 
//         ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(currentProject, message, "", icon));
//     }
// 
//     private Icon iconForNotificationType(NotificationType type) {
//         if (type == NotificationType.WARNING) {
//             return Messages.getWarningIcon();
//         } else if (type == NotificationType.ERROR) {
//             return Messages.getErrorIcon();
//         } else if (type == NotificationType.INFORMATION) {
//             return Messages.getInformationIcon();
//         } else {
//             return Messages.getErrorIcon();
//         }
//     }
// }


import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.components.JBScrollPane;
import fi.helsinki.cs.tmc.intellij.services.errors.ErrorMessageService;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;

    public static void display() {
        AboutTmcDialog dialog = new AboutTmcDialog();

        dialog.setLocationRelativeTo(null);
        dialog.setTitle("About");
        dialog.setVisible(true);
        dialog.setAlwaysOnTop(true);
    }

    public AboutTmcDialog() {
        super(
                WindowManager.getInstance()
                        .getFrame(ProjectManager.getInstance().getDefaultProject()),
                false);
        initComponents();

        this.headerLabel.setText("About Test My Code");
        this.infoTextPane.setText("<html> <body> <div> Test My Code is a service designed for learning and teaching programming. It is open "
                        + "source, provides support for automatic assessment of programming assignments, and comes with a server "
                        + "that can be used to maintain course-specific point lists and grading. </div> <br> <div> "
                        + "Find out more at <a href=\"https://mooc.fi/tmc\">https://mooc.fi/tmc</a>. </div> </body> </html>");
        this.closeButton.setText("Close");

        this.infoTextPane.addHyperlinkListener((HyperlinkEvent e) -> {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop desktop = Desktop.getDesktop();
                    desktop.browse(new URI("https://mooc.fi/tmc"));
                } catch (Exception ex) {
// Path: tmc-plugin-intellij/src/main/java/fi/helsinki/cs/tmc/intellij/services/errors/ErrorMessageService.java
// public class ErrorMessageService {
// 
//     /**
//      * Notification group used by IntelliJ to group TMC notifications.
//      */
//     public static final NotificationGroup TMC_NOTIFICATION = new NotificationGroup(
//             "TMC Error Messages",
//             NotificationDisplayType.STICKY_BALLOON,
//             true
//     );
// 
//     private static final Logger logger = LoggerFactory.getLogger(ErrorMessageService.class);
// 
//     public void showInfoBalloon(String message) {
//         showBalloonNotification(message, NotificationType.INFORMATION);
//     }
// 
//     public void showExercisesAreUpToDate(Course course) {
//         ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(
//                 "All exercises for " + course.toString() + " are up to date.",
//                 "All Exercises Are up to Date.",
//                 Messages.getInformationIcon()
//         ));
//     }
// 
//     public void showPopupWithDetails(String message,
//                                      String title,
//                                      String details,
//                                      NotificationType notificationType) {
//         Project currentProject = new ObjectFinder().findCurrentProject();
//         Icon icon = iconForNotificationType(notificationType);
// 
//         ApplicationManager.getApplication().invokeLater(() -> Messages.showDialog(
//                 currentProject,
//                 message,
//                 title,
//                 details,
//                 new String[] { Messages.OK_BUTTON },
//                 0,
//                 0,
//                 icon
//         ));
//     }
// 
//     /**
//      * Shows a human readable error message to the user as a popup or a notification balloon.
//      *
//      * @param coreException The cause of the error.
//      * @param showAsPopup if the error message will be a pop up or not.
//      */
//     public void showHumanReadableErrorMessage(TmcCoreException coreException, boolean showAsPopup) {
//         logger.info("Showing human readable TmcCoreException. {} @ErrorMessageService", coreException);
//         PresentableErrorMessage content = PresentableErrorMessage.forTmcException(coreException);
//         showNotification(content.getMessage(), content.getMessageType(), showAsPopup);
//     }
// 
//     /**
//      * Shows an error message to the user as a popup or a notification balloon.
//      *
//      * @param exception The cause of the error, prepended to the description.
//      * @param errorDescription Additional description of the error.
//      * @param showAsPopup if the error message will be a pop up or not.
//      */
//     public void showErrorMessageWithExceptionDetails(Exception exception,
//                                                      String errorDescription,
//                                                      boolean showAsPopup) {
//         logger.info("Showing Exception. {} @ErrorMessageService", exception);
//         String message = exception + ". \n" + errorDescription;
//         showNotification(message, NotificationType.ERROR, showAsPopup);
//     }
// 
//     public void showErrorMessagePopup(String errorMessage) {
//         logger.info("Showing error message: {}. @ErrorMessageService", errorMessage);
//         showNotification(errorMessage, NotificationType.ERROR, true);
//     }
// 
//     private void showNotification(String message, NotificationType type, boolean showAsPopup) {
//         if (showAsPopup) {
//             showPopup(message, type);
//         } else {
//             showBalloonNotification(message, type);
//         }
//     }
// 
//     private void showBalloonNotification(String message, NotificationType type) {
//         Notification notification = TMC_NOTIFICATION.createNotification(message, type);
//         Project currentProject = new ObjectFinder().findCurrentProject();
// 
//         ApplicationManager.getApplication().invokeLater(() -> Notifications.Bus.notify(notification, currentProject));
//     }
// 
//     private void showPopup(String message, NotificationType notificationType) {
//         Project currentProject = new ObjectFinder().findCurrentProject();
//         Icon icon = iconForNotificationType(notificationType);
// 
//         ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(currentProject, message, "", icon));
//     }
// 
//     private Icon iconForNotificationType(NotificationType type) {
//         if (type == NotificationType.WARNING) {
//             return Messages.getWarningIcon();
//         } else if (type == NotificationType.ERROR) {
//             return Messages.getErrorIcon();
//         } else if (type == NotificationType.INFORMATION) {
//             return Messages.getInformationIcon();
//         } else {
//             return Messages.getErrorIcon();
//         }
//     }
// }


// Path: tmc-plugin-intellij/src/main/java/fi/helsinki/cs/tmc/intellij/ui/aboutTmc/AboutTmcDialog.java
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.components.JBScrollPane;
import fi.helsinki.cs.tmc.intellij.services.errors.ErrorMessageService;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;


    public static void display() {
        AboutTmcDialog dialog = new AboutTmcDialog();

        dialog.setLocationRelativeTo(null);
        dialog.setTitle("About");
        dialog.setVisible(true);
        dialog.setAlwaysOnTop(true);
    }

    public AboutTmcDialog() {
        super(
                WindowManager.getInstance()
                        .getFrame(ProjectManager.getInstance().getDefaultProject()),
                false);
        initComponents();

        this.headerLabel.setText("About Test My Code");
        this.infoTextPane.setText("<html> <body> <div> Test My Code is a service designed for learning and teaching programming. It is open "
                        + "source, provides support for automatic assessment of programming assignments, and comes with a server "
                        + "that can be used to maintain course-specific point lists and grading. </div> <br> <div> "
                        + "Find out more at <a href=\"https://mooc.fi/tmc\">https://mooc.fi/tmc</a>. </div> </body> </html>");
        this.closeButton.setText("Close");

        this.infoTextPane.addHyperlinkListener((HyperlinkEvent e) -> {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop desktop = Desktop.getDesktop();
                    desktop.browse(new URI("https://mooc.fi/tmc"));
                } catch (Exception ex) {
                    new ErrorMessageService().showErrorMessagePopup("Failed to open browser.\n" + ex.getMessage());