Package ca.nengo.ui.lib.objects.activities

Examples of ca.nengo.ui.lib.objects.activities.TrackedAction


    @Override
    protected void action() throws ActionException {

      name = JOptionPane.showInputDialog("Enter name of file to export to: ");

      (new TrackedAction("Exporting to matlab") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void action() throws ActionException {
View Full Code Here


            if (preConfigurationSuccess) {
                //setVisible(false);  // doing both this and dispose() seems to cause problems in OpenJDK (the setVisible(true) call never returns)
                dispose();

                (new TrackedAction("Configuring " + myConfigManager.getConfigurable().getTypeName()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void action() throws ActionException {
View Full Code Here

            file = NengoGraphics.FileChooser.getSelectedFile();

            if (blocking) {
                saveSuccessful = saveModel();
            } else {
                new TrackedAction("Saving model") {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void action() throws ActionException {
                        saveSuccessful = saveModel();
View Full Code Here

        int response = NengoGraphics.FileChooser.showOpenDialog();
        if (response == JFileChooser.APPROVE_OPTION) {
            file = NengoGraphics.FileChooser.getSelectedFile();


            TrackedAction loadActivity = new TrackedAction("Loading network") {
                private static final long serialVersionUID = 1L;

                @Override
                protected void action() throws ActionException {

                    if (file.getName().endsWith(".py")) {
                      try {
                        NengoGraphics.getInstance().getProgressIndicator().start("Running "+file.getPath());
                        NengoGraphics.getInstance().getScriptConsole().addVariable("scriptname", file.getPath());
                        NengoGraphics.getInstance().getPythonInterpreter().execfile(file.getPath());
                      } catch (RuntimeException e) {
                        if (e.toString()=="ca.nengo.ui.util.ScriptInterruptException") {
                         
                            NengoGraphics.getInstance().getProgressIndicator().stop();
                          UserMessages.showDialog("Stopped","Stopped opening "+file.getName());                         
                        } else {
                          UserMessages.showError("Runtime exception:<br>" + e);
                        }
                      }
                    return;
                     
                    }

                    try {
                        // loading Python-based objects requires using a
                        // PythonObjectInputStream from within a
                        // PythonInterpreter.
                        // loading sometimes fails if a new interpreter is
                        // created, so
                        // we use the one from the NengoGraphics.
                        PythonInterpreter pi = NengoGraphics.getInstance().getPythonInterpreter();
                        pi.set("___inStream",
                                new PythonObjectInputStream(new FileInputStream(file)));
                        org.python.core.PyObject obj = pi.eval("___inStream.readObject()");
                        objLoaded = obj.__tojava__(Class.forName("ca.nengo.model.Node"));
                        pi.exec("del ___inStream");

                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                if (objLoaded != null) {
                                    try {
                                        processLoadedObject(objLoaded);
                                    } catch (ActionException e) {
                                        UserMessages.showWarning("Could not add node: "
                                                + e.getMessage());
                                    }
                                }
                                objLoaded = null;

                            }
                        });
                     

                    } catch (IOException e) {
                        UserMessages.showError("IO Exception loading file");
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                        UserMessages.showError("Class not found");
                    } catch (ClassCastException e) {
                        UserMessages.showError("Incorrect file version");
                    } catch (OutOfMemoryError e) {
                        UserMessages.showError("Out of memory loading file");
                    } catch (org.python.core.PyException e) {
                        PyClass pyClass = (PyClass) e.type;
                        String value = e.value.toString();
                        if (pyClass.__name__.equals("ImportError")) {
                            if (value.equals("no module named main")) {
                                UserMessages.showError("Error: this file was "
                                        + "built using Python class definitions that "
                                        + "cannot be found.<br>To fix this problem, "
                                        + "make a 'main.py' file in 'simulator-ui/lib/Lib' "
                                        + "<br>and place the required python class definitions "
                                        + "inside.");
                            } else if (value.startsWith("no module named ")) {
                                UserMessages.showError("Error: this file was "
                                        + "built using Python class definitions in <br>a file "
                                        + "named " + value.substring(16) + ", which"
                                        + "cannot be found.<br>To fix this problem, please "
                                        + "place this file in 'simulator-ui/lib/Lib'.");
                            } else {
                                UserMessages.showError("Python error interpretting file:<br>" + e);
                            }
                        } else if (pyClass.__name__.equals("AttributeError")) {
                            String attr = value.substring(value.lastIndexOf(' ') + 1);
                            UserMessages.showError("Error: this file uses a Python "
                                    + "definition of the class " + attr + ", but this definition "
                                    + "cannot be found.<br>If this class was defined in a "
                                    + "separate .py file, please place this file in "
                                    + "'simulator-ui/lib/Lib'.<br>Otherwise, please place the "
                                    + "class definition in 'simulator-ui/lib/Lib/main.py' "
                                    + "and restart the simulator.");
                        } else {
                            UserMessages.showError("Python error interpretting file:<br>" + e);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        UserMessages.showError("Unexpected exception loading file");
                    }

                }

                @Override
                protected void postAction() {
                  super.postAction();
                }
               

            };
            loadActivity.doAction();
        }

    }
View Full Code Here

    clearCommand();
    setTypedText();

    final String initText=text;
   
        (new TrackedAction("Running...") {
            private static final long serialVersionUID = 1L;
           

            @Override
            protected void action() throws ActionException {
View Full Code Here

   
        returnVal = NengoGraphics.FileChooser.showSaveDialog();

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = NengoGraphics.FileChooser.getSelectedFile();
            new TrackedAction("Generating script") {
                private static final long serialVersionUID = 1L;

                @Override
                protected void action() throws ActionException {
                    saveSuccessful = generateScript();
View Full Code Here

TOP

Related Classes of ca.nengo.ui.lib.objects.activities.TrackedAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.