Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public void actionPerformed(ActionEvent e) {
    final XcosDiagram parentGraph = (XcosDiagram) getGraph(e);

    // action disabled when the cell is edited
    final ScilabComponent comp = ((ScilabComponent) parentGraph.getAsComponent());
    if (comp.isEditing()) {
      return;
    }

    parentGraph.info(XcosMessages.GENERATE_SUPERBLOCK);
    parentGraph.getModel().beginUpdate();
    try {

      final SuperBlock superBlock;
      final Collection<Broken> brokenLinks;
      final Set<Object> inSelectionCells;

      /*
       * Allocate superBlock
       */
      final Object[] selection = parentGraph.getSelectionCells();
      final Object[] blocks = XcosDiagram.filterByClass(selection, BasicBlock.class);
      inSelectionCells = new LinkedHashSet<Object>(Arrays.asList(blocks));

      superBlock = allocateSuperBlock(parentGraph, selection);

      /*
       * First perform all modification on the parent diagram to handle
       * well undo/redo operations.
       */
      brokenLinks = updateParent(parentGraph, superBlock, inSelectionCells);

      /*
       * Then move some cells to the child diagram
       */
      final SuperBlockDiagram childGraph =
          moveToChild(parentGraph, superBlock, brokenLinks, inSelectionCells);

      /*
       * Finish the install on the child and sync it.
       */
      childGraph.installListeners();
      childGraph.installSuperBlockListeners();
      superBlock.invalidateRpar();

      Xcos.getInstance().addDiagram(parentGraph.getSavedFile(), childGraph);
    } finally {
      parentGraph.getModel().endUpdate();
      parentGraph.info(XcosMessages.EMPTY_INFO);
    }
  }
Ejemplo n.º 2
0
  /**
   * @param e parameter
   * @see
   *     org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    final XcosDiagram graph = (XcosDiagram) getGraph(e);

    // action disabled when the cell is edited
    final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
    if (comp.isEditing()) {
      return;
    }

    graph.info(XcosMessages.EXPORT_IN_PROGRESS);

    final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
    if (handler == null) {
      return;
    }
    (new SwingWorker<Void, Void>() {

          @Override
          protected Void doInBackground() {
            try {
              handler.writeDiagram(((XcosDiagram) getGraph(null)));
              ((XcosDiagram) getGraph(null)).setReadOnly(true);
            } catch (Exception e) {
              cancel(true);
            }
            return null;
          }

          @Override
          protected void done() {
            if (isCancelled()) {
              graph.info(XcosMessages.EMPTY_INFO);

              handler.release();
              return;
            }

            graph.info(XcosMessages.COMPILATION_IN_PROGRESS);
            String cmd = "cpr = xcos_compile(scs_m);";

            final ActionListener action =
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    graph.setReadOnly(false);
                    graph.info(XcosMessages.EMPTY_INFO);

                    handler.release();
                  }
                };

            try {
              ScilabInterpreterManagement.asynchronousScilabExec(action, cmd);
            } catch (InterpreterException e) {
              Logger.getLogger(CompileAction.class.getName()).severe(e.toString());

              handler.release();
            }
          }
        })
        .execute();
  }