Adding more semantic when using Scilab command execution
Clément DAVID [Fri, 18 Dec 2009 16:49:47 +0000 (17:49 +0100)]
26 files changed:
scilab/modules/xcos/macros/xcosBlockEval.sci
scilab/modules/xcos/macros/xcosBlockInterface.sci
scilab/modules/xcos/src/java/org/scilab/modules/graph/ScilabGraph.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/CodeGenerationAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/CompileAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/DebugLevelAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/DumpAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/OpenAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/StartAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/StopAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/ViewDiagramBrowserAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/ViewInScicosAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/XcosDemonstrationsAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/XcosDocumentationAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/ContextUpdate.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/BlockDocumentationAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ViewDetailsAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicPortCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/BlockPalette.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/actions/LoadAsPalAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosComponent.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosFileType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosInterpreterManagement.java [new file with mode: 0644]

index 624ee6d..c134ee7 100644 (file)
@@ -42,5 +42,4 @@ function xcosBlockEval(hdf5FileToLoad, hdf5FileToSave, interfaceAlias, hdf5Conte
   [new_scs_m, y, typ] = interfaceAlias('set', scs_m, []);
 
        export_to_hdf5(hdf5FileToSave, "new_scs_m");
-       xcosNotify(hdf5FileToSave);
 endfunction
index 706f67c..85efa0d 100644 (file)
@@ -40,5 +40,4 @@ function xcosBlockInterface(hdf5FileToLoad, hdf5FileToSave, ...
 
   [new_scs_m, y, typ] = interfaceAlias(job, scs_m, []);
   export_to_hdf5(hdf5FileToSave, "new_scs_m");
-  xcosNotify(hdf5FileToSave);
 endfunction
index bb5666d..840d0e4 100644 (file)
@@ -19,7 +19,6 @@ import org.scilab.modules.graph.utils.ScilabGraphMessages;
 import org.scilab.modules.gui.tab.Tab;
 import org.scilab.modules.gui.utils.UIElementMapper;
 import org.scilab.modules.gui.window.ScilabWindow;
-import org.scilab.modules.localization.Messages;
 import org.scilab.modules.xcos.utils.XcosComponent;
 
 import com.mxgraph.swing.mxGraphComponent;
index 64e764a..b139f74 100644 (file)
@@ -20,7 +20,6 @@ import java.util.Map;
 
 import javax.swing.SwingUtilities;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.gui.tab.Tab;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.block.SuperBlock;
@@ -29,6 +28,7 @@ import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.palette.XcosPaletteManager;
 import org.scilab.modules.xcos.palette.actions.ViewPaletteBrowserAction;
 import org.scilab.modules.xcos.utils.ConfigXcosManager;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 
 public final class Xcos {
 
@@ -47,7 +47,7 @@ public final class Xcos {
     /** Palette creation */
     static {
        /* load scicos libraries (macros) */
-       InterpreterManagement.requestScilabExec("loadScicosLibs();");
+       XcosInterpreterManagement.requestScilabExec("loadScicosLibs();");
     }
 
     /**
index e8179a8..50dee54 100644 (file)
 
 package org.scilab.modules.xcos.actions;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.io.File;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
@@ -24,7 +25,7 @@ import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.block.SuperBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.io.BlockReader;
-import org.scilab.modules.xcos.utils.Signal;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 import com.mxgraph.util.mxConstants;
@@ -67,26 +68,26 @@ public class CodeGenerationAction extends DefaultAction {
            H5Write.writeInDataSet(file_id, "scs_m", block.getAsScilabObj());
            H5Write.closeFile(file_id);
            
-           InterpreterManagement.requestScilabExec("xcosCodeGeneration(\""+tempOutput.getAbsolutePath()+"\""+
-                   ", \""+tempInput.getAbsolutePath()+"\");");
-           Thread launchMe = new Thread() {
-               public void run() {
-                   Signal.wait(tempInput.getAbsolutePath());
-                   // Now read new Block
-                   BasicBlock modifiedBlock = BlockReader.readBlockFromFile(tempInput.getAbsolutePath());
-                   block.updateBlockSettings(modifiedBlock);
-                   block.setInterfaceFunctionName(modifiedBlock.getInterfaceFunctionName());
-                   block.setSimulationFunctionName(modifiedBlock.getSimulationFunctionName());
-                   block.setSimulationFunctionType(modifiedBlock.getSimulationFunctionType());
-                   block.setStyle("blockWithLabel");
-                   mxUtils.setCellStyles(block.getParentDiagram().getModel(),
-                           new Object[] {block}, mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
-                   block.setValue(block.getSimulationFunctionName());
-                   block.setChild(null);
-                   ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
-               }
-           };
-           launchMe.start();
+                       String command = "xcosCodeGeneration(\""
+                                       + tempOutput.getAbsolutePath() + "\"" + ", \""
+                                       + tempInput.getAbsolutePath() + "\");";
+           
+                       XcosInterpreterManagement.AsynchronousScilabExec(command, new ActionListener() {
+                               public void actionPerformed(ActionEvent arg0) {
+                                       // Now read new Block
+                                   BasicBlock modifiedBlock = BlockReader.readBlockFromFile(tempInput.getAbsolutePath());
+                                   block.updateBlockSettings(modifiedBlock);
+                                   block.setInterfaceFunctionName(modifiedBlock.getInterfaceFunctionName());
+                                   block.setSimulationFunctionName(modifiedBlock.getSimulationFunctionName());
+                                   block.setSimulationFunctionType(modifiedBlock.getSimulationFunctionType());
+                                   block.setStyle("blockWithLabel");
+                                   mxUtils.setCellStyles(block.getParentDiagram().getModel(),
+                                           new Object[] {block}, mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
+                                   block.setValue(block.getSimulationFunctionName());
+                                   block.setChild(null);
+                                   ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
+                               }
+                       });
        }
        
        catch (Exception e) {
index e2b1ff2..5ab2e0b 100644 (file)
 
 package org.scilab.modules.xcos.actions;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.io.File;
 import java.io.IOException;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.utils.Signal;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
@@ -63,13 +64,15 @@ public class CompileAction extends DefaultAction {
                                                temp = File.createTempFile("xcos", ".h5");
                                                temp.deleteOnExit();
                                                ((XcosDiagram) getGraph(null)).dumpToHdf5File(temp.getAbsolutePath());
-                                               InterpreterManagement.requestScilabExec(
-                                                               "import_from_hdf5(\"" + temp.getAbsolutePath() + "\");" +
-                                                               "xcos_compile(scs_m);" +
-                                                               "xcosNotify(\""+compilationEnd+"\");"
-                                               );
-                                               Signal.wait(compilationEnd);
-                                               ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
+                                               
+                                               String command = "import_from_hdf5(\"" + temp.getAbsolutePath() + "\");" +
+                                                                                "xcos_compile(scs_m);" +
+                                                                                "xcosNotify(\""+compilationEnd+"\");";
+                                               XcosInterpreterManagement.AsynchronousScilabExec(command, new ActionListener() {
+                                                       public void actionPerformed(ActionEvent arg0) {
+                                                               ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);   
+                                                       }
+                                               });
                                        } catch (IOException e) {
                                                e.printStackTrace();
                                        }
index 8d5c852..f18c15a 100644 (file)
@@ -33,11 +33,11 @@ import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.ListSelectionModel;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 public class DebugLevelAction extends DefaultAction {
@@ -150,7 +150,7 @@ public class DebugLevelAction extends DefaultAction {
                        public void actionPerformed(ActionEvent e) {
                                int value = ((DebugLevel)debugList.getSelectedValue()).getValue();
                                diagram.setDebugLevel(value);
-                               InterpreterManagement.requestScilabExec("scicos_debug("+value+");");
+                               XcosInterpreterManagement.SynchronousScilabExec("scicos_debug("+value+");");
                
                                mainFrame.dispose();
                        }
index 3fd757f..0b80c6a 100644 (file)
@@ -17,12 +17,12 @@ import java.awt.event.ActionEvent;
 import java.io.File;
 import java.io.IOException;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 public class DumpAction extends DefaultAction {
@@ -46,7 +46,7 @@ public class DumpAction extends DefaultAction {
            File temp = File.createTempFile("xcos",".h5");
            temp.deleteOnExit();
            ((XcosDiagram) getGraph(e)).dumpToHdf5File(temp.getAbsolutePath());
-           InterpreterManagement.requestScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");deletefile(\"" + temp.getAbsolutePath()+"\");");
+           XcosInterpreterManagement.SynchronousScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");deletefile(\"" + temp.getAbsolutePath()+"\");");
        } catch (IOException e1) {
            e1.printStackTrace();
        }
index ab31895..b24f611 100644 (file)
@@ -21,9 +21,7 @@ import javax.swing.KeyStroke;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
-import org.scilab.modules.gui.filechooser.FileChooser;
 import org.scilab.modules.gui.filechooser.ScilabFileChooser;
-import org.scilab.modules.gui.filechooser.SimpleFileChooser;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.gui.utils.SciFileFilter;
@@ -31,7 +29,6 @@ import org.scilab.modules.xcos.Xcos;
 import org.scilab.modules.xcos.XcosTab;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.utils.ConfigXcosManager;
-import org.scilab.modules.xcos.utils.XcosFileType;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
index 807e7ba..d12932d 100644 (file)
 package org.scilab.modules.xcos.actions;
 
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.io.File;
 import java.io.IOException;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xcos.XcosTab;
 import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.utils.Signal;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 public class StartAction  extends DefaultAction {
@@ -51,21 +51,19 @@ public class StartAction  extends DefaultAction {
        ((XcosDiagram) getGraph(null)).getParentTab().getInfoBar().draw();
        try {
            temp = File.createTempFile("xcos",".h5");
-           temp.deleteOnExit();
            ((XcosDiagram) getGraph(e)).getRootDiagram().dumpToHdf5File(temp.getAbsolutePath());
-           Thread launchMe = new Thread() {
-               public void run() {
-                   Signal.wait(simulationEnd);
-                   ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
-                   XcosTab.setStartEnabled(true);
-               }
-           };
-           launchMe.start();
-           InterpreterManagement.requestScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");"
-                   +"scicos_debug("+((XcosDiagram) getGraph(e)).getDebugLevel()+");"
-                   +"xcos_simulate(scs_m);"
-                   +"xcosNotify(\"" + simulationEnd + "\");"
-                   +"deletefile(\"" + temp.getAbsolutePath()+"\");");
+
+           String command = "import_from_hdf5(\""+temp.getAbsolutePath()+"\");"
+                                       +"scicos_debug("+((XcosDiagram) getGraph(e)).getDebugLevel()+");"
+                                       +"xcos_simulate(scs_m);"
+                                       +"xcosNotify(\"" + simulationEnd + "\");"
+                                       +"deletefile(\"" + temp.getAbsolutePath()+"\");";
+           XcosInterpreterManagement.AsynchronousScilabExec(command, new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
+                           XcosTab.setStartEnabled(true);
+                       }
+               });
        } catch (IOException e1) {
            e1.printStackTrace();
            XcosTab.setStartEnabled(true);
index 927dfd7..728d50e 100644 (file)
@@ -15,13 +15,13 @@ package org.scilab.modules.xcos.actions;
 
 import java.awt.event.ActionEvent;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xcos.XcosTab;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 public class StopAction extends DefaultAction {
@@ -41,7 +41,7 @@ public class StopAction extends DefaultAction {
        }
 
        public void actionPerformed(ActionEvent e) {
-               InterpreterManagement.requestScilabExec("haltscicos");
+               XcosInterpreterManagement.requestScilabExec("haltscicos");
                ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
                XcosTab.setStartEnabled(true);
        }
index 9cb009a..cafed01 100644 (file)
@@ -16,11 +16,11 @@ package org.scilab.modules.xcos.actions;
 import java.io.File;
 import java.io.IOException;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 
@@ -39,7 +39,7 @@ public class ViewDiagramBrowserAction extends DefaultAction {
                    File temp = File.createTempFile("xcos",".h5");
                    temp.deleteOnExit();
                    ((XcosDiagram) getGraph(null)).dumpToHdf5File(temp.getAbsolutePath());
-                   InterpreterManagement.requestScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");"
+                   XcosInterpreterManagement.SynchronousScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");"
                            +"tree_show(scs_m);"
                            +"deletefile(\"" + temp.getAbsolutePath()+"\");");
                } catch (IOException e1) {
index 8e65e47..7745c8f 100644 (file)
@@ -17,12 +17,12 @@ import java.awt.event.ActionEvent;
 import java.io.File;
 import java.io.IOException;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 public class ViewInScicosAction  extends DefaultAction {
@@ -45,7 +45,7 @@ public class ViewInScicosAction  extends DefaultAction {
                        temp = File.createTempFile("xcos",".h5");
                        temp.deleteOnExit();
                        ((XcosDiagram) getGraph(e)).dumpToHdf5File(temp.getAbsolutePath());
-                       InterpreterManagement.requestScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");scicos(scs_m);deletefile(\"" + temp.getAbsolutePath()+"\");");
+                       XcosInterpreterManagement.SynchronousScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");scicos(scs_m);deletefile(\"" + temp.getAbsolutePath()+"\");");
                } catch (IOException e1) {
                        e1.printStackTrace();
                }
index 6963da2..62c99db 100644 (file)
@@ -14,11 +14,11 @@ package org.scilab.modules.xcos.actions;
 
 import java.awt.event.ActionEvent;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
@@ -61,6 +61,6 @@ public final class XcosDemonstrationsAction extends DefaultAction {
         * @see org.scilab.modules.gui.events.callback.CallBack#actionPerformed(java.awt.event.ActionEvent)
         */
        public void actionPerformed(ActionEvent e) {
-               InterpreterManagement.requestScilabExec("exec(\"" + System.getenv("SCI") + "/modules/xcos/demos/xcos_demos.sce\", -1)");
+               XcosInterpreterManagement.requestScilabExec("exec(\"" + System.getenv("SCI") + "/modules/xcos/demos/xcos_demos.sce\", -1)");
        }
 }
index c4749dd..6264b51 100644 (file)
@@ -14,11 +14,11 @@ package org.scilab.modules.xcos.actions;
 
 import java.awt.event.ActionEvent;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
@@ -61,7 +61,7 @@ public final class XcosDocumentationAction extends DefaultAction {
         * @see org.scilab.modules.gui.events.callback.CallBack#actionPerformed(java.awt.event.ActionEvent)
         */
        public void actionPerformed(ActionEvent e) {
-               InterpreterManagement.requestScilabExec("help xcos");
+               XcosInterpreterManagement.requestScilabExec("help xcos");
        }
 
 }
index 0987faa..f7d7a29 100644 (file)
@@ -14,6 +14,8 @@ package org.scilab.modules.xcos.block;
 
 
 import java.awt.MouseInfo;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
@@ -22,7 +24,6 @@ import java.util.Map;
 
 import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.CopyAction;
 import org.scilab.modules.graph.actions.CutAction;
@@ -64,9 +65,9 @@ import org.scilab.modules.xcos.port.control.ControlPort;
 import org.scilab.modules.xcos.port.input.InputPort;
 import org.scilab.modules.xcos.port.output.OutputPort;
 import org.scilab.modules.xcos.utils.BlockPositioning;
-import org.scilab.modules.xcos.utils.Signal;
 import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosEvent;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 import com.mxgraph.model.mxGeometry;
@@ -608,19 +609,16 @@ public class BasicBlock extends XcosUIDObject {
            cmd += ", \"set\"";
            cmd += ", \""+tempContext.getAbsolutePath()+"\");";
            
-           InterpreterManagement.putCommandInScilabQueue(cmd);
            final BasicBlock currentBlock = this;
-           Thread launchMe = new Thread() {
-               public void run() {
-                   Signal.wait(tempInput.getAbsolutePath());
-                   // Now read new Block
-                   BasicBlock modifiedBlock = BlockReader.readBlockFromFile(tempInput.getAbsolutePath());
-                   updateBlockSettings(modifiedBlock);
-                   getParentDiagram().fireEvent(XcosEvent.ADD_PORTS, new mxEventObject(new Object[] {currentBlock}));
-                   setLocked(false);
-               }
-           };
-           launchMe.start();
+           XcosInterpreterManagement.AsynchronousScilabExec(cmd, new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               // Now read new Block
+                           BasicBlock modifiedBlock = BlockReader.readBlockFromFile(tempInput.getAbsolutePath());
+                           updateBlockSettings(modifiedBlock);
+                           getParentDiagram().fireEvent(XcosEvent.ADD_PORTS, new mxEventObject(new Object[] {currentBlock}));
+                           setLocked(false);
+                       }
+               });
            setLocked(true);
 
        } catch (IOException e) {
@@ -800,7 +798,7 @@ public class BasicBlock extends XcosUIDObject {
            private static final long serialVersionUID = -1480947262397441951L;
 
            public void callBack() {
-               InterpreterManagement.requestScilabExec("help " + getInterfaceFunctionName());
+               XcosInterpreterManagement.requestScilabExec("help " + getInterfaceFunctionName());
            }
        });
        menu.add(help);
index 8eb60dd..ec718a8 100644 (file)
@@ -3,9 +3,8 @@ package org.scilab.modules.xcos.block;
 import java.io.File;
 import java.io.IOException;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.xcos.io.BlockReader;
-import org.scilab.modules.xcos.utils.Signal;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 
 public abstract class ContextUpdate extends BasicBlock{
 
@@ -71,8 +70,7 @@ public abstract class ContextUpdate extends BasicBlock{
            cmd += ", \""+tempContext.getAbsolutePath()+"\");";
 
            synchronized (_mutex_) {
-               InterpreterManagement.putCommandInScilabQueue(cmd);
-               Signal.wait(tempInput.getAbsolutePath());
+               XcosInterpreterManagement.SynchronousScilabExec(cmd);
                BasicBlock modifiedBlock = BlockReader.readBlockFromFile(tempInput.getAbsolutePath());
                updateBlockSettings(modifiedBlock);
            }
index 02e2906..d30f4b2 100644 (file)
@@ -14,7 +14,6 @@ package org.scilab.modules.xcos.block.actions;
 
 import java.awt.event.ActionEvent;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
@@ -22,6 +21,7 @@ import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.utils.XcosDialogs;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
@@ -66,7 +66,7 @@ public final class BlockDocumentationAction extends DefaultAction {
        public void actionPerformed(ActionEvent e) {
                BasicBlock selectedBlock = ((BasicBlock) getGraph(e).getSelectionCell());
                if (selectedBlock != null) {
-                       InterpreterManagement.requestScilabExec("help " + selectedBlock.getInterfaceFunctionName());
+                       XcosInterpreterManagement.requestScilabExec("help " + selectedBlock.getInterfaceFunctionName());
                } else {
                        XcosDialogs.noBlockSelected((XcosDiagram) getGraph(e));
                }
index 8d915b2..fcd9bac 100644 (file)
@@ -15,7 +15,6 @@ package org.scilab.modules.xcos.block.actions;
 
 import java.io.File;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.menuitem.MenuItem;
@@ -25,6 +24,7 @@ import org.scilab.modules.xcos.block.SplitBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.io.BasicBlockInfo;
 import org.scilab.modules.xcos.link.BasicLink;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 
@@ -53,7 +53,7 @@ public class ViewDetailsAction extends DefaultAction {
                    int file_id = H5Write.createFile(temp.getAbsolutePath());
                    H5Write.writeInDataSet(file_id, "scs_m", BasicBlockInfo.getAsScilabObj((BasicBlock) selectedCells[i]));
                    H5Write.closeFile(file_id);
-                   InterpreterManagement.requestScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");tree_show(scs_m);deletefile(\"" + temp.getAbsolutePath()+"\");");
+                   XcosInterpreterManagement.SynchronousScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");tree_show(scs_m);deletefile(\"" + temp.getAbsolutePath()+"\");");
                }
                catch (Exception e) {
                    // Do Nothing !!!
@@ -66,7 +66,7 @@ public class ViewDetailsAction extends DefaultAction {
                    int file_id = H5Write.createFile(temp.getAbsolutePath());
                    H5Write.writeInDataSet(file_id, "scs_m", ((BasicLink) selectedCells[i]).getAsScilabObj());
                    H5Write.closeFile(file_id);
-                   InterpreterManagement.requestScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");tree_show(scs_m);deletefile(\"" + temp.getAbsolutePath()+"\");");;
+                   XcosInterpreterManagement.SynchronousScilabExec("import_from_hdf5(\""+temp.getAbsolutePath()+"\");tree_show(scs_m);deletefile(\"" + temp.getAbsolutePath()+"\");");;
                }
                catch (Exception e) {
                    // Do Nothing !!!
index 45cd258..4e87d22 100644 (file)
@@ -28,8 +28,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
-import java.util.logging.Logger;
-
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
index 76c212f..b3d980d 100644 (file)
@@ -16,14 +16,12 @@ package org.scilab.modules.xcos.io.codec;
 import java.util.Map;
 
 import org.scilab.modules.xcos.block.BasicBlock;
-import org.scilab.modules.xcos.block.SplitBlock;
 import org.scilab.modules.xcos.io.XcosObjectCodec;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
 import com.mxgraph.io.mxCodec;
-import com.mxgraph.model.mxICell;
 
 public class BasicPortCodec extends XcosObjectCodec {
 
index 25e0274..8a85880 100644 (file)
@@ -27,7 +27,6 @@ import javax.swing.SwingUtilities;
 import javax.swing.border.Border;
 
 import org.flexdock.plaf.common.border.ShadowBorder;
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
 import org.scilab.modules.gui.contextmenu.ContextMenu;
 import org.scilab.modules.gui.contextmenu.ScilabContextMenu;
@@ -42,6 +41,7 @@ import org.scilab.modules.xcos.block.TextBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.io.BlockReader;
 import org.scilab.modules.xcos.utils.XcosConstants;
+import org.scilab.modules.xcos.utils.XcosInterpreterManagement;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 import com.mxgraph.swing.util.mxGraphTransferable;
@@ -152,7 +152,7 @@ public class BlockPalette extends JLabel {
                                                private static final long serialVersionUID = -8720228686621887887L;
 
                                                public void callBack() {
-                                                       InterpreterManagement.requestScilabExec("help " + BlockPalette.this.getText());
+                                                       XcosInterpreterManagement.requestScilabExec("help " + BlockPalette.this.getText());
                                                }
                                        });
                                        menu.add(help);
index ab93371..c639a97 100644 (file)
@@ -9,13 +9,11 @@ import javax.swing.KeyStroke;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
-import org.scilab.modules.gui.filechooser.FileChooser;
 import org.scilab.modules.gui.filechooser.ScilabFileChooser;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.gui.utils.SciFileFilter;
 import org.scilab.modules.xcos.palette.XcosPaletteManager;
-import org.scilab.modules.xcos.utils.XcosFileType;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
 public class LoadAsPalAction extends DefaultAction {
index 3a6342f..44c6b0f 100644 (file)
@@ -8,7 +8,6 @@ import java.awt.event.ComponentListener;
 import org.scilab.modules.xcos.graph.PaletteDiagram;
 
 import com.mxgraph.swing.mxGraphComponent;
-import com.mxgraph.util.mxRectangle;
 import com.mxgraph.view.mxGraph;
 import com.mxgraph.view.mxGraphView;
 
index 6806513..0eec9b2 100644 (file)
@@ -17,8 +17,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Arrays;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
-
 /**
  * All the filetype recognized by Xcos.
  */
@@ -184,11 +182,10 @@ public enum XcosFileType {
                String cmd = "scs_m = importScicosDiagram(\"" + filename.getAbsolutePath() + "\");";
                cmd += "export_to_hdf5(\"" + tempOutput.getAbsolutePath() + "\", \"scs_m\");";
                cmd += "xcosNotify(\"" + tempOutput.getAbsolutePath() + "\");";
-               InterpreterManagement.requestScilabExec(cmd);
+               XcosInterpreterManagement.SynchronousScilabExec(cmd);
            } catch (IOException e) {
                e.printStackTrace();
            }
-           Signal.wait(tempOutput.getAbsolutePath());
            return tempOutput;
        }
 }
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosInterpreterManagement.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosInterpreterManagement.java
new file mode 100644 (file)
index 0000000..73fc308
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2009 - DIGITEO - Clément DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos.utils;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+import javax.swing.SwingUtilities;
+
+import org.scilab.modules.action_binding.InterpreterManagement;
+
+/**
+ * Implements useful methods to communicate with the Scilab interpreter.
+ */
+public class XcosInterpreterManagement extends InterpreterManagement {
+
+       private static Executor executor = Executors.newSingleThreadExecutor();
+
+       private XcosInterpreterManagement() {
+               // full static class so private constructor
+       }
+
+       /**
+        * Execute the command and wait for the end of the execution.
+        * 
+        * @param command
+        *            The scilab command
+        * @return Status of the execution
+        */
+       public static int SynchronousScilabExec(String command) {
+               final String uid = Integer.toString(command.hashCode());
+               
+               command += ";xcosNotify(\"" + uid + "\");";
+               int ret = InterpreterManagement.requestScilabExec(command);
+               Signal.wait(uid);
+               return ret;
+       }
+
+       /**
+        * Execute the command asynchronously and call the callback actionPerformed
+        * method when the execution ends.
+        * 
+        * The ActionEvent send to the callback actionPerformed method is composed
+        * of :
+        * <ul>
+        * <li>source: The XcosInterpreterManagement.class value which is unique.</li>
+        * <li>id: the command.hashCode() value use it to compare to your own.</li>
+        * <li>command: the command passed to the interpreter.</li>
+        * </ul>
+        * 
+        * Note: the callback is called on the EDT thread so your are free to
+        * manipulate AWT/SWING objects on it.
+        * 
+        * @param command
+        *            The command to execute
+        * @param callback
+        *            The callback which is called at the end of the execution.
+        */
+       public static void AsynchronousScilabExec(final String command,
+                       final ActionListener callback) {
+               final int uid = command.hashCode();
+               final String uidDesc = Integer.toString(uid);
+               final String fullCommand = command + ";xcosNotify(\"" + uidDesc + "\");";
+               final ActionEvent event = new ActionEvent(
+                               XcosInterpreterManagement.class, uid, command);
+
+               executor.execute(new Runnable() {
+                       public void run() {
+                               InterpreterManagement.putCommandInScilabQueue(fullCommand);
+                               Signal.wait(Integer.toString(uid));
+                               SwingUtilities.invokeLater(new Runnable() {
+                                       public void run() {
+                                               callback.actionPerformed(event);
+                                       }
+                               });
+                       }
+               });
+       }
+}