Search in sources :

Example 1 with TaskCallbackStatus

use of cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus in project vcell by virtualcell.

the class SimulationConsolePanel method appendToConsole.

private void appendToConsole(TaskCallbackMessage newCallbackMessage) {
    TaskCallbackStatus status = newCallbackMessage.getStatus();
    String string = newCallbackMessage.getText();
    StyledDocument doc = netGenConsoleText.getStyledDocument();
    SimpleAttributeSet keyWord = new SimpleAttributeSet();
    try {
        switch(status) {
            case // clean console, display task initialization message
            Clean:
                netGenConsoleText.setText("");
                break;
            case TaskStopped:
                StyleConstants.setForeground(keyWord, Color.RED);
                StyleConstants.setBold(keyWord, true);
                doc.insertString(doc.getLength(), "  " + string + "\n", keyWord);
                break;
            case // normal notification, just display the string
            Notification:
                doc.insertString(doc.getLength(), string + "\n", null);
                break;
            case // display this in red, bold
            Error:
                StyleConstants.setForeground(keyWord, Color.RED);
                StyleConstants.setBold(keyWord, true);
                doc.insertString(doc.getLength(), string + "\n", keyWord);
                break;
            case // display this in red
            Warning:
                StyleConstants.setForeground(keyWord, Color.RED);
                doc.insertString(doc.getLength(), string + "\n", keyWord);
                break;
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) StyledDocument(javax.swing.text.StyledDocument) TaskCallbackStatus(cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus)

Example 2 with TaskCallbackStatus

use of cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus in project vcell by virtualcell.

the class TaskCallbackProcessor method process.

private void process(TaskCallbackMessage newCallbackMessage) {
    TaskCallbackStatus status = newCallbackMessage.getStatus();
    String string = newCallbackMessage.getText();
    // System.out.println(string);
    try {
        switch(status) {
            case // clean console, display task initialization message
            Clean:
                System.out.println("Clean");
                previousIterationSpecies = 0;
                currentIterationSpecies = 0;
                needAdjustIterations = false;
                needAdjustMaxMolecules = false;
                // sc.setInsufficientIterations(false);
                // sc.setInsufficientMaxMolecules(false);
                TaskCallbackMessage tcm = new TaskCallbackMessage(TaskCallbackStatus.Clean, "");
                consoleNotificationList.add(tcm);
                sc.firePropertyChange("appendToConsole", "", tcm);
                if (string != null && !string.isEmpty()) {
                    tcm = new TaskCallbackMessage(TaskCallbackStatus.Notification, string);
                    consoleNotificationList.add(tcm);
                    sc.firePropertyChange("appendToConsole", "", tcm);
                }
                break;
            case // display task initialization message
            TaskStart:
                System.out.println("Task started");
                tcm = new TaskCallbackMessage(TaskCallbackStatus.Notification, string);
                consoleNotificationList.add(tcm);
                sc.firePropertyChange("appendToConsole", "", tcm);
                break;
            case TaskEnd:
                System.out.println("Task ended");
                if (getPreviousIterationSpecies() > 0 && getCurrentIterationSpecies() > 0 && getCurrentIterationSpecies() != getPreviousIterationSpecies()) {
                    String s = NetworkTransformer.getInsufficientIterationsMessage();
                    tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, s);
                    consoleNotificationList.add(tcm);
                    sc.firePropertyChange("appendToConsole", "", tcm);
                    sc.setInsufficientIterations(true);
                } else {
                    sc.setInsufficientIterations(false);
                }
                if (getPreviousIterationSpecies() > 0 && getCurrentIterationSpecies() > 0 && getCurrentIterationSpecies() == getPreviousIterationSpecies()) {
                    if (isNeedAdjustMaxMolecules()) {
                        String s = NetworkTransformer.getInsufficientMaxMoleculesMessage();
                        tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, s);
                        consoleNotificationList.add(tcm);
                        sc.firePropertyChange("appendToConsole", "", tcm);
                        sc.setInsufficientMaxMolecules(true);
                    } else {
                        sc.setInsufficientMaxMolecules(false);
                    }
                }
                break;
            case TaskEndNotificationOnly:
                System.out.println("TaskEndNotificationOnly");
                if (getPreviousIterationSpecies() > 0 && getCurrentIterationSpecies() > 0 && getCurrentIterationSpecies() != getPreviousIterationSpecies()) {
                    String s = NetworkTransformer.getInsufficientIterationsMessage();
                    tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, s);
                    consoleNotificationList.add(tcm);
                    sc.firePropertyChange("appendToConsole", "", tcm);
                }
                if (getPreviousIterationSpecies() > 0 && getCurrentIterationSpecies() > 0 && getCurrentIterationSpecies() == getPreviousIterationSpecies()) {
                    if (isNeedAdjustMaxMolecules()) {
                        String s = NetworkTransformer.getInsufficientMaxMoleculesMessage();
                        tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, s);
                        consoleNotificationList.add(tcm);
                        sc.firePropertyChange("appendToConsole", "", tcm);
                    }
                }
                // }
                break;
            case TaskEndAdjustSimulationContextFlagsOnly:
                System.out.println("TaskEndAdjustSimulationContextFlagsOnly");
                if (getPreviousIterationSpecies() > 0 && getCurrentIterationSpecies() > 0 && getCurrentIterationSpecies() != getPreviousIterationSpecies()) {
                    sc.setInsufficientIterations(true);
                } else {
                    sc.setInsufficientIterations(false);
                }
                if (getPreviousIterationSpecies() > 0 && getCurrentIterationSpecies() > 0 && getCurrentIterationSpecies() == getPreviousIterationSpecies()) {
                    if (isNeedAdjustMaxMolecules()) {
                        sc.setInsufficientMaxMolecules(true);
                    } else {
                        sc.setInsufficientMaxMolecules(false);
                    }
                }
                break;
            case // by user, fired by cancelButton_actionPerformed(...
            TaskStopped:
                System.out.println("Task stopped by user");
                tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, string);
                consoleNotificationList.add(tcm);
                sc.firePropertyChange("appendToConsole", "", tcm);
                // we can't evaluate the max iterations anymore
                previousIterationSpecies = 0;
                currentIterationSpecies = 0;
                // we don't know anymore if we need to adjust the max molecules or not
                needAdjustMaxMolecules = false;
                break;
            case // specific details, string will be processed, details extracted, formatted, etc
            Detail:
                processDetail(string);
                break;
            case // like above, but all details arrive in just one single shot, we can do some post processing
            DetailBatch:
                processDetail(string);
                String s = "";
                if (getPreviousIterationSpecies() != getCurrentIterationSpecies()) {
                    s = NetworkTransformer.getInsufficientIterationsMessage();
                    tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, s);
                    consoleNotificationList.add(tcm);
                    sc.firePropertyChange("appendToConsole", "", tcm);
                    sc.setInsufficientIterations(true);
                    needAdjustIterations = true;
                }
                if (getPreviousIterationSpecies() > 0 && getCurrentIterationSpecies() > 0 && getCurrentIterationSpecies() == getPreviousIterationSpecies()) {
                    if (isNeedAdjustMaxMolecules()) {
                        s = NetworkTransformer.getInsufficientMaxMoleculesMessage();
                        tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, s);
                        consoleNotificationList.add(tcm);
                        sc.firePropertyChange("appendToConsole", "", tcm);
                        sc.setInsufficientMaxMolecules(true);
                    }
                }
                break;
            case // normal notification, just display the string
            Notification:
                tcm = new TaskCallbackMessage(TaskCallbackStatus.Notification, string);
                consoleNotificationList.add(tcm);
                sc.firePropertyChange("appendToConsole", "", tcm);
                break;
            case Error:
                tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, string);
                consoleNotificationList.add(tcm);
                sc.firePropertyChange("appendToConsole", "", tcm);
                break;
            case Warning:
                tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, string);
                consoleNotificationList.add(tcm);
                sc.firePropertyChange("appendToConsole", "", tcm);
                break;
            // -------------------------- notification from the Multipass executor service
            case AdjustAllFlags:
                StringTokenizer flags = new StringTokenizer(string, ",");
                String token = flags.nextToken();
                previousIterationSpecies = Integer.parseInt(token);
                token = flags.nextToken();
                currentIterationSpecies = Integer.parseInt(token);
                token = flags.nextToken();
                if (!token.equals("0")) {
                    needAdjustMaxMolecules = true;
                }
                break;
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) BadLocationException(javax.swing.text.BadLocationException) TaskCallbackStatus(cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus)

Aggregations

TaskCallbackStatus (cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus)2 StringTokenizer (java.util.StringTokenizer)1 BadLocationException (javax.swing.text.BadLocationException)1 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)1 StyledDocument (javax.swing.text.StyledDocument)1