2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 package org.scilab.modules.xcos.block;
15 import java.awt.MouseInfo;
16 import java.io.Serializable;
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.Collections;
20 import java.util.Comparator;
21 import java.util.Deque;
22 import java.util.HashMap;
23 import java.util.LinkedList;
24 import java.util.List;
26 import java.util.Optional;
29 import org.apache.batik.css.engine.StyleMap;
30 import org.scilab.modules.action_binding.InterpreterManagement;
31 import org.scilab.modules.graph.ScilabGraph;
32 import org.scilab.modules.graph.ScilabGraphUniqueObject;
33 import org.scilab.modules.graph.actions.CopyAction;
34 import org.scilab.modules.graph.actions.CutAction;
35 import org.scilab.modules.graph.actions.DeleteAction;
36 import org.scilab.modules.graph.actions.base.DefaultAction;
37 import org.scilab.modules.graph.utils.ScilabGraphConstants;
38 import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
39 import org.scilab.modules.gui.contextmenu.ContextMenu;
40 import org.scilab.modules.gui.contextmenu.ScilabContextMenu;
41 import org.scilab.modules.gui.events.callback.CommonCallBack;
42 import org.scilab.modules.gui.menu.Menu;
43 import org.scilab.modules.gui.menu.ScilabMenu;
44 import org.scilab.modules.gui.menuitem.MenuItem;
45 import org.scilab.modules.gui.menuitem.ScilabMenuItem;
46 import org.scilab.modules.xcos.JavaController;
47 import org.scilab.modules.xcos.Kind;
48 import org.scilab.modules.xcos.ObjectProperties;
49 import org.scilab.modules.xcos.Xcos;
50 import org.scilab.modules.xcos.XcosTab;
51 import org.scilab.modules.xcos.actions.EditFormatAction;
52 import org.scilab.modules.xcos.actions.ShowHideShadowAction;
53 import org.scilab.modules.xcos.block.actions.BlockDocumentationAction;
54 import org.scilab.modules.xcos.block.actions.BlockParametersAction;
55 import org.scilab.modules.xcos.block.actions.BorderColorAction;
56 import org.scilab.modules.xcos.block.actions.FilledColorAction;
57 import org.scilab.modules.xcos.block.actions.FlipAction;
58 import org.scilab.modules.xcos.block.actions.MirrorAction;
59 import org.scilab.modules.xcos.block.actions.RegionToSuperblockAction;
60 import org.scilab.modules.xcos.block.actions.RotateAction;
61 import org.scilab.modules.xcos.block.actions.ViewDetailsAction;
62 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockAction;
63 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionBottom;
64 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionCenter;
65 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionLeft;
66 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionMiddle;
67 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionRight;
68 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionTop;
69 import org.scilab.modules.xcos.graph.XcosDiagram;
70 import org.scilab.modules.xcos.graph.model.XcosCell;
71 import org.scilab.modules.xcos.io.scicos.BasicBlockInfo;
72 import org.scilab.modules.xcos.port.BasicPort;
73 import org.scilab.modules.xcos.port.command.CommandPort;
74 import org.scilab.modules.xcos.port.control.ControlPort;
75 import org.scilab.modules.xcos.port.input.InputPort;
76 import org.scilab.modules.xcos.port.output.OutputPort;
77 import org.scilab.modules.xcos.utils.BlockPositioning;
78 import org.scilab.modules.xcos.utils.XcosConstants;
79 import org.scilab.modules.xcos.utils.XcosMessages;
81 import com.mxgraph.model.mxGeometry;
82 import com.mxgraph.model.mxICell;
85 * A block on the diagram
87 @SuppressWarnings(value = { "serial" })
88 public class BasicBlock extends XcosCell implements Serializable {
90 * Sorted kind of input, useful to sort them by kind
92 private static final Class<?>[] sortedChildrenClass = {InputPort.class, OutputPort.class, ControlPort.class, CommandPort.class, Object.class};
99 * Default interface function name
101 public static final String DEFAULT_INTERFACE_FUNCTION = "xcos_block";
103 * Default simulation function name
105 public static final String DEFAULT_SIMULATION_FUNCTION = "xcos_simulate";
111 private static final double DEFAULT_POSITION_X = 10.0;
112 private static final double DEFAULT_POSITION_Y = 10.0;
113 private static final double DEFAULT_WIDTH = 40.0;
114 private static final double DEFAULT_HEIGHT = 40.0;
117 * Sort the children list in place.
119 * The sort put inputs then outputs the control then command ports. The
120 * local port order is preserved.The sort is performed in place and do not
125 * the children to sort
127 public static final void sort(List<?> children) {
128 final List<Object> reference = new ArrayList<Object>(children);
130 Collections.sort(children, new Comparator<Object>() {
132 public int compare(Object o1, Object o2) {
133 // diff is the major sorting by kind
134 int diff = compareByChildClass(o1, o2);
135 if (o1 instanceof BasicPort && o2 instanceof BasicPort) {
136 // first sort with the port list index
137 final int diffIndexOf = Integer.signum(reference.indexOf(o1) - reference.indexOf(o2));
138 // then sort with the ordering value
139 final int diffOrdering = Integer.signum(((BasicPort) o1).getOrdering() - ((BasicPort) o2).getOrdering());
140 // then sort with the port position value
141 final mxGeometry o1Geom = ((BasicPort) o1).getGeometry();
142 final mxGeometry o2Geom = ((BasicPort) o2).getGeometry();
143 final int diffPosition = Integer.signum((int) (o2Geom.getX() - o1Geom.getX() - o2Geom.getY() + o1Geom.getY()));
145 // voting is performed with these equivalent 3 selector
146 diff = diff + diffIndexOf + diffOrdering + diffPosition;
155 * Internal method to get a base index to compare with depending on the cell
160 * @return the base index
162 private static final int compareByChildClass(final Object o1, final Object o2) {
166 for (int i = 0; i < sortedChildrenClass.length; i++) {
167 final Class<?> klass = sortedChildrenClass[i];
169 if (klass.isInstance(o1)) {
174 for (int i = 0; i < sortedChildrenClass.length; i++) {
175 final Class<?> klass = sortedChildrenClass[i];
177 if (klass.isInstance(o2)) {
183 final int base = o1Index - o2Index;
184 return base * (Integer.MAX_VALUE / sortedChildrenClass.length);
187 private boolean locked;
190 * Represent a simulation function type compatible with Scilab/Scicos
191 * function type descriptors.
193 public static enum SimulationFunctionType {
194 /** event select; reduced at compilation */
196 /** if then else; reduced at compilation */
198 /** first common block */
200 /** first native block */
202 /** second native block */
204 /** third native block */
206 /** forth native block */
212 /** dynamic {@link #TYPE_1} Fortran blocks (fortran_block.sci) */
213 DYNAMIC_FORTRAN_1(1001.0),
214 /** dynamic {@link #TYPE_1} C blocks (c_block.sci) */
216 /** Explicit dynamic {@link #TYPE_4} blocks (CBLOCK.sci) */
217 DYNAMIC_EXPLICIT_4(2004.0),
218 /** Implicit {@link #TYPE_1} Fortran blocks (DIFF_f.sci) */
220 /** Implicit {@link #C_OR_FORTRAN} blocks */
221 IMPLICIT_C_OR_FORTRAN(10004.0),
222 /** Implicit dynamic {@link #TYPE_4} blocks (CBLOCK.sci) */
223 DYNAMIC_IMPLICIT_4(12004.0),
224 /** Modelica {@link #C_OR_FORTRAN} blocks */
229 private double value;
232 * Default constructor
235 * Scilab/Scicos function type descriptor
237 private SimulationFunctionType(double scilabValue) {
242 * Get the Java descriptor from the Scilab descriptor.
245 * Scilab/Scicos function type descriptor
246 * @return The corresponding java descriptor
248 public static SimulationFunctionType convertScilabValue(int scilabValue) {
249 for (SimulationFunctionType iter : SimulationFunctionType.values()) {
250 if (iter.getAsDouble() == scilabValue) {
258 * Get the Scilab Descriptor from the Java Descriptor
260 * @return The corresponding Scilab/Scicos descriptor
262 public double getAsDouble() {
267 public BasicBlock(long uid) {
268 this(uid, Kind.BLOCK);
272 * Default constructor.
274 public BasicBlock(long uid, Kind kind) {
278 * Default parameters for blocks
282 this.connectable = false;
283 this.geometry = new mxGeometry(DEFAULT_POSITION_X, DEFAULT_POSITION_Y, DEFAULT_WIDTH, DEFAULT_HEIGHT);
287 * @return the parent diagram of this graphical object
289 public XcosDiagram getParentDiagram() {
291 * Retrieve the parent
293 long[] parentBlock = new long[0];
294 long[] parentDiagram = new long[0];
295 JavaController controller = new JavaController();
296 controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.PARENT_BLOCK, parentBlock);
297 controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.PARENT_DIAGRAM, parentDiagram);
301 if (parentBlock[0] == 0l) {
302 parent = parentDiagram[0];
305 parent = parentBlock[0];
310 * Retrieve and create on demand the corresponding Diagram
313 Collection<XcosDiagram> diagrams = Xcos.getInstance().getDiagrams(parentDiagram[0]);
314 Optional<XcosDiagram> optDiagram = diagrams.stream().filter(d -> d.getUID() == parent).findFirst();
315 if (optDiagram.isPresent()) {
316 diagram = optDiagram.get();
318 diagram = new XcosDiagram(parent, kind);
319 Xcos.getInstance().addDiagram(parentDiagram[0], diagram);
326 * @return locked status
328 public synchronized boolean isLocked() {
334 * change locked status
336 public synchronized void setLocked(boolean locked) {
337 this.locked = locked;
341 * Update the children of the block.
343 * @param modifiedBlock
344 * the new block instance
346 private void updateChildren(BasicBlock modifiedBlock) {
347 // if (modifiedBlock == null) {
351 // XcosDiagram graph = getParentDiagram();
352 // if (graph == null) {
353 // setParentDiagram(Xcos.findParent(this));
354 // graph = getParentDiagram();
355 // LOG.finest(PARENT_DIAGRAM_WAS_NULL);
359 // * Checked as port classes only
361 // @SuppressWarnings("unchecked")
362 // Set < Class <? extends mxICell >> types = new HashSet < Class <? extends mxICell >> (Arrays.asList(InputPort.class, OutputPort.class, ControlPort.class,
363 // CommandPort.class));
365 // Map < Class <? extends mxICell > , Deque<mxICell >> annotatedOlds = getTypedChildren(types);
366 // Map < Class <? extends mxICell > , Deque<mxICell >> annotatedNews = modifiedBlock.getTypedChildren(types);
368 // getParentDiagram().getModel().beginUpdate();
370 // for (Class <? extends mxICell > klass : types) {
371 // final Deque<mxICell> olds = annotatedOlds.get(klass);
372 // final Deque<mxICell> news = annotatedNews.get(klass);
375 // while (!olds.isEmpty() && !news.isEmpty()) {
376 // mxICell previous = olds.poll();
377 // mxICell modified = news.poll();
379 // final int previousIndex = children.indexOf(previous);
382 // if (previous.getEdgeCount() != 0) {
383 // final mxICell edge = previous.getEdgeAt(0);
384 // final boolean isOutgoing = previous == edge.getTerminal(true);
385 // previous.removeEdge(edge, isOutgoing);
386 // modified.insertEdge(edge, isOutgoing);
389 // getParentDiagram().removeCells(new Object[] { previous }, false);
390 // getParentDiagram().addCells(new Object[] { modified }, this, previousIndex);
392 // // Clone the geometry to avoid empty geometry on new cells.
393 // getParentDiagram().getModel().setGeometry(modified, (mxGeometry) previous.getGeometry().clone());
398 // if (!olds.isEmpty()) {
399 // getParentDiagram().removeCells(olds.toArray(), true);
403 // if (!news.isEmpty()) {
404 // getParentDiagram().addCells(news.toArray(), this);
408 // getParentDiagram().getModel().endUpdate();
413 * Format the children as a typed map for the given class set.
416 * the classes to search for.
417 * @return a map which linked foreach type the corresponding cell list.
419 private Map < Class <? extends mxICell > , Deque<mxICell >> getTypedChildren(Set < Class <? extends mxICell >> types) {
420 Map < Class <? extends mxICell > , Deque<mxICell >> oldPorts = new HashMap < Class <? extends mxICell > , Deque<mxICell >> ();
422 // Allocate all types set
423 for (Class <? extends mxICell > type : types) {
424 oldPorts.put(type, new LinkedList<mxICell>());
427 if (getChildCount() <= 0) {
431 // sort children according to the ordering parameter (useful on
432 // scilab-5.2.x diagrams)
436 for (Object cell : children) {
438 Class <? extends Object > klass = cell.getClass();
439 while (klass != null) {
440 if (types.contains(klass)) {
443 klass = klass.getSuperclass();
446 final Deque<mxICell> current = oldPorts.get(klass);
447 if (current != null) {
448 current.add((mxICell) cell);
456 * Sort the children list in place.
458 * The sort put inputs then outputs the control then command ports. The
459 * local port order is preserved.The sort is performed in place and do not
462 public void sortChildren() {
463 if (getChildCount() <= 0) {
472 * parent diagram context
474 public void openBlockSettings() {
475 // FIXME: implement something
476 // final XcosDiagram graph;
477 // if (getParentDiagram() == null) {
478 // setParentDiagram(Xcos.findParent(this));
479 // graph = getParentDiagram();
480 // LOG.finest(PARENT_DIAGRAM_WAS_NULL);
482 // graph = getParentDiagram();
484 // if (graph instanceof PaletteDiagram) {
488 // if (context == null) {
489 // throw new IllegalArgumentException();
492 // // prevent to open twice
497 // graph.setCellsLocked(true);
498 // graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
500 // // sort children according to the ordering parameter (useful on
501 // // scilab-5.2.x diagrams)
504 // final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
505 // if (handler == null) {
511 // handler.writeBlock(this);
513 // handler.writeContext(context);
515 // final ActionListener action = new ActionListener() {
517 // public void actionPerformed(ActionEvent e) {
518 // LOG.finest("Updating data.");
520 // graph.getView().clear(this, true, true);
522 // // Now read new Block
523 // graph.getModel().beginUpdate();
525 // final BasicBlock modifiedBlock = handler.readBlock();
526 // updateBlockSettings(modifiedBlock);
528 // graph.fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, BasicBlock.this));
529 // } catch (ScicosFormatException ex) {
530 // LOG.severe(ex.toString());
532 // graph.getModel().endUpdate();
535 // handler.release();
537 // graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
538 // graph.setCellsLocked(false);
544 // ScilabInterpreterManagement.asynchronousScilabExec(action, "blk = xcosBlockInterface", getInterfaceFunctionName().toCharArray(), "set",
545 // ScilabDirectHandler.BLK.toCharArray(), ScilabDirectHandler.CONTEXT.toCharArray());
546 // } catch (InterpreterException e) {
547 // LOG.severe(e.toString());
550 // handler.release();
552 // graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
553 // graph.setCellsLocked(false);
558 * @return tooltip text
560 public String getToolTipText() {
561 StringBuilder result = new StringBuilder();
562 result.append(ScilabGraphConstants.HTML_BEGIN);
564 JavaController controller = new JavaController();
566 String[] interfaceFunctionName = new String[1];
567 controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunctionName);
568 String[] simulationFunctionName = new String[1];
569 controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.SIM_FUNCTION_NAME, simulationFunctionName);
571 result.append("Block Name : " + interfaceFunctionName[0] + ScilabGraphConstants.HTML_NEWLINE);
572 result.append("Simulation : " + simulationFunctionName[1] + ScilabGraphConstants.HTML_NEWLINE);
574 // if (getParentDiagram() instanceof PaletteDiagram) {
575 // if (getIntegerParameters() != null) {
576 // result.append("Integer parameters : " + getIntegerParameters() + ScilabGraphConstants.HTML_NEWLINE);
579 // if (getRealParameters() != null && getRealParameters().getHeight() != 0 && getRealParameters().getWidth() != 0) {
580 // result.append("Real parameters : " + getRealParameters() + ScilabGraphConstants.HTML_NEWLINE);
583 // if (getObjectsParameters() != null) {
584 // result.append("Object parameters : " + getObjectsParameters() + ScilabGraphConstants.HTML_NEWLINE);
587 result.append("UID : " + getId() + ScilabGraphConstants.HTML_NEWLINE);
588 final int length = getStyle().length();
589 result.append("Style : ");
590 if (length > XcosConstants.MAX_CHAR_IN_STYLE) {
591 result.append(getStyle().substring(0, XcosConstants.MAX_CHAR_IN_STYLE));
592 result.append(XcosMessages.DOTS);
594 result.append(getStyle());
596 result.append(ScilabGraphConstants.HTML_NEWLINE);
597 result.append("Input ports : " + BasicBlockInfo.getAllTypedPorts(this, false, InputPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
598 result.append("Output ports : " + BasicBlockInfo.getAllTypedPorts(this, false, OutputPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
599 result.append("Control ports : " + BasicBlockInfo.getAllTypedPorts(this, false, ControlPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
600 result.append("Command ports : " + BasicBlockInfo.getAllTypedPorts(this, false, CommandPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
603 result.append("x : " + getGeometry().getX() + ScilabGraphConstants.HTML_NEWLINE);
604 result.append("y : " + getGeometry().getY() + ScilabGraphConstants.HTML_NEWLINE);
605 result.append("w : " + getGeometry().getWidth() + ScilabGraphConstants.HTML_NEWLINE);
606 result.append("h : " + getGeometry().getHeight() + ScilabGraphConstants.HTML_NEWLINE);
607 result.append(ScilabGraphConstants.HTML_END);
608 return result.toString();
615 public void openContextMenu(ScilabGraph graph) {
616 ContextMenu menu = null;
617 // if (getParentDiagram() instanceof PaletteDiagram) {
618 // menu = createPaletteContextMenu(graph);
620 menu = createContextMenu(graph);
622 menu.setVisible(true);
628 * @return context menu
631 public ContextMenu createPaletteContextMenu(ScilabGraph graph) {
632 ContextMenu menu = ScilabContextMenu.createContextMenu();
634 final List<XcosDiagram> allDiagrams = Xcos.getInstance().openedDiagrams();
636 if (allDiagrams.size() == 0) {
637 // No diagram opened: should never happen if Xcos opens an empty
638 // diagram when it is launched
639 MenuItem addTo = ScilabMenuItem.createMenuItem();
641 addTo.setText(XcosMessages.ADDTO_NEW_DIAGRAM);
642 addTo.setCallback(new CommonCallBack(XcosMessages.ADDTO_NEW_DIAGRAM) {
644 public void callBack() {
645 JavaController controller = new JavaController();
646 XcosDiagram theDiagram = new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM);
647 BasicBlock block = (BasicBlock) BlockFactory.createClone(BasicBlock.this);
648 theDiagram.getModel().add(theDiagram.getDefaultParent(), block, 0);
649 mxGeometry geom = BasicBlock.this.getGeometry();
650 setDefaultPosition(geom);
651 theDiagram.getModel().setGeometry(block, geom);
653 XcosTab.get(theDiagram).setVisible(true);
654 BlockPositioning.updateBlockView(block);
660 } else if (allDiagrams.size() == 1) {
661 // A single diagram opened: add to this diagram
662 MenuItem addTo = ScilabMenuItem.createMenuItem();
664 addTo.setText(XcosMessages.ADDTO + " " + XcosTab.get(allDiagrams.get(0)).getName());
665 final XcosDiagram theDiagram = allDiagrams.get(0);
666 addTo.setCallback(new CommonCallBack(theDiagram.getTitle()) {
667 private static final long serialVersionUID = -99601763227525686L;
670 public void callBack() {
671 BasicBlock block = (BasicBlock) BlockFactory.createClone(BasicBlock.this);
672 theDiagram.getModel().add(theDiagram.getDefaultParent(), block, 0);
673 mxGeometry geom = BasicBlock.this.getGeometry();
674 setDefaultPosition(geom);
675 theDiagram.getModel().setGeometry(block, geom);
676 BlockPositioning.updateBlockView(block);
683 // The user has to choose
684 Menu addTo = ScilabMenu.createMenu();
686 addTo.setText(XcosMessages.ADDTO);
688 for (int i = 0; i < allDiagrams.size(); i++) {
689 MenuItem diagram = ScilabMenuItem.createMenuItem();
690 final XcosDiagram theDiagram = allDiagrams.get(i);
691 diagram.setText(XcosTab.get(allDiagrams.get(i)).getName());
692 diagram.setCallback(new CommonCallBack(theDiagram.getTitle()) {
693 private static final long serialVersionUID = 3345416658377835057L;
696 public void callBack() {
697 BasicBlock block = (BasicBlock) BlockFactory.createClone(BasicBlock.this);
698 theDiagram.getModel().add(theDiagram.getDefaultParent(), block, 0);
699 mxGeometry geom = BasicBlock.this.getGeometry();
700 setDefaultPosition(geom);
701 theDiagram.getModel().setGeometry(block, geom);
702 BlockPositioning.updateBlockView(block);
711 menu.getAsSimpleContextMenu().addSeparator();
713 MenuItem help = ScilabMenuItem.createMenuItem();
714 help.setText(XcosMessages.BLOCK_DOCUMENTATION);
715 help.setCallback(new CommonCallBack(XcosMessages.BLOCK_DOCUMENTATION) {
716 private static final long serialVersionUID = -1480947262397441951L;
719 public void callBack() {
720 JavaController controller = new JavaController();
721 String[] interfaceFunctionName = new String[1];
722 controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunctionName);
724 InterpreterManagement.requestScilabExec("help " + interfaceFunctionName[0]);
729 menu.setVisible(true);
731 ((SwingScilabContextMenu) menu.getAsSimpleContextMenu()).setLocation(MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo()
742 * @return context menu
745 public ContextMenu createContextMenu(ScilabGraph graph) {
746 ContextMenu menu = ScilabContextMenu.createContextMenu();
747 Map < Class <? extends DefaultAction > , Menu > menuList = new HashMap < Class <? extends DefaultAction > , Menu > ();
749 MenuItem value = BlockParametersAction.createMenu(graph);
750 menuList.put(BlockParametersAction.class, value);
753 menu.getAsSimpleContextMenu().addSeparator();
755 value = CutAction.cutMenu(graph);
756 menuList.put(CutAction.class, value);
758 value = CopyAction.copyMenu(graph);
759 menuList.put(CopyAction.class, value);
761 value = DeleteAction.createMenu(graph);
762 menuList.put(DeleteAction.class, value);
765 menu.getAsSimpleContextMenu().addSeparator();
767 value = RegionToSuperblockAction.createMenu(graph);
768 menuList.put(RegionToSuperblockAction.class, value);
771 menu.getAsSimpleContextMenu().addSeparator();
773 Menu format = ScilabMenu.createMenu();
774 format.setText(XcosMessages.FORMAT);
776 value = RotateAction.createMenu(graph);
777 menuList.put(RotateAction.class, value);
779 value = MirrorAction.createMenu(graph);
780 menuList.put(MirrorAction.class, value);
782 value = FlipAction.createMenu(graph);
783 menuList.put(FlipAction.class, value);
785 value = ShowHideShadowAction.createMenu(graph);
786 menuList.put(ShowHideShadowAction.class, value);
789 format.addSeparator();
791 Menu alignMenu = ScilabMenu.createMenu();
792 alignMenu.setText(XcosMessages.ALIGN_BLOCKS);
793 alignMenu.add(AlignBlockActionLeft.createMenu(graph));
794 alignMenu.add(AlignBlockActionCenter.createMenu(graph));
795 alignMenu.add(AlignBlockActionRight.createMenu(graph));
796 alignMenu.addSeparator();
797 alignMenu.add(AlignBlockActionTop.createMenu(graph));
798 alignMenu.add(AlignBlockActionMiddle.createMenu(graph));
799 alignMenu.add(AlignBlockActionBottom.createMenu(graph));
800 menuList.put(AlignBlockAction.class, alignMenu);
801 format.add(alignMenu);
803 format.addSeparator();
805 if (graph.getSelectionCells().length > 1) {
806 format.add(BorderColorAction.createMenu(graph));
807 format.add(FilledColorAction.createMenu(graph));
809 format.add(EditFormatAction.createMenu(graph));
812 menu.getAsSimpleContextMenu().addSeparator();
814 menu.add(ViewDetailsAction.createMenu(graph));
816 menu.getAsSimpleContextMenu().addSeparator();
818 menu.add(BlockDocumentationAction.createMenu(graph));
820 ((SwingScilabContextMenu) menu.getAsSimpleContextMenu()).setLocation(MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo()
823 customizeMenu(menuList);
829 * Override this to customize contextual menu
834 protected void customizeMenu(Map < Class <? extends DefaultAction > , Menu > menuList) {
835 // To be overridden by sub-classes
840 * Set the default block position on the geom
845 private void setDefaultPosition(mxGeometry geom) {
846 geom.setX(DEFAULT_POSITION_X);
847 geom.setY(DEFAULT_POSITION_Y);
851 * Overriden methods from jgraphx
855 * @return always false
856 * @see com.mxgraph.model.mxCell#isConnectable()
859 public boolean isConnectable() {
866 * Sync the specific child {@link EditFormatAction#HASH_IDENTIFIER}
869 public mxICell insert(mxICell child, int index) {
871 * Update the id if this is an identifier cell (herited identifier)
873 if (child.getId().endsWith(XcosDiagram.HASH_IDENTIFIER)) {
874 child.setId(getId() + XcosDiagram.HASH_IDENTIFIER);
877 return super.insert(child, index);