Xcos: format source code 07/5307/1
Clément DAVID [Tue, 25 Oct 2011 14:34:21 +0000 (16:34 +0200)]
Change-Id: Ie8b9d8cd03d5320b2a45ae74708d783e7b38ebd5

187 files changed:
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/AboutXcosAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/CloseAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/CloseViewportAction.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/DiagramBackgroundAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/DumpAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/EditFormatAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/ExportAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/FitDiagramToViewAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/InitModelicaAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/NewDiagramAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/NormalViewAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/OpenAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/PrintAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/QuitAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/RecentFileAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/SaveAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/SaveAsAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/SetContextAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/SetupAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/ShowHideShadowAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/SimulationNotRunningAction.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/ViewGridAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/ViewViewportAction.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/actions/dialog/DebugLevelDialog.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/dialog/SetContextDialog.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/dialog/SetupDialog.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/AfficheBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BlockFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/SplitBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/SuperBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/TextBlock.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/BlockParametersAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/BorderColorAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/CodeGenerationAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/FilledColorAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/FlipAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/MirrorAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/RegionToSuperblockAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/RotateAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ShowParentAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperBlockSelectedAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCreateAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskCustomizeAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/SuperblockMaskRemoveAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ViewDetailsAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/alignement/AlignBlockAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/alignement/AlignBlockActionBottom.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/alignement/AlignBlockActionCenter.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/alignement/AlignBlockActionLeft.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/alignement/AlignBlockActionMiddle.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/alignement/AlignBlockActionRight.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/alignement/AlignBlockActionTop.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ContextUpdate.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/EventInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/EventOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ExplicitInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ExplicitOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ImplicitInBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ImplicitOutBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/listener/ProdPortLabelingListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/listener/SumPortLabelingListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/positionning/BigSom.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/positionning/GroundBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/positionning/Product.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/positionning/RoundBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/positionning/Summation.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/positionning/VoltageSensorBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/ConfigurationManager.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/model/DocumentType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/model/ObjectFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/model/PositionType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/model/RecentFilesType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/model/SettingType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/model/WindowsManagementType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/configuration/utils/ConfigurationConstants.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/CompilationEngineStatus.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/PaletteDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/ScicosParameters.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/SuperBlockDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/swing/GraphComponent.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/swing/handler/ConnectPreview.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/swing/handler/ConnectionHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/swing/handler/GraphHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/XcosCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/XcosObjectCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicPortCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/OrientationCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/XcosDiagramCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/AbstractElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/BasicBlockInfo.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/BlockElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/BlockModelElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/BlockPartsElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/Element.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/H5RWHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/LabelElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/LinkElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScicosFormatException.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScicosParametersElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/BasicLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/LinkPortMap.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/actions/StyleAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/actions/StyleHorizontalAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/actions/StyleStraightAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/actions/StyleVerticalAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/actions/TextAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/commandcontrol/CommandControlLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/explicit/ExplicitLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/implicit/ImplicitLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/ModelStatistics.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/Modelica.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/ModelicaController.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/ModelicaMessages.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/TerminalAccessor.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/TerminalTableModel.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/listener/FixDerivativesAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/listener/FixStatesAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/listener/SolveAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/listener/StatisticsUpdater.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Info.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Model.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ModelicaValue.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/ObjectFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Output.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Struct.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/model/Terminal.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/view/LabelWithValue.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/modelica/view/MainPanel.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/Palette.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteBlockCtrl.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteManager.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PreLoadedElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/StyleElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/actions/ClosePalettesAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/actions/LoadAsPalAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/actions/NewPaletteAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/actions/ViewPaletteBrowserAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteBlockMouseListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteManagerMouseListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteManagerTreeSelectionListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteTreeTransferHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/Category.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/Custom.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/ObjectFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/Palette.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/PaletteBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/PaletteNode.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/PreLoaded.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/model/VariablePath.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/ModifiedFlowLayout.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteBlockView.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteComponent.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteConfiguratorListView.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteManagerPanel.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteManagerView.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteTreeModel.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteView.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/BasicPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/Orientation.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/PortCheck.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/command/CommandPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/control/ControlPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/input/ExplicitInputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/input/ImplicitInputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/input/InputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/output/ExplicitOutputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/output/ImplicitOutputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/output/OutputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockChange.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/PaletteComponent.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosConstants.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosDialogs.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosEvent.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosFileType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosMessages.java

index d53d84e..b1d9e8b 100644 (file)
@@ -55,761 +55,778 @@ import com.mxgraph.view.mxStylesheet;
 // CSOFF: ClassFanOutComplexity
 // CSOFF: ClassDataAbstractionCoupling
 public final class Xcos {
-       /**
-        * The current Xcos version
-        */
-       public static final String VERSION = "1.0";
-       /**
-        * The current Xcos tradename
-        */
-       public static final String TRADENAME = "Xcos";
-
-       private static final String LOAD_XCOS_LIBS_LOAD_SCICOS = "loadXcosLibs(); loadScicos();";
-       
-       /*
-        * Dependencies version
-        */
-       private static final List<String> MXGRAPH_VERSIONS = Arrays.asList("1.7.0.6", "1.7.0.7");
-       private static final List<String> HDF5_VERSIONS = Arrays.asList("[1, 8, 4]", "[1, 8, 5]", "[1, 8, 6]", "[1, 8, 7]");
-       private static final List<String> BATIK_VERSIONS = Arrays.asList("1.7");
-       
-       private static final String UNABLE_TO_LOAD_JGRAPHX = 
-               Messages.gettext("Unable to load the jgraphx library.\nExpecting version %s ; Getting version %s .");
-       private static final String UNABLE_TO_LOAD_JHDF5 = 
-               Messages.gettext("Unable to load the hdf5-java (jhdf5) library. \nExpecting version %s ; Getting version %s .");
-       private static final String UNABLE_TO_LOAD_HDF5 = 
-               Messages.gettext("Unable to load the native HDF5 library.");
-       private static final String UNABLE_TO_LOAD_BATIK = 
-               Messages.gettext("Unable to load the Batik library. \nExpecting version %s ; Getting version %s .");
-       
-       private static final String CALLED_OUTSIDE_THE_EDT_THREAD = "Called outside the EDT thread.";
-       private static final Log LOG = LogFactory.getLog(Xcos.class);
-
-       /** common shared instance */
-       private static volatile Xcos sharedInstance;
-
-       /*
-        * Instance data
-        */
-       private final List<XcosDiagram> diagrams;
-
-       /*
-        * Instance handlers
-        */
-       private final PaletteManager palette;
-       private final ConfigurationManager configuration;
-       private final mxStylesheet styleSheet;
-
-       /**
-        * Construct an Xcos instance.
-        * 
-        * There must be only one Xcos instance per Scilab application
-        */
-       private Xcos() {
-               /*
-                * Read the configuration to support dynamic (before Xcos launch)
-                * settings. 
-                */
-               try {
-                       LogManager.getLogManager().readConfiguration();
-               } catch (final SecurityException e) {
-                       LOG.error(e);
-               } catch (final IOException e) {
-                       LOG.error(e);
-               }
-               
-               /* Check the dependencies at startup time */
-               checkDependencies();
-               
-               /*
-                * Allocate synchronized communications data
-                */
-               diagrams = Collections.synchronizedList(new Vector<XcosDiagram>());
-
-               /*
-                * get the handlers instance
-                */
-               palette = PaletteManager.getInstance();
-               configuration = ConfigurationManager.getInstance();
-               styleSheet = new mxStylesheet();
-
-               try {
-                       FileUtils.decodeStyle(styleSheet);
-               } catch (final IOException e) {
-                       LOG.error(e);
-               }
-       }
-
-       /**
-        * Check the dependencies and the version dependencies.
-        * 
-        * This method use runtime class loading to handle ClassNotFoundException. 
-        * 
-        * This method catch any exception and rethrow it with a well defined
-        * message. Thus it doesn't pass the IllegalCatch metrics.
-        */
-       // CSOFF: IllegalCatch
-       // CSOFF: MagicNumber
-       private void checkDependencies() {
-               final ClassLoader loader = ClassLoader.getSystemClassLoader();
-               
-               /* JGraphx */
-               String mxGraphVersion = "";
-               try {
-                       final Class< ? > klass = loader.loadClass("com.mxgraph.view.mxGraph");
-                       mxGraphVersion = (String) klass.getDeclaredField("VERSION").get(null);
-                       
-                       if (MXGRAPH_VERSIONS != null && !MXGRAPH_VERSIONS.contains(mxGraphVersion)) {
-                               throw new Exception();
-                       }
-               } catch (final Throwable e) {
-                       throw new RuntimeException(String.format(UNABLE_TO_LOAD_JGRAPHX,
-                                       MXGRAPH_VERSIONS.get(0), mxGraphVersion), e);
-               }
-               
-               /* HDF5 */
-               final int[] libVersion = new int[3]; 
-               try {
-                       final Class< ? > klass = loader.loadClass("ncsa.hdf.hdf5lib.H5");
-                       
-                       /* hdf5-java */
-                       int ret = (Integer) klass.getMethod("H5get_libversion", libVersion.getClass())
-                                                                       .invoke(null, libVersion);
-                       if (ret < 0) {
-                               throw new Exception();
-                       }
-                       
-                       if (!HDF5_VERSIONS.contains(Arrays.toString(libVersion))) {
-                               throw new Exception();
-                       }
-                       
-                       
-                       /* hdf5 */
-                       ret = (Integer) klass.getMethod("H5check_version", int.class,
-                                       int.class, int.class).invoke(null, libVersion[0],
-                                       libVersion[1], libVersion[2]);
-                       if (ret < 0) {
-                               throw new RuntimeException(UNABLE_TO_LOAD_HDF5);
-                       }
-                       
-               } catch (final Throwable e) {
-                       if (!(e instanceof RuntimeException)) {
-                               throw new RuntimeException(String.format(UNABLE_TO_LOAD_JHDF5,
-                                               HDF5_VERSIONS.get(0), Arrays.toString(libVersion)), e);
-                       }
-               }
-               
-               /* Batik */
-               String batikVersion = null;
-               try {
-                       final Class< ? > klass = loader.loadClass("org.apache.batik.Version");
-                       batikVersion = klass.getPackage().getImplementationVersion()
-                                                               .split("\\+")[0];
-                       
-                       if (!BATIK_VERSIONS.contains(batikVersion)) {
-                               throw new Exception();
-                       }
-                       
-               } catch (final Throwable e) {
-                       throw new RuntimeException(String.format(UNABLE_TO_LOAD_BATIK,
-                                       BATIK_VERSIONS.get(0), batikVersion), e);
-               }
-       }
-       // CSON: MagicNumber
-       // CSON: IllegalCatch
-
-       /**
-        * @return the per Scilab application, Xcos instance
-        */
-       public static synchronized Xcos getInstance() {
-               if (sharedInstance == null) {
-                       sharedInstance = new Xcos();
-                       
-                       /*
-                        * Lazy loading of HDF5 libraries to avoid first drag lag.
-                        */
-                       (new SwingWorker<Void, Void>() {
-
-                               @Override
-                               protected Void doInBackground() throws Exception {
-                                       try {
-                                               final Category root = PaletteManager.getInstance().getRoot();
-                                               
-                                               final PaletteBlock b = ((PreLoaded) root.getNode().get(0)).getBlock().get(0);
-                                               new PaletteBlockCtrl(b).getTransferable();
-                                       } catch (IndexOutOfBoundsException e) {
-                                               LOG.debug(e);
-                                       } catch (ClassCastException e) {
-                                               LOG.debug(e);
-                                       }
-                                       return null;
-                               }
-                       }).execute();
-                       
-                       LOG.trace("Session started");
-               }
-
-               return sharedInstance;
-       }
-       
-       /**
-        * Clear the shared instance.
-        */
-       private static synchronized void clearInstance() {
-               sharedInstance = null;
-               LOG.trace("Session ended");
-       }
-
-       /**
-        * @return the already opened diagrams
-        */
-       public List<XcosDiagram> getDiagrams() {
-               return diagrams;
-       }
-       
-       /**
-        * @return the global shared styleSheet
-        */
-       public mxStylesheet getStyleSheet() {
-               return styleSheet;
-       }
-       
-       /**
-        * Open a file from it's filename.
-        * 
-        * This method must be called on the EDT thread. For other use, please use
-        * the {@link #xcos(String)} method.
-        * 
-        * @param filename
-        *            the file to open. If null an empty diagram is created.
-        */
-       public void open(final File filename) {
-               if (!SwingUtilities.isEventDispatchThread()) {
-                       LOG.error(CALLED_OUTSIDE_THE_EDT_THREAD);
-               }
-
-               XcosDiagram diag = null;
-
-               if (filename != null) {
-                       configuration.addToRecentFiles(filename);
-
-                       /*
-                        * looking for an already opened diagram
-                        */
-                       for (final XcosDiagram diagram : diagrams) {
-                               if (diagram.getSavedFile() != null
-                                               && diagram.getSavedFile().equals(filename)) {
-                                       diag = diagram;
-                                       break;
-                               }
-                       }
-               }
-
-               if (diag == null) {
-
-                       /*
-                        * Allocate and setup a new diagram
-                        */
-                       diag = new XcosDiagram();
-                       diag.installListeners();
-                       final XcosTab tab = new XcosTab(diag);
-
-                       if (filename != null) {
-                               // wait the end of the load before displaying the tab.
-                               diag = diag.openDiagramFromFile(filename);
-                       } else {
-                               // empty tab, display it
-                               tab.setVisible(true);
-                       }
-                       
-                       if (diag != null) {
-                               diagrams.add(diag);
-                       }
-               } else {
-
-                       /*
-                        * Focus on an existing diagram
-                        */
-                       diag.getParentTab().setCurrent();
-               }
-       }
-
-       /**
-        * Close a diagram.
-        * 
-        * This method must be called on the EDT thread.
-        * 
-        * @param diagram
-        *            the diagram to close
-        * @param force
-        *            true, if the diagram must always be closed at the return.
-        * @return the closing status (true, the diagram has been closed; false,
-        *         otherwise)
-        */
-       public boolean close(final XcosDiagram diagram, final boolean force) {
-               if (!SwingUtilities.isEventDispatchThread()) {
-                       LOG.error(CALLED_OUTSIDE_THE_EDT_THREAD);
-               }
-               
-               final boolean status = diagram.close(force);
-               
-               if (status) {
-                   diagram.setOpened(false);
-                   diagrams.remove(diagram);
-                   
-                   if (diagrams.isEmpty()) {
-                       Xcos.closeSession();
-                   } else {
-                       // we must also close the session is no diagram is visible
-                       for (final XcosDiagram diag : diagrams) {
-                                       if (diag.getParentTab() != null) {
-                                               return true;
-                                       }
-                       }
-                       Xcos.closeSession();
-                   }
-                   return true;
-               }
-               return false;
-       }
-
-       /**
-        * Close the current xcos session.
-        * 
-        * This method must be called on the EDT thread. For other use, please use
-        * the {@link #closeXcosFromScilab()} method.
-        */
-       public static synchronized void closeSession() {
-               if (!SwingUtilities.isEventDispatchThread()) {
-                       LOG.error(CALLED_OUTSIDE_THE_EDT_THREAD);
-               }
-
-               /* Doesn't instantiate xcos on close operation */
-               if (sharedInstance == null) {
-                       return;
-               }
-               
-               final Xcos instance = sharedInstance;
-               final List<XcosDiagram> diagrams = instance.diagrams;
-
-               /*
-                * We are looping in the inverted order because we have to close latest
-                * add diagrams (eg SuperBlockDiagrams) before any others.
-                * 
-                * Furthermore the closeDiagram operation modify the diagram list. Thus
-                * we must *NOT* use i-- there.
-                */
-               for (int i = diagrams.size() - 1; i >= 0; i = diagrams.size() - 1) {
-                       instance.close(diagrams.get(i), true);
-               }
-
-               if (instance.palette.getView() != null 
-                               && instance.palette.getView().isVisible()) {
-                       instance.palette.getView().close();
-                       instance.palette.setView(null);
-               }
-               
-               /* terminate any remaining simulation */
-               InterpreterManagement.requestScilabExec("haltscicos");
-
-               /* Saving modified data */
-               instance.palette.saveConfig();
-               instance.configuration.saveConfig();
-       }
-
-       /**
-        * Debug main function
-        * 
-        * @param args
-        *            command line args (Not used)
-        */
-       public static void main(final String[] args) {
-               xcos();
-       }
-
-       /*
-        * Scilab exported methods.
-        * 
-        * All the following methods must use SwingUtilities method to assert that
-        * the operations will be called on the EDT thread.
-        * 
-        * @see modules/xcos/src/jni/Xcos.giws.xml
-        * @see sci_gateway/xcos_gateway.xml
-        * @see modules/xcos/sci_gateway/cpp/sci_*.cpp
-        */
-
-       /**
-        * Entry point without filename.
-        * 
-        * This method invoke Xcos operation on the EDT thread.
-        */
-       @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-       public static void xcos() {
-               final Xcos instance = getInstance();
-               
-               /* load scicos libraries (macros) */
-               InterpreterManagement.requestScilabExec(LOAD_XCOS_LIBS_LOAD_SCICOS);
-
-               SwingUtilities.invokeLater(new Runnable() {
-                       @Override
-                       public void run() {
-                               instance.open(null);
-                               PaletteManager.setVisible(true);
-                       }
-               });
-       }
-
-       /**
-        * Entry point with filename
-        * 
-        * This method invoke Xcos operation on the EDT thread.
-        * 
-        * @param fileName
-        *            The filename
-        */
-       @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-       public static void xcos(final String fileName) {
-               final Xcos instance = getInstance();
-               final File filename = new File(fileName);
-               
-               /* load scicos libraries (macros) */
-               InterpreterManagement.requestScilabExec(LOAD_XCOS_LIBS_LOAD_SCICOS);
-               
-               try {
-                       SwingUtilities.invokeAndWait(new Runnable() {
-                               @Override
-                               public void run() {
-                                       instance.open(filename);
-                               }
-                       });
-               } catch (final InterruptedException e) {
-                       LOG.error(e);
-               } catch (final InvocationTargetException e) {
-                       Throwable throwable = e;
-                       String firstMessage = null;
-                       while (throwable != null) {
-                               firstMessage = throwable.getLocalizedMessage();
-                               throwable = throwable.getCause();
-                       }
-                       
-                       throw new RuntimeException(firstMessage, e);
-               }
-       }
-
-       /**
-        * Close the current xcos session from any thread.
-        * 
-        * This method invoke Xcos operation on the EDT thread. Please prefer using
-        * {@link #closeSession()} when the caller is on the EDT thread.
-        */
-       @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-       public static void closeXcosFromScilab() {
-               try {
-                       SwingUtilities.invokeAndWait(new Runnable() {
-                               @Override
-                               public void run() {
-                                       closeSession();
-                                       clearInstance();
-                               }
-                       });
-               } catch (final InterruptedException e) {
-                       LOG.error(e);
-               } catch (final InvocationTargetException e) {
-                       Throwable throwable = e;
-                       String firstMessage = null;
-                       while (throwable != null) {
-                               firstMessage = throwable.getLocalizedMessage();
-                               throwable = throwable.getCause();
-                       }
-                       
-                       throw new RuntimeException(firstMessage, e);
-               }
-       }
-
-       /**
-        * Look in each diagram to find the block corresponding to the given uid and
-        * display a warning message.
-        * 
-        * This method invoke Xcos operation on the EDT thread.
-        * 
-        * @param uid
-        *            A String as UID.
-        * @param message
-        *            The message to display.
-        */
-       @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-       public static void warnCellByUID(final String[] uid, final String message) {
-               try {
-                       SwingUtilities.invokeAndWait(new Runnable() {
-                               @Override
-                               public void run() {
-                                       final ArrayDeque<String> deque = new ArrayDeque<String>(Arrays.asList(uid));
-                                       
-                                       String id;
-                                       BasicBlock block = null;
-                                       
-                                       // specific case with an empty array
-                                       if (deque.isEmpty()) {
-                                               return;
-                                       }
-                                       
-                                       // first element
-                                       id = deque.pop();
-                                       for (XcosDiagram diagram : getInstance().getDiagrams()) {
-                                               block = (BasicBlock) ((mxGraphModel) diagram.getModel()).getCell(id);
-                                               if (block != null) {
-                                                       break;
-                                               }
-                                       }
-                                       
-                                       
-                                       // loop to get only the last diagram
-                                       while (block instanceof SuperBlock && !deque.isEmpty()) {
-                                               block.getParentDiagram()
-                                                               .warnCellByUID(
-                                                                               block.getId(),
-                                                                               XcosMessages.ERROR_UNABLE_TO_COMPILE_THIS_SUPER_BLOCK);
-                                               
-                                               final SuperBlock superBlock = (SuperBlock) block;
-                                               id = deque.pop();
-                                               
-                                               if (!Xcos.getInstance().getDiagrams().contains(superBlock.getChild())) {
-                                                       block.openBlockSettings(null);
-                                               }
-                                               block = (BasicBlock) ((mxGraphModel) superBlock.getChild().getModel()).getCell(id);
-                                       }
-                                       
-                                       // We are unable to find the block with the right id
-                                       if (block == null) {
-                                               return;
-                                       }
-                                       
-                                       
-                                       // finally perform the action on the last block
-                                       final XcosDiagram parent = block.getParentDiagram();
-                                       parent.warnCellByUID(block.getId(), message);
-                                       
-                                       SwingUtilities.invokeLater(new Runnable() {
-                                               @Override
-                                               public void run() {
-                                                       /*
-                                                        * Focus on an existing diagram
-                                                        */
-                                                       parent.getParentTab().setCurrent();
-                                               }
-                                       });
-                                       
-                               }
-                       });
-               } catch (final InterruptedException e) {
-                       LOG.error(e);
-               } catch (final InvocationTargetException e) {
-                       Throwable throwable = e;
-                       String firstMessage = null;
-                       while (throwable != null) {
-                               firstMessage = throwable.getLocalizedMessage();
-                               throwable = throwable.getCause();
-                       }
-                       
-                       throw new RuntimeException(firstMessage, e);
-               }
-       }
-
-       /**
-        * This function convert a Xcos diagram to Scilab variable.
-        * 
-        * This method invoke Xcos operation on the EDT thread.
-        * 
-        * @param xcosFile
-        *            The xcos diagram file
-        * @param h5File
-        *            The target file
-        * @param overwrite
-        *            Does the file will be overwritten ?
-        * @return Not used (compatibility)
-        */
-       @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-       public static int xcosDiagramToHDF5(final String xcosFile, final String h5File,
-                       final boolean overwrite) {
-               final File file = new File(xcosFile);
-
-               if (exists(h5File)) {
-                       if (!overwrite) {
-                               return 1;
-                       } else {
-                               delete(h5File);
-                       }
-               }
-               
-               if (!file.exists()) {
-                       return 1;
-               }
-               
-               try {
-                       SwingUtilities.invokeAndWait(new Runnable() {
-                               @Override
-                               public void run() {
-                                       final XcosDiagram diagram = new XcosDiagram();
-                                       diagram.openDiagramFromFile(file);
-                                       diagram.dumpToHdf5File(h5File);
-                               }
-                       });
-               } catch (final InterruptedException e) {
-                       throw new RuntimeException(e);
-               } catch (final InvocationTargetException e) {
-                       Throwable throwable = e;
-                       String firstMessage = null;
-                       while (throwable != null) {
-                               firstMessage = throwable.getLocalizedMessage();
-                               throwable = throwable.getCause();
-                       }
-                       
-                       throw new RuntimeException(firstMessage, e);
-               }
-
-               return 0;
-       }
-
-       /**
-        * Open a diagram by uid.
-        * 
-        * This method invoke Xcos operation on the EDT thread.
-        * 
-        * @param uid
-        *            UID path to a block.
-        */
-       @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-       public static void xcosDiagramOpen(final String[] uid) {
-               final ArrayDeque<String> deque = new ArrayDeque<String>(Arrays.asList(uid));
-               
-               try {
-                       SwingUtilities.invokeAndWait(new Runnable() {
-                               @Override
-                               public void run() {
-                                       String id;
-                                       Object block = null;
-                                       
-                                       // specific case with an empty array
-                                       if (deque.isEmpty()) {
-                                               return;
-                                       }
-                                       
-                                       // first element
-                                       id = deque.pop();
-                                       for (XcosDiagram diagram : getInstance().getDiagrams()) {
-                                               block = ((mxGraphModel) diagram.getModel()).getCell(id);
-                                               if (block instanceof SuperBlock) {
-                                                       break;
-                                               }
-                                       }
-                                       
-                                       // loop to get only the last diagram
-                                       while (block instanceof SuperBlock & !deque.isEmpty()) {
-                                               final SuperBlock superBlock = (SuperBlock) block;
-                                               id = deque.pop();
-                                               
-                                               superBlock.openBlockSettings(null);
-                                               block = ((mxGraphModel) superBlock.getChild().getModel()).getCell(id);
-                                       }
-                                       
-                                       // finally perform the action
-                                       if (block instanceof SuperBlock) {
-                                               ((SuperBlock) block).openBlockSettings(null);
-                                       }
-                               }
-                       });
-               } catch (final InterruptedException e) {
-                       LOG.error(e);
-               } catch (final InvocationTargetException e) {
-                       Throwable throwable = e;
-                       String firstMessage = null;
-                       while (throwable != null) {
-                               firstMessage = throwable.getLocalizedMessage();
-                               throwable = throwable.getCause();
-                       }
-                       
-                       throw new RuntimeException(firstMessage, e);
-               }
-       }
-
-       /**
-        * Close a diagram by uid.
-        * 
-        * This method invoke Xcos operation on the EDT thread.
-        * 
-        * @param uid The diagram id path
-        */
-       @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-       public static void xcosDiagramClose(final String[] uid) {
-               final ArrayDeque<String> deque = new ArrayDeque<String>(Arrays.asList(uid));
-               
-               try {
-                       SwingUtilities.invokeAndWait(new Runnable() {
-                               @Override
-                               public void run() {
-                                       String id;
-                                       Object block = null;
-                                       
-                                       // specific case with an empty array
-                                       if (deque.isEmpty()) {
-                                               closeSession();
-                                       }
-                                       
-                                       // first element
-                                       id = deque.pop();
-                                       for (XcosDiagram diagram : getInstance().getDiagrams()) {
-                                               block = ((mxGraphModel) diagram.getModel()).getCell(id);
-                                               if (block instanceof SuperBlock) {
-                                                       break;
-                                               }
-                                       }
-                                       
-                                       // loop to get only the last diagram
-                                       while (block instanceof SuperBlock & !deque.isEmpty()) {
-                                               final SuperBlock superBlock = (SuperBlock) block;
-                                               id = deque.pop();
-                                               
-                                               superBlock.openBlockSettings(null);
-                                               block = ((mxGraphModel) superBlock.getChild().getModel()).getCell(id);
-                                       }
-                                       
-                                       // finally perform the action
-                                       if (block instanceof SuperBlock) {
-                                               ((SuperBlock) block).closeBlockSettings();
-                                       }
-                               }
-                       });
-               } catch (final InterruptedException e) {
-                       LOG.error(e);
-               } catch (final InvocationTargetException e) {
-                       Throwable throwable = e;
-                       String firstMessage = null;
-                       while (throwable != null) {
-                               firstMessage = throwable.getLocalizedMessage();
-                               throwable = throwable.getCause();
-                       }
-                       
-                       throw new RuntimeException(firstMessage, e);
-               }
-       }
-       
-       /**
-        * Look for the parent diagram of the cell in the diagram hierarchy.
-        * @param cell the cell to search for
-        * @return the associated diagram
-        */
-       public static XcosDiagram findParent(Object cell) {
-               final Xcos instance = getInstance();
-               for (XcosDiagram diag : instance.getDiagrams()) {
-                       if (diag.getModel().contains(cell)) {
-                               if (cell instanceof BasicBlock) {
-                                       ((BasicBlock) cell).setParentDiagram(diag);
-                               }
-                               return diag;
-                       }
-               }
-               return null;
-       }
+    /**
+     * The current Xcos version
+     */
+    public static final String VERSION = "1.0";
+    /**
+     * The current Xcos tradename
+     */
+    public static final String TRADENAME = "Xcos";
+
+    private static final String LOAD_XCOS_LIBS_LOAD_SCICOS = "loadXcosLibs(); loadScicos();";
+
+    /*
+     * Dependencies version
+     */
+    private static final List<String> MXGRAPH_VERSIONS = Arrays.asList(
+            "1.7.0.6", "1.7.0.7");
+    private static final List<String> HDF5_VERSIONS = Arrays.asList(
+            "[1, 8, 4]", "[1, 8, 5]", "[1, 8, 6]", "[1, 8, 7]");
+    private static final List<String> BATIK_VERSIONS = Arrays.asList("1.7");
+
+    private static final String UNABLE_TO_LOAD_JGRAPHX = Messages
+            .gettext("Unable to load the jgraphx library.\nExpecting version %s ; Getting version %s .");
+    private static final String UNABLE_TO_LOAD_JHDF5 = Messages
+            .gettext("Unable to load the hdf5-java (jhdf5) library. \nExpecting version %s ; Getting version %s .");
+    private static final String UNABLE_TO_LOAD_HDF5 = Messages
+            .gettext("Unable to load the native HDF5 library.");
+    private static final String UNABLE_TO_LOAD_BATIK = Messages
+            .gettext("Unable to load the Batik library. \nExpecting version %s ; Getting version %s .");
+
+    private static final String CALLED_OUTSIDE_THE_EDT_THREAD = "Called outside the EDT thread.";
+    private static final Log LOG = LogFactory.getLog(Xcos.class);
+
+    /** common shared instance */
+    private static volatile Xcos sharedInstance;
+
+    /*
+     * Instance data
+     */
+    private final List<XcosDiagram> diagrams;
+
+    /*
+     * Instance handlers
+     */
+    private final PaletteManager palette;
+    private final ConfigurationManager configuration;
+    private final mxStylesheet styleSheet;
+
+    /**
+     * Construct an Xcos instance.
+     * 
+     * There must be only one Xcos instance per Scilab application
+     */
+    private Xcos() {
+        /*
+         * Read the configuration to support dynamic (before Xcos launch)
+         * settings.
+         */
+        try {
+            LogManager.getLogManager().readConfiguration();
+        } catch (final SecurityException e) {
+            LOG.error(e);
+        } catch (final IOException e) {
+            LOG.error(e);
+        }
+
+        /* Check the dependencies at startup time */
+        checkDependencies();
+
+        /*
+         * Allocate synchronized communications data
+         */
+        diagrams = Collections.synchronizedList(new Vector<XcosDiagram>());
+
+        /*
+         * get the handlers instance
+         */
+        palette = PaletteManager.getInstance();
+        configuration = ConfigurationManager.getInstance();
+        styleSheet = new mxStylesheet();
+
+        try {
+            FileUtils.decodeStyle(styleSheet);
+        } catch (final IOException e) {
+            LOG.error(e);
+        }
+    }
+
+    /**
+     * Check the dependencies and the version dependencies.
+     * 
+     * This method use runtime class loading to handle ClassNotFoundException.
+     * 
+     * This method catch any exception and rethrow it with a well defined
+     * message. Thus it doesn't pass the IllegalCatch metrics.
+     */
+    // CSOFF: IllegalCatch
+    // CSOFF: MagicNumber
+    private void checkDependencies() {
+        final ClassLoader loader = ClassLoader.getSystemClassLoader();
+
+        /* JGraphx */
+        String mxGraphVersion = "";
+        try {
+            final Class<?> klass = loader.loadClass("com.mxgraph.view.mxGraph");
+            mxGraphVersion = (String) klass.getDeclaredField("VERSION").get(
+                    null);
+
+            if (MXGRAPH_VERSIONS != null
+                    && !MXGRAPH_VERSIONS.contains(mxGraphVersion)) {
+                throw new Exception();
+            }
+        } catch (final Throwable e) {
+            throw new RuntimeException(String.format(UNABLE_TO_LOAD_JGRAPHX,
+                    MXGRAPH_VERSIONS.get(0), mxGraphVersion), e);
+        }
+
+        /* HDF5 */
+        final int[] libVersion = new int[3];
+        try {
+            final Class<?> klass = loader.loadClass("ncsa.hdf.hdf5lib.H5");
+
+            /* hdf5-java */
+            int ret = (Integer) klass.getMethod("H5get_libversion",
+                    libVersion.getClass()).invoke(null, libVersion);
+            if (ret < 0) {
+                throw new Exception();
+            }
+
+            if (!HDF5_VERSIONS.contains(Arrays.toString(libVersion))) {
+                throw new Exception();
+            }
+
+            /* hdf5 */
+            ret = (Integer) klass.getMethod("H5check_version", int.class,
+                    int.class, int.class).invoke(null, libVersion[0],
+                    libVersion[1], libVersion[2]);
+            if (ret < 0) {
+                throw new RuntimeException(UNABLE_TO_LOAD_HDF5);
+            }
+
+        } catch (final Throwable e) {
+            if (!(e instanceof RuntimeException)) {
+                throw new RuntimeException(String.format(UNABLE_TO_LOAD_JHDF5,
+                        HDF5_VERSIONS.get(0), Arrays.toString(libVersion)), e);
+            }
+        }
+
+        /* Batik */
+        String batikVersion = null;
+        try {
+            final Class<?> klass = loader.loadClass("org.apache.batik.Version");
+            batikVersion = klass.getPackage().getImplementationVersion()
+                    .split("\\+")[0];
+
+            if (!BATIK_VERSIONS.contains(batikVersion)) {
+                throw new Exception();
+            }
+
+        } catch (final Throwable e) {
+            throw new RuntimeException(String.format(UNABLE_TO_LOAD_BATIK,
+                    BATIK_VERSIONS.get(0), batikVersion), e);
+        }
+    }
+
+    // CSON: MagicNumber
+    // CSON: IllegalCatch
+
+    /**
+     * @return the per Scilab application, Xcos instance
+     */
+    public static synchronized Xcos getInstance() {
+        if (sharedInstance == null) {
+            sharedInstance = new Xcos();
+
+            /*
+             * Lazy loading of HDF5 libraries to avoid first drag lag.
+             */
+            (new SwingWorker<Void, Void>() {
+
+                @Override
+                protected Void doInBackground() throws Exception {
+                    try {
+                        final Category root = PaletteManager.getInstance()
+                                .getRoot();
+
+                        final PaletteBlock b = ((PreLoaded) root.getNode().get(
+                                0)).getBlock().get(0);
+                        new PaletteBlockCtrl(b).getTransferable();
+                    } catch (IndexOutOfBoundsException e) {
+                        LOG.debug(e);
+                    } catch (ClassCastException e) {
+                        LOG.debug(e);
+                    }
+                    return null;
+                }
+            }).execute();
+
+            LOG.trace("Session started");
+        }
+
+        return sharedInstance;
+    }
+
+    /**
+     * Clear the shared instance.
+     */
+    private static synchronized void clearInstance() {
+        sharedInstance = null;
+        LOG.trace("Session ended");
+    }
+
+    /**
+     * @return the already opened diagrams
+     */
+    public List<XcosDiagram> getDiagrams() {
+        return diagrams;
+    }
+
+    /**
+     * @return the global shared styleSheet
+     */
+    public mxStylesheet getStyleSheet() {
+        return styleSheet;
+    }
+
+    /**
+     * Open a file from it's filename.
+     * 
+     * This method must be called on the EDT thread. For other use, please use
+     * the {@link #xcos(String)} method.
+     * 
+     * @param filename
+     *            the file to open. If null an empty diagram is created.
+     */
+    public void open(final File filename) {
+        if (!SwingUtilities.isEventDispatchThread()) {
+            LOG.error(CALLED_OUTSIDE_THE_EDT_THREAD);
+        }
+
+        XcosDiagram diag = null;
+
+        if (filename != null) {
+            configuration.addToRecentFiles(filename);
+
+            /*
+             * looking for an already opened diagram
+             */
+            for (final XcosDiagram diagram : diagrams) {
+                if (diagram.getSavedFile() != null
+                        && diagram.getSavedFile().equals(filename)) {
+                    diag = diagram;
+                    break;
+                }
+            }
+        }
+
+        if (diag == null) {
+
+            /*
+             * Allocate and setup a new diagram
+             */
+            diag = new XcosDiagram();
+            diag.installListeners();
+            final XcosTab tab = new XcosTab(diag);
+
+            if (filename != null) {
+                // wait the end of the load before displaying the tab.
+                diag = diag.openDiagramFromFile(filename);
+            } else {
+                // empty tab, display it
+                tab.setVisible(true);
+            }
+
+            if (diag != null) {
+                diagrams.add(diag);
+            }
+        } else {
+
+            /*
+             * Focus on an existing diagram
+             */
+            diag.getParentTab().setCurrent();
+        }
+    }
+
+    /**
+     * Close a diagram.
+     * 
+     * This method must be called on the EDT thread.
+     * 
+     * @param diagram
+     *            the diagram to close
+     * @param force
+     *            true, if the diagram must always be closed at the return.
+     * @return the closing status (true, the diagram has been closed; false,
+     *         otherwise)
+     */
+    public boolean close(final XcosDiagram diagram, final boolean force) {
+        if (!SwingUtilities.isEventDispatchThread()) {
+            LOG.error(CALLED_OUTSIDE_THE_EDT_THREAD);
+        }
+
+        final boolean status = diagram.close(force);
+
+        if (status) {
+            diagram.setOpened(false);
+            diagrams.remove(diagram);
+
+            if (diagrams.isEmpty()) {
+                Xcos.closeSession();
+            } else {
+                // we must also close the session is no diagram is visible
+                for (final XcosDiagram diag : diagrams) {
+                    if (diag.getParentTab() != null) {
+                        return true;
+                    }
+                }
+                Xcos.closeSession();
+            }
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Close the current xcos session.
+     * 
+     * This method must be called on the EDT thread. For other use, please use
+     * the {@link #closeXcosFromScilab()} method.
+     */
+    public static synchronized void closeSession() {
+        if (!SwingUtilities.isEventDispatchThread()) {
+            LOG.error(CALLED_OUTSIDE_THE_EDT_THREAD);
+        }
+
+        /* Doesn't instantiate xcos on close operation */
+        if (sharedInstance == null) {
+            return;
+        }
+
+        final Xcos instance = sharedInstance;
+        final List<XcosDiagram> diagrams = instance.diagrams;
+
+        /*
+         * We are looping in the inverted order because we have to close latest
+         * add diagrams (eg SuperBlockDiagrams) before any others.
+         * 
+         * Furthermore the closeDiagram operation modify the diagram list. Thus
+         * we must *NOT* use i-- there.
+         */
+        for (int i = diagrams.size() - 1; i >= 0; i = diagrams.size() - 1) {
+            instance.close(diagrams.get(i), true);
+        }
+
+        if (instance.palette.getView() != null
+                && instance.palette.getView().isVisible()) {
+            instance.palette.getView().close();
+            instance.palette.setView(null);
+        }
+
+        /* terminate any remaining simulation */
+        InterpreterManagement.requestScilabExec("haltscicos");
+
+        /* Saving modified data */
+        instance.palette.saveConfig();
+        instance.configuration.saveConfig();
+    }
+
+    /**
+     * Debug main function
+     * 
+     * @param args
+     *            command line args (Not used)
+     */
+    public static void main(final String[] args) {
+        xcos();
+    }
+
+    /*
+     * Scilab exported methods.
+     * 
+     * All the following methods must use SwingUtilities method to assert that
+     * the operations will be called on the EDT thread.
+     * 
+     * @see modules/xcos/src/jni/Xcos.giws.xml
+     * 
+     * @see sci_gateway/xcos_gateway.xml
+     * 
+     * @see modules/xcos/sci_gateway/cpp/sci_*.cpp
+     */
+
+    /**
+     * Entry point without filename.
+     * 
+     * This method invoke Xcos operation on the EDT thread.
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static void xcos() {
+        final Xcos instance = getInstance();
+
+        /* load scicos libraries (macros) */
+        InterpreterManagement.requestScilabExec(LOAD_XCOS_LIBS_LOAD_SCICOS);
+
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                instance.open(null);
+                PaletteManager.setVisible(true);
+            }
+        });
+    }
+
+    /**
+     * Entry point with filename
+     * 
+     * This method invoke Xcos operation on the EDT thread.
+     * 
+     * @param fileName
+     *            The filename
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static void xcos(final String fileName) {
+        final Xcos instance = getInstance();
+        final File filename = new File(fileName);
+
+        /* load scicos libraries (macros) */
+        InterpreterManagement.requestScilabExec(LOAD_XCOS_LIBS_LOAD_SCICOS);
+
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    instance.open(filename);
+                }
+            });
+        } catch (final InterruptedException e) {
+            LOG.error(e);
+        } catch (final InvocationTargetException e) {
+            Throwable throwable = e;
+            String firstMessage = null;
+            while (throwable != null) {
+                firstMessage = throwable.getLocalizedMessage();
+                throwable = throwable.getCause();
+            }
+
+            throw new RuntimeException(firstMessage, e);
+        }
+    }
+
+    /**
+     * Close the current xcos session from any thread.
+     * 
+     * This method invoke Xcos operation on the EDT thread. Please prefer using
+     * {@link #closeSession()} when the caller is on the EDT thread.
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static void closeXcosFromScilab() {
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    closeSession();
+                    clearInstance();
+                }
+            });
+        } catch (final InterruptedException e) {
+            LOG.error(e);
+        } catch (final InvocationTargetException e) {
+            Throwable throwable = e;
+            String firstMessage = null;
+            while (throwable != null) {
+                firstMessage = throwable.getLocalizedMessage();
+                throwable = throwable.getCause();
+            }
+
+            throw new RuntimeException(firstMessage, e);
+        }
+    }
+
+    /**
+     * Look in each diagram to find the block corresponding to the given uid and
+     * display a warning message.
+     * 
+     * This method invoke Xcos operation on the EDT thread.
+     * 
+     * @param uid
+     *            A String as UID.
+     * @param message
+     *            The message to display.
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static void warnCellByUID(final String[] uid, final String message) {
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    final ArrayDeque<String> deque = new ArrayDeque<String>(
+                            Arrays.asList(uid));
+
+                    String id;
+                    BasicBlock block = null;
+
+                    // specific case with an empty array
+                    if (deque.isEmpty()) {
+                        return;
+                    }
+
+                    // first element
+                    id = deque.pop();
+                    for (XcosDiagram diagram : getInstance().getDiagrams()) {
+                        block = (BasicBlock) ((mxGraphModel) diagram.getModel())
+                                .getCell(id);
+                        if (block != null) {
+                            break;
+                        }
+                    }
+
+                    // loop to get only the last diagram
+                    while (block instanceof SuperBlock && !deque.isEmpty()) {
+                        block.getParentDiagram()
+                                .warnCellByUID(
+                                        block.getId(),
+                                        XcosMessages.ERROR_UNABLE_TO_COMPILE_THIS_SUPER_BLOCK);
+
+                        final SuperBlock superBlock = (SuperBlock) block;
+                        id = deque.pop();
+
+                        if (!Xcos.getInstance().getDiagrams()
+                                .contains(superBlock.getChild())) {
+                            block.openBlockSettings(null);
+                        }
+                        block = (BasicBlock) ((mxGraphModel) superBlock
+                                .getChild().getModel()).getCell(id);
+                    }
+
+                    // We are unable to find the block with the right id
+                    if (block == null) {
+                        return;
+                    }
+
+                    // finally perform the action on the last block
+                    final XcosDiagram parent = block.getParentDiagram();
+                    parent.warnCellByUID(block.getId(), message);
+
+                    SwingUtilities.invokeLater(new Runnable() {
+                        @Override
+                        public void run() {
+                            /*
+                             * Focus on an existing diagram
+                             */
+                            parent.getParentTab().setCurrent();
+                        }
+                    });
+
+                }
+            });
+        } catch (final InterruptedException e) {
+            LOG.error(e);
+        } catch (final InvocationTargetException e) {
+            Throwable throwable = e;
+            String firstMessage = null;
+            while (throwable != null) {
+                firstMessage = throwable.getLocalizedMessage();
+                throwable = throwable.getCause();
+            }
+
+            throw new RuntimeException(firstMessage, e);
+        }
+    }
+
+    /**
+     * This function convert a Xcos diagram to Scilab variable.
+     * 
+     * This method invoke Xcos operation on the EDT thread.
+     * 
+     * @param xcosFile
+     *            The xcos diagram file
+     * @param h5File
+     *            The target file
+     * @param overwrite
+     *            Does the file will be overwritten ?
+     * @return Not used (compatibility)
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static int xcosDiagramToHDF5(final String xcosFile,
+            final String h5File, final boolean overwrite) {
+        final File file = new File(xcosFile);
+
+        if (exists(h5File)) {
+            if (!overwrite) {
+                return 1;
+            } else {
+                delete(h5File);
+            }
+        }
+
+        if (!file.exists()) {
+            return 1;
+        }
+
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    final XcosDiagram diagram = new XcosDiagram();
+                    diagram.openDiagramFromFile(file);
+                    diagram.dumpToHdf5File(h5File);
+                }
+            });
+        } catch (final InterruptedException e) {
+            throw new RuntimeException(e);
+        } catch (final InvocationTargetException e) {
+            Throwable throwable = e;
+            String firstMessage = null;
+            while (throwable != null) {
+                firstMessage = throwable.getLocalizedMessage();
+                throwable = throwable.getCause();
+            }
+
+            throw new RuntimeException(firstMessage, e);
+        }
+
+        return 0;
+    }
+
+    /**
+     * Open a diagram by uid.
+     * 
+     * This method invoke Xcos operation on the EDT thread.
+     * 
+     * @param uid
+     *            UID path to a block.
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static void xcosDiagramOpen(final String[] uid) {
+        final ArrayDeque<String> deque = new ArrayDeque<String>(
+                Arrays.asList(uid));
+
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    String id;
+                    Object block = null;
+
+                    // specific case with an empty array
+                    if (deque.isEmpty()) {
+                        return;
+                    }
+
+                    // first element
+                    id = deque.pop();
+                    for (XcosDiagram diagram : getInstance().getDiagrams()) {
+                        block = ((mxGraphModel) diagram.getModel()).getCell(id);
+                        if (block instanceof SuperBlock) {
+                            break;
+                        }
+                    }
+
+                    // loop to get only the last diagram
+                    while (block instanceof SuperBlock & !deque.isEmpty()) {
+                        final SuperBlock superBlock = (SuperBlock) block;
+                        id = deque.pop();
+
+                        superBlock.openBlockSettings(null);
+                        block = ((mxGraphModel) superBlock.getChild()
+                                .getModel()).getCell(id);
+                    }
+
+                    // finally perform the action
+                    if (block instanceof SuperBlock) {
+                        ((SuperBlock) block).openBlockSettings(null);
+                    }
+                }
+            });
+        } catch (final InterruptedException e) {
+            LOG.error(e);
+        } catch (final InvocationTargetException e) {
+            Throwable throwable = e;
+            String firstMessage = null;
+            while (throwable != null) {
+                firstMessage = throwable.getLocalizedMessage();
+                throwable = throwable.getCause();
+            }
+
+            throw new RuntimeException(firstMessage, e);
+        }
+    }
+
+    /**
+     * Close a diagram by uid.
+     * 
+     * This method invoke Xcos operation on the EDT thread.
+     * 
+     * @param uid
+     *            The diagram id path
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static void xcosDiagramClose(final String[] uid) {
+        final ArrayDeque<String> deque = new ArrayDeque<String>(
+                Arrays.asList(uid));
+
+        try {
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    String id;
+                    Object block = null;
+
+                    // specific case with an empty array
+                    if (deque.isEmpty()) {
+                        closeSession();
+                    }
+
+                    // first element
+                    id = deque.pop();
+                    for (XcosDiagram diagram : getInstance().getDiagrams()) {
+                        block = ((mxGraphModel) diagram.getModel()).getCell(id);
+                        if (block instanceof SuperBlock) {
+                            break;
+                        }
+                    }
+
+                    // loop to get only the last diagram
+                    while (block instanceof SuperBlock & !deque.isEmpty()) {
+                        final SuperBlock superBlock = (SuperBlock) block;
+                        id = deque.pop();
+
+                        superBlock.openBlockSettings(null);
+                        block = ((mxGraphModel) superBlock.getChild()
+                                .getModel()).getCell(id);
+                    }
+
+                    // finally perform the action
+                    if (block instanceof SuperBlock) {
+                        ((SuperBlock) block).closeBlockSettings();
+                    }
+                }
+            });
+        } catch (final InterruptedException e) {
+            LOG.error(e);
+        } catch (final InvocationTargetException e) {
+            Throwable throwable = e;
+            String firstMessage = null;
+            while (throwable != null) {
+                firstMessage = throwable.getLocalizedMessage();
+                throwable = throwable.getCause();
+            }
+
+            throw new RuntimeException(firstMessage, e);
+        }
+    }
+
+    /**
+     * Look for the parent diagram of the cell in the diagram hierarchy.
+     * 
+     * @param cell
+     *            the cell to search for
+     * @return the associated diagram
+     */
+    public static XcosDiagram findParent(Object cell) {
+        final Xcos instance = getInstance();
+        for (XcosDiagram diag : instance.getDiagrams()) {
+            if (diag.getModel().contains(cell)) {
+                if (cell instanceof BasicBlock) {
+                    ((BasicBlock) cell).setParentDiagram(diag);
+                }
+                return diag;
+            }
+        }
+        return null;
+    }
 }
-//CSON: ClassDataAbstractionCoupling
-//CSON: ClassFanOutComplexity
+// CSON: ClassDataAbstractionCoupling
+// CSON: ClassFanOutComplexity
index 22a2b3e..0e570c9 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2010 - DIGITEO - Clément DAVID
@@ -118,468 +117,471 @@ import com.mxgraph.swing.mxGraphOutline;
  * 
  * This class implement specific operation of an Xcos Tab.
  */
-//CSOFF: ClassFanOutComplexity
-//CSOFF: ClassDataAbstractionCoupling
+// CSOFF: ClassFanOutComplexity
+// CSOFF: ClassDataAbstractionCoupling
 public class XcosTab extends ScilabTab {
 
-       static {
-               DefaultAction.addIconPath(new File(ScilabConstants.SCI,
-                               "/modules/xcos/images/icons/"));
-       }
-
-       /*
-        * Instance fields
-        */
-       private MenuBar menuBar;
-       private Menu fileMenu;
-       private Menu recentsMenu;
-       private Menu edit;
-       private Menu view;
-       private Menu simulate;
-       private Menu format;
-       private Menu alignMenu;
-       private Menu linkStyle;
-       private Menu tools;
-       private Menu help;
-
-       private PushButton openAction;
-       private PushButton saveAction;
-       private PushButton saveAsAction;
-       private PushButton printAction;
-       private PushButton newDiagramAction;
-       private PushButton deleteAction;
-       private PushButton undoAction;
-       private PushButton redoAction;
-       private PushButton fitDiagramToViewAction;
-       private PushButton startAction;
-       private PushButton stopAction;
-       private PushButton zoomInAction;
-       private PushButton zoomOutAction;
-       private PushButton xcosDemonstrationAction;
-       private PushButton xcosDocumentationAction;
-
-       /**
-        * Default constructor
-        * 
-        * @param diagram
-        *            The associated diagram
-        */
-       public XcosTab(final XcosDiagram diagram) {
-               super(XcosMessages.XCOS);
-
-               /** tab association */
-               diagram.setParentTab(this);
-
-               initComponents(diagram);
-
-               ((SwingScilabTab) getAsSimpleTab())
-                               .setWindowIcon(new ImageIcon(
-                                               System.getenv("SCI")
-                                                               + "/modules/gui/images/icons/32x32/apps/utilities-system-monitor.png")
-                                               .getImage());
-
-               // No SimpleTab.addMember(ScilabComponent ...) so perform a raw
-               // association.
-               ((SwingScilabTab) getAsSimpleTab()).setContentPane(diagram
-                               .getAsComponent());
-
-               // Get the palette window position and align on it.
-               if (PaletteManager.isVisible()) {
-                       final Window win = PaletteManager.getInstance().getView()
-                                       .getParentWindow();
-                       final Position palPosition = win.getPosition();
-                       final Size palSize = win.getDims();
-                       final Position mainPosition = new Position(palPosition.getX()
-                                       + palSize.getWidth(), palPosition.getY());
-                       getParentWindow().setPosition(mainPosition);
-               }
-
-               /*
-                * VIEW PORT
-                */
-               XcosTab.createViewPort(diagram);
-
-               setCallback(new CloseAction(diagram));
-               diagram.getAsComponent().addKeyListener(new ArrowKeyListener());
-               diagram.updateTabTitle();
-       }
-
-       /**
-        * Instantiate all the subcomponents of this Tab.
-        * 
-        * @param diagram
-        *            the diagram
-        */
-       private void initComponents(final XcosDiagram diagram) {
-               final Window window = ScilabWindow.createWindow();
-
-               final ConfigurationManager manager = ConfigurationManager.getInstance();
-               final PositionType p = manager.getSettings().getWindows().getDiagram();
-
-               window.setDims(new Size(p.getWidth(), p.getHeight()));
-               window.setPosition(new Position(p.getX(), p.getY()));
-
-               /* Create the menu bar */
-               menuBar = createMenuBar(diagram);
-               addMenuBar(menuBar);
-
-               /* Create the toolbar */
-               final ToolBar toolBar = createToolBar(diagram);
-               addToolBar(toolBar);
-
-               /* Create the infoBar */
-               addInfoBar(ScilabTextBox.createTextBox());
-
-               window.addTab(this);
-               BarUpdater.updateBars(getParentWindowId(), getMenuBar(), getToolBar(),
-                               getInfoBar(), getName());
-       }
-
-       /**
-        * Create the windows menu bar
-        * 
-        * @param diagram
-        *            the diagram
-        * @return the Xcos diagram menu bar
-        */
-       // CSOFF: JavaNCSS
-       private MenuBar createMenuBar(final XcosDiagram diagram) {
-
-               menuBar = ScilabMenuBar.createMenuBar();
-
-               /** FILE MENU */
-               fileMenu = ScilabMenu.createMenu();
-               fileMenu.setText(XcosMessages.FILE);
-               fileMenu.setMnemonic('F');
-
-               fileMenu.add(NewDiagramAction.createMenu(diagram));
-
-               fileMenu.add(OpenAction.createMenu(diagram));
-               fileMenu.addSeparator();
-               fileMenu.add(SaveAction.createMenu(diagram));
-               fileMenu.add(SaveAsAction.createMenu(diagram));
-               fileMenu.add(ExportAction.createMenu(diagram));
-
-               recentsMenu = createRecentMenu();
-
-               fileMenu.add(recentsMenu);
-
-               fileMenu.add(PrintAction.createMenu(diagram));
-               fileMenu.addSeparator();
-               fileMenu.add(CloseAction.createMenu(diagram));
-               fileMenu.addSeparator();
-               fileMenu.add(QuitAction.createMenu(diagram));
-
-               menuBar.add(fileMenu);
-
-               /** Edit menu */
-               edit = ScilabMenu.createMenu();
-               edit.setText(XcosMessages.EDIT);
-               edit.setMnemonic('E');
-               menuBar.add(edit);
-
-               edit.add(UndoAction.undoMenu(diagram));
-               edit.add(RedoAction.redoMenu(diagram));
-               edit.addSeparator();
-               edit.add(CutAction.cutMenu(diagram));
-               edit.add(CopyAction.copyMenu(diagram));
-               edit.add(PasteAction.pasteMenu(diagram));
-               edit.add(DeleteAction.createMenu(diagram));
-               edit.addSeparator();
-               edit.add(SelectAllAction.createMenu(diagram));
-               edit.add(InvertSelectionAction.createMenu(diagram));
-               edit.addSeparator();
-               edit.add(BlockParametersAction.createMenu(diagram));
-               edit.addSeparator();
-               edit.add(RegionToSuperblockAction.createMenu(diagram));
-
-               /** View menu */
-               view = ScilabMenu.createMenu();
-               view.setText(XcosMessages.VIEW);
-               view.setMnemonic('V');
-               menuBar.add(view);
-
-               view.add(ZoomInAction.zoominMenu(diagram));
-               view.add(ZoomOutAction.zoomoutMenu(diagram));
-               view.add(FitDiagramToViewAction.createMenu(diagram));
-               view.add(NormalViewAction.createMenu(diagram));
-               view.addSeparator();
-               view.add(ViewPaletteBrowserAction.createCheckBoxMenu(diagram));
-               view.add(ViewDiagramBrowserAction.createMenu(diagram));
-               final CheckBoxMenuItem menu = ViewViewportAction
-                               .createCheckBoxMenu(diagram);
-               view.add(menu);
-               (diagram).setViewPortMenuItem(menu);
-               view.add(ViewDetailsAction.createMenu(diagram));
-
-               /** Simulation menu */
-               simulate = ScilabMenu.createMenu();
-               simulate.setText(XcosMessages.SIMULATION);
-               simulate.setMnemonic('S');
-               menuBar.add(simulate);
-
-               final MenuItem startMenu = StartAction.createMenu(diagram);
-               final MenuItem stopMenu = StopAction.createMenu(diagram);
-
-               simulate.add(SetupAction.createMenu(diagram));
-               simulate.add(DebugLevelAction.createMenu(diagram));
-               simulate.add(SetContextAction.createMenu(diagram));
-               simulate.add(CompileAction.createMenu(diagram));
-               simulate.add(InitModelicaAction.createMenu(diagram));
-               simulate.add(startMenu);
-               simulate.add(stopMenu);
-
-               /** Format menu */
-               format = ScilabMenu.createMenu();
-               format.setText(XcosMessages.FORMAT);
-               format.setMnemonic('O');
-               menuBar.add(format);
-
-               format.add(RotateAction.createMenu(diagram));
-               format.add(FlipAction.createMenu(diagram));
-               format.add(MirrorAction.createMenu(diagram));
-               format.add(ShowHideShadowAction.createMenu(diagram));
-
-               format.addSeparator();
-               alignMenu = ScilabMenu.createMenu();
-               alignMenu.setText(XcosMessages.ALIGN_BLOCKS);
-               alignMenu.add(AlignBlockActionLeft.createMenu(diagram));
-               alignMenu.add(AlignBlockActionCenter.createMenu(diagram));
-               alignMenu.add(AlignBlockActionRight.createMenu(diagram));
-               alignMenu.addSeparator();
-               alignMenu.add(AlignBlockActionTop.createMenu(diagram));
-               alignMenu.add(AlignBlockActionMiddle.createMenu(diagram));
-               alignMenu.add(AlignBlockActionBottom.createMenu(diagram));
-               format.add(alignMenu);
-               format.addSeparator();
-
-               format.add(BorderColorAction.createMenu(diagram));
-               format.add(FilledColorAction.createMenu(diagram));
-               format.addSeparator();
-
-               linkStyle = ScilabMenu.createMenu();
-               linkStyle.setText(XcosMessages.LINK_STYLE);
-               linkStyle.add(StyleHorizontalAction.createMenu(diagram));
-               linkStyle.add(StyleStraightAction.createMenu(diagram));
-               linkStyle.add(StyleVerticalAction.createMenu(diagram));
-               format.add(linkStyle);
-               format.addSeparator();
-
-               format.add(DiagramBackgroundAction.createMenu(diagram));
-               final CheckBoxMenuItem gridMenu = ViewGridAction
-                               .createCheckBoxMenu(diagram);
-               format.add(gridMenu);
-
-               /** Tools menu */
-               tools = ScilabMenu.createMenu();
-               tools.setText(XcosMessages.TOOLS);
-               tools.setMnemonic('T');
-               menuBar.add(tools);
-
-               tools.add(CodeGenerationAction.createMenu(diagram));
-
-               /** Help menu */
-               help = ScilabMenu.createMenu();
-               help.setText(XcosMessages.HELP);
-               help.setMnemonic('?');
-               menuBar.add(help);
-
-               help.add(XcosDocumentationAction.createMenu(diagram));
-               help.add(BlockDocumentationAction.createMenu(diagram));
-               help.addSeparator();
-               help.add(XcosDemonstrationsAction.createMenu(diagram));
-               help.addSeparator();
-               help.add(AboutXcosAction.createMenu(diagram));
-
-               return menuBar;
-       }
-       // CSON: JavaNCSS
-       
-       /**
-        * Create the recent menu from the previously opened files
-        * @return the recent menu
-        */
-       private Menu createRecentMenu() {
-               final Menu recent;
-
-               recent = ScilabMenu.createMenu();
-               recent.setText(XcosMessages.RECENT_FILES);
-
-               final ConfigurationManager manager = ConfigurationManager.getInstance();
-               final List<DocumentType> recentFiles = manager.getSettings()
-                               .getRecentFiles().getDocument();
-               for (int i = 0; i < recentFiles.size(); i++) {
-                       URL url;
-                       try {
-                               url = new URL(recentFiles.get(i).getUrl());
-                       } catch (final MalformedURLException e) {
-                               LogFactory.getLog(XcosTab.class).error(e);
-                               break;
-                       }
-                       recent.add(RecentFileAction.createMenu(url));
-               }
-
-               ConfigurationManager.getInstance().addPropertyChangeListener(
-                               ConfigurationConstants.RECENT_FILES_CHANGED,
-                               new PropertyChangeListener() {
-                                       @Override
-                                       public void propertyChange(final PropertyChangeEvent evt) {
-                                               assert evt.getPropertyName().equals(
-                                                               ConfigurationConstants.RECENT_FILES_CHANGED);
-
-                                               /*
-                                                * We only handle menu creation there. Return when this
-                                                * is not the case.
-                                                */
-                                               if (evt.getOldValue() != null) {
-                                                       return;
-                                               }
-
-                                               URL url;
-                                               try {
-                                                       url = new URL(((DocumentType) evt.getNewValue())
-                                                                       .getUrl());
-                                               } catch (final MalformedURLException e) {
-                                                       LogFactory.getLog(XcosTab.class).error(e);
-                                                       return;
-                                               }
-
-                                               ((SwingScilabMenu) recent.getAsSimpleMenu()).add(
-                                                               (SwingScilabMenu) RecentFileAction.createMenu(
-                                                                               url).getAsSimpleMenu(), 0);
-                                       }
-                               });
-
-               return recent;
-       }
-
-       /**
-        * Create the Tab toolbar
-        * 
-        * @param diagram
-        *            the associated diagram
-        * @return tool bar
-        */
-       private ToolBar createToolBar(final XcosDiagram diagram) {
-               final ToolBar toolBar = ScilabToolBar.createToolBar();
-
-               newDiagramAction = NewDiagramAction.createButton(diagram);
-               toolBar.add(newDiagramAction);
-
-               openAction = OpenAction.createButton(diagram);
-               toolBar.add(openAction);
-
-               toolBar.addSeparator();
-
-               saveAction = SaveAction.createButton(diagram);
-               toolBar.add(saveAction);
-               saveAsAction = SaveAsAction.createButton(diagram);
-               toolBar.add(saveAsAction);
-
-               toolBar.addSeparator();
-
-               printAction = PrintAction.createButton(diagram);
-               toolBar.add(printAction);
-
-               toolBar.addSeparator();
-
-               deleteAction = DeleteAction.createButton(diagram);
-               toolBar.add(deleteAction);
-
-               toolBar.addSeparator();
-
-               // UNDO / REDO
-               undoAction = UndoAction.undoButton(diagram);
-               redoAction = RedoAction.redoButton(diagram);
-               toolBar.add(undoAction);
-               toolBar.add(redoAction);
-
-               toolBar.addSeparator();
-
-               fitDiagramToViewAction = FitDiagramToViewAction.createButton(diagram);
-               toolBar.add(fitDiagramToViewAction);
-
-               toolBar.addSeparator();
-
-               // START / STOP
-               startAction = StartAction.createButton(diagram);
-               stopAction = StopAction.createButton(diagram);
-
-               toolBar.add(startAction);
-               toolBar.add(stopAction);
-
-               toolBar.addSeparator();
-
-               // ZOOMIN / ZOOMOUT
-               zoomInAction = ZoomInAction.zoominButton(diagram);
-               toolBar.add(zoomInAction);
-               zoomOutAction = ZoomOutAction.zoomoutButton(diagram);
-               toolBar.add(zoomOutAction);
-
-               toolBar.addSeparator();
-
-               xcosDemonstrationAction = XcosDemonstrationsAction
-                               .createButton(diagram);
-               toolBar.add(xcosDemonstrationAction);
-               xcosDocumentationAction = XcosDocumentationAction.createButton(diagram);
-               toolBar.add(xcosDocumentationAction);
-
-               return toolBar;
-       }
-
-       /**
-        * @param xcosDiagramm
-        *            diagram
-        */
-       private static void createViewPort(final ScilabGraph xcosDiagramm) {
-               final Window outline = ScilabWindow.createWindow();
-               final Tab outlineTab = ScilabTab.createTab(XcosMessages.VIEWPORT);
-
-               outlineTab.setCallback(new CloseViewportAction(xcosDiagramm));
+    static {
+        DefaultAction.addIconPath(new File(ScilabConstants.SCI,
+                "/modules/xcos/images/icons/"));
+    }
+
+    /*
+     * Instance fields
+     */
+    private MenuBar menuBar;
+    private Menu fileMenu;
+    private Menu recentsMenu;
+    private Menu edit;
+    private Menu view;
+    private Menu simulate;
+    private Menu format;
+    private Menu alignMenu;
+    private Menu linkStyle;
+    private Menu tools;
+    private Menu help;
+
+    private PushButton openAction;
+    private PushButton saveAction;
+    private PushButton saveAsAction;
+    private PushButton printAction;
+    private PushButton newDiagramAction;
+    private PushButton deleteAction;
+    private PushButton undoAction;
+    private PushButton redoAction;
+    private PushButton fitDiagramToViewAction;
+    private PushButton startAction;
+    private PushButton stopAction;
+    private PushButton zoomInAction;
+    private PushButton zoomOutAction;
+    private PushButton xcosDemonstrationAction;
+    private PushButton xcosDocumentationAction;
+
+    /**
+     * Default constructor
+     * 
+     * @param diagram
+     *            The associated diagram
+     */
+    public XcosTab(final XcosDiagram diagram) {
+        super(XcosMessages.XCOS);
+
+        /** tab association */
+        diagram.setParentTab(this);
+
+        initComponents(diagram);
+
+        ((SwingScilabTab) getAsSimpleTab())
+                .setWindowIcon(new ImageIcon(
+                        System.getenv("SCI")
+                                + "/modules/gui/images/icons/32x32/apps/utilities-system-monitor.png")
+                        .getImage());
+
+        // No SimpleTab.addMember(ScilabComponent ...) so perform a raw
+        // association.
+        ((SwingScilabTab) getAsSimpleTab()).setContentPane(diagram
+                .getAsComponent());
+
+        // Get the palette window position and align on it.
+        if (PaletteManager.isVisible()) {
+            final Window win = PaletteManager.getInstance().getView()
+                    .getParentWindow();
+            final Position palPosition = win.getPosition();
+            final Size palSize = win.getDims();
+            final Position mainPosition = new Position(palPosition.getX()
+                    + palSize.getWidth(), palPosition.getY());
+            getParentWindow().setPosition(mainPosition);
+        }
+
+        /*
+         * VIEW PORT
+         */
+        XcosTab.createViewPort(diagram);
+
+        setCallback(new CloseAction(diagram));
+        diagram.getAsComponent().addKeyListener(new ArrowKeyListener());
+        diagram.updateTabTitle();
+    }
+
+    /**
+     * Instantiate all the subcomponents of this Tab.
+     * 
+     * @param diagram
+     *            the diagram
+     */
+    private void initComponents(final XcosDiagram diagram) {
+        final Window window = ScilabWindow.createWindow();
+
+        final ConfigurationManager manager = ConfigurationManager.getInstance();
+        final PositionType p = manager.getSettings().getWindows().getDiagram();
+
+        window.setDims(new Size(p.getWidth(), p.getHeight()));
+        window.setPosition(new Position(p.getX(), p.getY()));
+
+        /* Create the menu bar */
+        menuBar = createMenuBar(diagram);
+        addMenuBar(menuBar);
+
+        /* Create the toolbar */
+        final ToolBar toolBar = createToolBar(diagram);
+        addToolBar(toolBar);
+
+        /* Create the infoBar */
+        addInfoBar(ScilabTextBox.createTextBox());
+
+        window.addTab(this);
+        BarUpdater.updateBars(getParentWindowId(), getMenuBar(), getToolBar(),
+                getInfoBar(), getName());
+    }
+
+    /**
+     * Create the windows menu bar
+     * 
+     * @param diagram
+     *            the diagram
+     * @return the Xcos diagram menu bar
+     */
+    // CSOFF: JavaNCSS
+    private MenuBar createMenuBar(final XcosDiagram diagram) {
+
+        menuBar = ScilabMenuBar.createMenuBar();
+
+        /** FILE MENU */
+        fileMenu = ScilabMenu.createMenu();
+        fileMenu.setText(XcosMessages.FILE);
+        fileMenu.setMnemonic('F');
+
+        fileMenu.add(NewDiagramAction.createMenu(diagram));
+
+        fileMenu.add(OpenAction.createMenu(diagram));
+        fileMenu.addSeparator();
+        fileMenu.add(SaveAction.createMenu(diagram));
+        fileMenu.add(SaveAsAction.createMenu(diagram));
+        fileMenu.add(ExportAction.createMenu(diagram));
+
+        recentsMenu = createRecentMenu();
+
+        fileMenu.add(recentsMenu);
+
+        fileMenu.add(PrintAction.createMenu(diagram));
+        fileMenu.addSeparator();
+        fileMenu.add(CloseAction.createMenu(diagram));
+        fileMenu.addSeparator();
+        fileMenu.add(QuitAction.createMenu(diagram));
+
+        menuBar.add(fileMenu);
+
+        /** Edit menu */
+        edit = ScilabMenu.createMenu();
+        edit.setText(XcosMessages.EDIT);
+        edit.setMnemonic('E');
+        menuBar.add(edit);
+
+        edit.add(UndoAction.undoMenu(diagram));
+        edit.add(RedoAction.redoMenu(diagram));
+        edit.addSeparator();
+        edit.add(CutAction.cutMenu(diagram));
+        edit.add(CopyAction.copyMenu(diagram));
+        edit.add(PasteAction.pasteMenu(diagram));
+        edit.add(DeleteAction.createMenu(diagram));
+        edit.addSeparator();
+        edit.add(SelectAllAction.createMenu(diagram));
+        edit.add(InvertSelectionAction.createMenu(diagram));
+        edit.addSeparator();
+        edit.add(BlockParametersAction.createMenu(diagram));
+        edit.addSeparator();
+        edit.add(RegionToSuperblockAction.createMenu(diagram));
+
+        /** View menu */
+        view = ScilabMenu.createMenu();
+        view.setText(XcosMessages.VIEW);
+        view.setMnemonic('V');
+        menuBar.add(view);
+
+        view.add(ZoomInAction.zoominMenu(diagram));
+        view.add(ZoomOutAction.zoomoutMenu(diagram));
+        view.add(FitDiagramToViewAction.createMenu(diagram));
+        view.add(NormalViewAction.createMenu(diagram));
+        view.addSeparator();
+        view.add(ViewPaletteBrowserAction.createCheckBoxMenu(diagram));
+        view.add(ViewDiagramBrowserAction.createMenu(diagram));
+        final CheckBoxMenuItem menu = ViewViewportAction
+                .createCheckBoxMenu(diagram);
+        view.add(menu);
+        (diagram).setViewPortMenuItem(menu);
+        view.add(ViewDetailsAction.createMenu(diagram));
+
+        /** Simulation menu */
+        simulate = ScilabMenu.createMenu();
+        simulate.setText(XcosMessages.SIMULATION);
+        simulate.setMnemonic('S');
+        menuBar.add(simulate);
+
+        final MenuItem startMenu = StartAction.createMenu(diagram);
+        final MenuItem stopMenu = StopAction.createMenu(diagram);
+
+        simulate.add(SetupAction.createMenu(diagram));
+        simulate.add(DebugLevelAction.createMenu(diagram));
+        simulate.add(SetContextAction.createMenu(diagram));
+        simulate.add(CompileAction.createMenu(diagram));
+        simulate.add(InitModelicaAction.createMenu(diagram));
+        simulate.add(startMenu);
+        simulate.add(stopMenu);
+
+        /** Format menu */
+        format = ScilabMenu.createMenu();
+        format.setText(XcosMessages.FORMAT);
+        format.setMnemonic('O');
+        menuBar.add(format);
+
+        format.add(RotateAction.createMenu(diagram));
+        format.add(FlipAction.createMenu(diagram));
+        format.add(MirrorAction.createMenu(diagram));
+        format.add(ShowHideShadowAction.createMenu(diagram));
+
+        format.addSeparator();
+        alignMenu = ScilabMenu.createMenu();
+        alignMenu.setText(XcosMessages.ALIGN_BLOCKS);
+        alignMenu.add(AlignBlockActionLeft.createMenu(diagram));
+        alignMenu.add(AlignBlockActionCenter.createMenu(diagram));
+        alignMenu.add(AlignBlockActionRight.createMenu(diagram));
+        alignMenu.addSeparator();
+        alignMenu.add(AlignBlockActionTop.createMenu(diagram));
+        alignMenu.add(AlignBlockActionMiddle.createMenu(diagram));
+        alignMenu.add(AlignBlockActionBottom.createMenu(diagram));
+        format.add(alignMenu);
+        format.addSeparator();
+
+        format.add(BorderColorAction.createMenu(diagram));
+        format.add(FilledColorAction.createMenu(diagram));
+        format.addSeparator();
+
+        linkStyle = ScilabMenu.createMenu();
+        linkStyle.setText(XcosMessages.LINK_STYLE);
+        linkStyle.add(StyleHorizontalAction.createMenu(diagram));
+        linkStyle.add(StyleStraightAction.createMenu(diagram));
+        linkStyle.add(StyleVerticalAction.createMenu(diagram));
+        format.add(linkStyle);
+        format.addSeparator();
+
+        format.add(DiagramBackgroundAction.createMenu(diagram));
+        final CheckBoxMenuItem gridMenu = ViewGridAction
+                .createCheckBoxMenu(diagram);
+        format.add(gridMenu);
+
+        /** Tools menu */
+        tools = ScilabMenu.createMenu();
+        tools.setText(XcosMessages.TOOLS);
+        tools.setMnemonic('T');
+        menuBar.add(tools);
+
+        tools.add(CodeGenerationAction.createMenu(diagram));
+
+        /** Help menu */
+        help = ScilabMenu.createMenu();
+        help.setText(XcosMessages.HELP);
+        help.setMnemonic('?');
+        menuBar.add(help);
+
+        help.add(XcosDocumentationAction.createMenu(diagram));
+        help.add(BlockDocumentationAction.createMenu(diagram));
+        help.addSeparator();
+        help.add(XcosDemonstrationsAction.createMenu(diagram));
+        help.addSeparator();
+        help.add(AboutXcosAction.createMenu(diagram));
+
+        return menuBar;
+    }
+
+    // CSON: JavaNCSS
+
+    /**
+     * Create the recent menu from the previously opened files
+     * 
+     * @return the recent menu
+     */
+    private Menu createRecentMenu() {
+        final Menu recent;
+
+        recent = ScilabMenu.createMenu();
+        recent.setText(XcosMessages.RECENT_FILES);
+
+        final ConfigurationManager manager = ConfigurationManager.getInstance();
+        final List<DocumentType> recentFiles = manager.getSettings()
+                .getRecentFiles().getDocument();
+        for (int i = 0; i < recentFiles.size(); i++) {
+            URL url;
+            try {
+                url = new URL(recentFiles.get(i).getUrl());
+            } catch (final MalformedURLException e) {
+                LogFactory.getLog(XcosTab.class).error(e);
+                break;
+            }
+            recent.add(RecentFileAction.createMenu(url));
+        }
+
+        ConfigurationManager.getInstance().addPropertyChangeListener(
+                ConfigurationConstants.RECENT_FILES_CHANGED,
+                new PropertyChangeListener() {
+                    @Override
+                    public void propertyChange(final PropertyChangeEvent evt) {
+                        assert evt.getPropertyName().equals(
+                                ConfigurationConstants.RECENT_FILES_CHANGED);
+
+                        /*
+                         * We only handle menu creation there. Return when this
+                         * is not the case.
+                         */
+                        if (evt.getOldValue() != null) {
+                            return;
+                        }
+
+                        URL url;
+                        try {
+                            url = new URL(((DocumentType) evt.getNewValue())
+                                    .getUrl());
+                        } catch (final MalformedURLException e) {
+                            LogFactory.getLog(XcosTab.class).error(e);
+                            return;
+                        }
+
+                        ((SwingScilabMenu) recent.getAsSimpleMenu()).add(
+                                (SwingScilabMenu) RecentFileAction.createMenu(
+                                        url).getAsSimpleMenu(), 0);
+                    }
+                });
+
+        return recent;
+    }
+
+    /**
+     * Create the Tab toolbar
+     * 
+     * @param diagram
+     *            the associated diagram
+     * @return tool bar
+     */
+    private ToolBar createToolBar(final XcosDiagram diagram) {
+        final ToolBar toolBar = ScilabToolBar.createToolBar();
+
+        newDiagramAction = NewDiagramAction.createButton(diagram);
+        toolBar.add(newDiagramAction);
+
+        openAction = OpenAction.createButton(diagram);
+        toolBar.add(openAction);
+
+        toolBar.addSeparator();
+
+        saveAction = SaveAction.createButton(diagram);
+        toolBar.add(saveAction);
+        saveAsAction = SaveAsAction.createButton(diagram);
+        toolBar.add(saveAsAction);
+
+        toolBar.addSeparator();
+
+        printAction = PrintAction.createButton(diagram);
+        toolBar.add(printAction);
+
+        toolBar.addSeparator();
+
+        deleteAction = DeleteAction.createButton(diagram);
+        toolBar.add(deleteAction);
+
+        toolBar.addSeparator();
+
+        // UNDO / REDO
+        undoAction = UndoAction.undoButton(diagram);
+        redoAction = RedoAction.redoButton(diagram);
+        toolBar.add(undoAction);
+        toolBar.add(redoAction);
+
+        toolBar.addSeparator();
+
+        fitDiagramToViewAction = FitDiagramToViewAction.createButton(diagram);
+        toolBar.add(fitDiagramToViewAction);
+
+        toolBar.addSeparator();
+
+        // START / STOP
+        startAction = StartAction.createButton(diagram);
+        stopAction = StopAction.createButton(diagram);
+
+        toolBar.add(startAction);
+        toolBar.add(stopAction);
+
+        toolBar.addSeparator();
+
+        // ZOOMIN / ZOOMOUT
+        zoomInAction = ZoomInAction.zoominButton(diagram);
+        toolBar.add(zoomInAction);
+        zoomOutAction = ZoomOutAction.zoomoutButton(diagram);
+        toolBar.add(zoomOutAction);
+
+        toolBar.addSeparator();
+
+        xcosDemonstrationAction = XcosDemonstrationsAction
+                .createButton(diagram);
+        toolBar.add(xcosDemonstrationAction);
+        xcosDocumentationAction = XcosDocumentationAction.createButton(diagram);
+        toolBar.add(xcosDocumentationAction);
+
+        return toolBar;
+    }
+
+    /**
+     * @param xcosDiagramm
+     *            diagram
+     */
+    private static void createViewPort(final ScilabGraph xcosDiagramm) {
+        final Window outline = ScilabWindow.createWindow();
+        final Tab outlineTab = ScilabTab.createTab(XcosMessages.VIEWPORT);
 
-               final MenuBar vpMenuBar = ScilabMenuBar.createMenuBar();
-               outlineTab.addMenuBar(vpMenuBar);
+        outlineTab.setCallback(new CloseViewportAction(xcosDiagramm));
+
+        final MenuBar vpMenuBar = ScilabMenuBar.createMenuBar();
+        outlineTab.addMenuBar(vpMenuBar);
 
-               final Menu vpMenu = ScilabMenu.createMenu();
-               vpMenu.setText(XcosMessages.VIEWPORT);
-               vpMenu.setMnemonic('V');
-               vpMenuBar.add(vpMenu);
+        final Menu vpMenu = ScilabMenu.createMenu();
+        vpMenu.setText(XcosMessages.VIEWPORT);
+        vpMenu.setMnemonic('V');
+        vpMenuBar.add(vpMenu);
 
-               vpMenu.add(CloseViewportAction.createMenu(xcosDiagramm));
+        vpMenu.add(CloseViewportAction.createMenu(xcosDiagramm));
 
-               outlineTab.getAsSimpleTab().setInfoBar(ScilabTextBox.createTextBox());
+        outlineTab.getAsSimpleTab().setInfoBar(ScilabTextBox.createTextBox());
 
-               ((XcosDiagram) xcosDiagramm).setViewPort(outlineTab);
+        ((XcosDiagram) xcosDiagramm).setViewPort(outlineTab);
 
-               // Creates the graph outline component
-               final mxGraphOutline graphOutline = new mxGraphOutline(xcosDiagramm
-                               .getAsComponent());
+        // Creates the graph outline component
+        final mxGraphOutline graphOutline = new mxGraphOutline(
+                xcosDiagramm.getAsComponent());
 
-               graphOutline.setDrawLabels(true);
+        graphOutline.setDrawLabels(true);
 
-               ((SwingScilabTab) outlineTab.getAsSimpleTab())
-                               .setContentPane(graphOutline);
-               outline.addTab(outlineTab);
-               outline.setVisible(false);
-               outlineTab.setVisible(false);
-       }
+        ((SwingScilabTab) outlineTab.getAsSimpleTab())
+                .setContentPane(graphOutline);
+        outline.addTab(outlineTab);
+        outline.setVisible(false);
+        outlineTab.setVisible(false);
+    }
 
-       /**
-        * Set the current tab and the associated window visible when a unique Tab
-        * is docked.
-        * 
-        * @param newVisibleState the new state
-        * @see org.scilab.modules.gui.tab.ScilabTab#setVisible(boolean)
-        */
-       @Override
-       public void setVisible(final boolean newVisibleState) {
-               if (getParentWindow().getNbDockedObjects() == 1) {
-                       getParentWindow().setVisible(newVisibleState);
-               }
+    /**
+     * Set the current tab and the associated window visible when a unique Tab
+     * is docked.
+     * 
+     * @param newVisibleState
+     *            the new state
+     * @see org.scilab.modules.gui.tab.ScilabTab#setVisible(boolean)
+     */
+    @Override
+    public void setVisible(final boolean newVisibleState) {
+        if (getParentWindow().getNbDockedObjects() == 1) {
+            getParentWindow().setVisible(newVisibleState);
+        }
 
-               super.setVisible(newVisibleState);
-       }
+        super.setVisible(newVisibleState);
+    }
 }
 
-//CSON: ClassDataAbstractionCoupling
-//CSON: ClassFanOutComplexity
+// CSON: ClassDataAbstractionCoupling
+// CSON: ClassFanOutComplexity
index 61e9a8f..423f191 100644 (file)
@@ -23,52 +23,52 @@ import org.scilab.modules.gui.utils.ScilabAboutBox;
 import org.scilab.modules.xcos.Xcos;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
-
 /**
  * Display about box for Xcos
  */
 public class AboutXcosAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.ABOUT_XCOS;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = 0;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = 0;
+    /** Name of the action */
+    public static final String NAME = XcosMessages.ABOUT_XCOS;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = 0;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = 0;
+
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated Scilab graph
+     */
+    public AboutXcosAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
+
+    /**
+     * Menu created for "Help menu"
+     * 
+     * @param scilabGraph
+     *            associated Scilab graph
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, AboutXcosAction.class);
+    }
+
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        String[] contents = { Xcos.TRADENAME, "", XcosMessages.CONSORTIUM,
+                XcosMessages.COPYRIGHT_INRIA, "", XcosMessages.SCICOS_BASED };
 
-       /**
-        * Constructor
-        * @param scilabGraph associated Scilab graph
-        */
-       public AboutXcosAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
+        ScilabAboutBox.createAboutBox(XcosMessages.ABOUT_XCOS, contents, null,
+                null);
 
-       /**
-        * Menu created for "Help menu"
-        * @param scilabGraph associated Scilab graph
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, AboutXcosAction.class);
-       }
-       
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               String[] contents = {
-                               Xcos.TRADENAME,
-                               "",
-                               XcosMessages.CONSORTIUM,
-                               XcosMessages.COPYRIGHT_INRIA,
-                               "",
-                               XcosMessages.SCICOS_BASED};
-               
-               ScilabAboutBox.createAboutBox(XcosMessages.ABOUT_XCOS, contents, null, null);
-       
     }
 }
index a955590..86c558f 100644 (file)
@@ -29,43 +29,50 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * Diagram closing management
  */
 public class CloseAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.CLOSE;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = KeyEvent.VK_W;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+    /** Name of the action */
+    public static final String NAME = XcosMessages.CLOSE;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = KeyEvent.VK_W;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit()
+            .getMenuShortcutKeyMask();
 
-       /**
-        * Constructor
-        * @param scilabGraph associated diagram
-        */
-       public CloseAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     */
+    public CloseAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
 
-       /**
-        * Menu for diagram menubar
-        * @param scilabGraph associated diagram
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, CloseAction.class);
-       }
+    /**
+     * Menu for diagram menubar
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, CloseAction.class);
+    }
 
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               if (getGraph(null) instanceof SuperBlockDiagram) {
-                       ((SuperBlockDiagram) getGraph(null)).getContainer().closeBlockSettings();
-               } else {
-                       Xcos.getInstance().close((XcosDiagram) getGraph(null), false);
-               }
-       }
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        if (getGraph(null) instanceof SuperBlockDiagram) {
+            ((SuperBlockDiagram) getGraph(null)).getContainer()
+                    .closeBlockSettings();
+        } else {
+            Xcos.getInstance().close((XcosDiagram) getGraph(null), false);
+        }
+    }
 
 }
index f10c243..c4a1b4e 100644 (file)
@@ -27,38 +27,44 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * Close action for viewport tab
  */
 public class CloseViewportAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.CLOSE;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = KeyEvent.VK_W;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
-       
-       /**
-        * Constructor
-        * @param scilabGraph associated Scilab Graph
-        */
-       public CloseViewportAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
+    /** Name of the action */
+    public static final String NAME = XcosMessages.CLOSE;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = KeyEvent.VK_W;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit()
+            .getMenuShortcutKeyMask();
 
-       /**
-        * Create the close menu for the menu bar 
-        * @param scilabGraph associated Scilab Graph
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, CloseViewportAction.class);
-       }
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     */
+    public CloseViewportAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
 
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               ((XcosDiagram) getGraph(null)).setViewPortVisible(false);
-       }
+    /**
+     * Create the close menu for the menu bar
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, CloseViewportAction.class);
+    }
+
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        ((XcosDiagram) getGraph(null)).setViewPortVisible(false);
+    }
 }
index fda6863..bfe3ac8 100644 (file)
@@ -35,80 +35,88 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * Diagram compilation management
  */
 public class CompileAction extends SimulationNotRunningAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.COMPILE;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = 0;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = 0;
-
-       /**
-        * Constructor
-        * @param scilabGraph associated diagram
-        */
-       public CompileAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
-
-       /**
-        * Create associated menu
-        * @param scilabGraph associated diagram
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, CompileAction.class);
-       }
-
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               ((XcosDiagram) getGraph(null)).info(XcosMessages.EXPORT_IN_PROGRESS);
-               
-               final String temp;
-               try {
-                       temp = FileUtils.createTempFile();
-               } catch (IOException e1) {
-                       LogFactory.getLog(CompileAction.class).error(e1);
-                       return;
-               }
-               
-               (new SwingWorker<Void, Void>() {
-
-                       @Override
-                       protected Void doInBackground() throws Exception {
-                               ((XcosDiagram) getGraph(null)).dumpToHdf5File(temp);
-                               ((XcosDiagram) getGraph(null)).setReadOnly(true);
-                               return null;
-                       }
-                       
-                       @Override
-                       protected void done() {
-                               ((XcosDiagram) getGraph(null)).info(XcosMessages.COMPILATION_IN_PROGRESS);
-                               
-                               String cmd = buildCall("import_from_hdf5", temp) 
-                                                    + "cpr = xcos_compile(scs_m);";
-                               
-                               final ActionListener action = new ActionListener() {
-                                       @Override
-                                       public void actionPerformed(ActionEvent e) {
-                                               delete(temp);
-                                               ((XcosDiagram) getGraph(null)).setReadOnly(false);
-                                               ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
-                                       }
-                               };
-                               
-                               try {
-                                       ScilabInterpreterManagement.asynchronousScilabExec(action, cmd);
-                               } catch (InterpreterException e) {
-                                       LogFactory.getLog(CompileAction.class).error(e);
-                               }
-                       }
-                       
-               }).execute();
-       }
+    /** Name of the action */
+    public static final String NAME = XcosMessages.COMPILE;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = 0;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = 0;
+
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     */
+    public CompileAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
+
+    /**
+     * Create associated menu
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, CompileAction.class);
+    }
+
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        ((XcosDiagram) getGraph(null)).info(XcosMessages.EXPORT_IN_PROGRESS);
+
+        final String temp;
+        try {
+            temp = FileUtils.createTempFile();
+        } catch (IOException e1) {
+            LogFactory.getLog(CompileAction.class).error(e1);
+            return;
+        }
+
+        (new SwingWorker<Void, Void>() {
+
+            @Override
+            protected Void doInBackground() throws Exception {
+                ((XcosDiagram) getGraph(null)).dumpToHdf5File(temp);
+                ((XcosDiagram) getGraph(null)).setReadOnly(true);
+                return null;
+            }
+
+            @Override
+            protected void done() {
+                ((XcosDiagram) getGraph(null))
+                        .info(XcosMessages.COMPILATION_IN_PROGRESS);
+
+                String cmd = buildCall("import_from_hdf5", temp)
+                        + "cpr = xcos_compile(scs_m);";
+
+                final ActionListener action = new ActionListener() {
+                    @Override
+                    public void actionPerformed(ActionEvent e) {
+                        delete(temp);
+                        ((XcosDiagram) getGraph(null)).setReadOnly(false);
+                        ((XcosDiagram) getGraph(null))
+                                .info(XcosMessages.EMPTY_INFO);
+                    }
+                };
+
+                try {
+                    ScilabInterpreterManagement.asynchronousScilabExec(action,
+                            cmd);
+                } catch (InterpreterException e) {
+                    LogFactory.getLog(CompileAction.class).error(e);
+                }
+            }
+
+        }).execute();
+    }
 }
index c60fca8..6eccd2a 100644 (file)
@@ -11,7 +11,6 @@
  *
  */
 
-
 package org.scilab.modules.xcos.actions;
 
 import java.awt.event.ActionEvent;
@@ -26,84 +25,92 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * Set the debug level
  */
 public class DebugLevelAction extends SimulationNotRunningAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.SET_DEBUG;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = 0;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = 0;
+    /** Name of the action */
+    public static final String NAME = XcosMessages.SET_DEBUG;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = 0;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = 0;
+
+    /**
+     * Get the enum level value
+     */
+    public static enum DebugLevel {
+        /** No trace nor debug */
+        ZERO(0, XcosMessages.DEBUGLEVEL_0),
+        /** Discrete/Continous switch */
+        ONE(1, XcosMessages.DEBUGLEVEL_1),
+        /** Per block trace */
+        TWO(2, XcosMessages.DEBUGLEVEL_2),
+        /** Debug blocks without trace */
+        THREE(3, XcosMessages.DEBUGLEVEL_3);
+
+        private int level;
+        private String debugName;
+
+        /**
+         * @param realNumber
+         *            level
+         * @param name
+         *            debug name
+         */
+        private DebugLevel(int realNumber, String name) {
+            level = realNumber;
+            debugName = name;
+        }
+
+        /**
+         * @return value
+         */
+        public int getValue() {
+            return level;
+        }
+
+        /**
+         * @return the localized debug name
+         * @see java.lang.Enum#toString()
+         */
+        @Override
+        public String toString() {
+            return debugName;
+        }
+    }
+
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            corresponding Scilab Graph
+     */
+    public DebugLevelAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
 
-       /**
-        * Get the enum level value
-        */
-       public static enum DebugLevel {
-               /** No trace nor debug */
-               ZERO (0, XcosMessages.DEBUGLEVEL_0),
-               /** Discrete/Continous switch */
-               ONE (1, XcosMessages.DEBUGLEVEL_1),
-               /** Per block trace */
-               TWO (2, XcosMessages.DEBUGLEVEL_2),
-               /** Debug blocks without trace */
-               THREE (3, XcosMessages.DEBUGLEVEL_3);
-               
-               private int level;
-               private String debugName;
-               
-               /**
-                * @param realNumber level
-                * @param name debug name
-                */
-               private DebugLevel(int realNumber, String name) {
-                       level = realNumber;
-                       debugName = name;
-               }
-               
-               /**
-                * @return value
-                */
-               public int getValue() {
-                       return level;
-               }
-               
-               /**
-                * @return the localized debug name
-                * @see java.lang.Enum#toString()
-                */
-               @Override
-               public String toString() {
-                       return debugName;
-               }
-       }
-       
-       /**
-        * Constructor
-        * @param scilabGraph corresponding Scilab Graph
-        */
-       public DebugLevelAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
+    /**
+     * Action !!!
+     * 
+     * @param e
+     *            action parameters
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        final XcosDiagram diag = (XcosDiagram) getGraph(e);
+        final DebugLevelDialog dialog = new DebugLevelDialog(
+                diag.getAsComponent(), diag.getScicosParameters());
 
-       /**
-        * Action !!!
-        * @param e action parameters
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               final XcosDiagram diag = (XcosDiagram) getGraph(e);
-               final DebugLevelDialog dialog = new DebugLevelDialog(diag.getAsComponent(), diag.getScicosParameters());
-               
-               dialog.pack();
-               dialog.setVisible(true);
-       }
+        dialog.pack();
+        dialog.setVisible(true);
+    }
 
-       /**
-        * @param scilabGraph graph
-        * @return menu item
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, DebugLevelAction.class);
-       }
+    /**
+     * @param scilabGraph
+     *            graph
+     * @return menu item
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, DebugLevelAction.class);
+    }
 }
index 4784119..9aa7f4e 100644 (file)
@@ -29,48 +29,54 @@ import com.mxgraph.swing.mxGraphComponent;
  * Diagram background color changing
  */
 public class DiagramBackgroundAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.DIAGRAM_BACKGROUND;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = 0;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = 0;
+    /** Name of the action */
+    public static final String NAME = XcosMessages.DIAGRAM_BACKGROUND;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = 0;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = 0;
 
-       /**
-        * Constructor
-        * @param scilabGraph associated diagram
-        */
-       public DiagramBackgroundAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     */
+    public DiagramBackgroundAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
 
-       /**
-        * Menu for diagram menubar
-        * @param scilabGraph associated diagram
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, DiagramBackgroundAction.class);
-       }
+    /**
+     * Menu for diagram menubar
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, DiagramBackgroundAction.class);
+    }
 
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               mxGraphComponent graphComponent = getGraph(null).getAsComponent();
-               Color newColor = JColorChooser.showDialog(graphComponent, XcosMessages.DIAGRAM_BACKGROUND, null);
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        mxGraphComponent graphComponent = getGraph(null).getAsComponent();
+        Color newColor = JColorChooser.showDialog(graphComponent,
+                XcosMessages.DIAGRAM_BACKGROUND, null);
 
-               if (newColor != null) {
-                       graphComponent.getViewport().setOpaque(false);
-                       graphComponent.setBackground(newColor);
-               }       
+        if (newColor != null) {
+            graphComponent.getViewport().setOpaque(false);
+            graphComponent.setBackground(newColor);
+        }
 
-               // Forces a repaint of the outline
-               graphComponent.getGraph().repaint();
-       }
+        // Forces a repaint of the outline
+        graphComponent.getGraph().repaint();
+    }
 
 }
index 81d7db1..137c3da 100644 (file)
@@ -34,61 +34,67 @@ import org.scilab.modules.xcos.utils.XcosMessages;
 /**
  * Dump the graph into scilab.
  * 
- * This action is only used for debugging purpose but not on any release version.
+ * This action is only used for debugging purpose but not on any release
+ * version.
  */
 public class DumpAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.DUMP;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = 0;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = 0;
+    /** Name of the action */
+    public static final String NAME = XcosMessages.DUMP;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = 0;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = 0;
 
     /**
-     * @param scilabGraph graph
+     * @param scilabGraph
+     *            graph
      */
     public DumpAction(ScilabGraph scilabGraph) {
-       super(scilabGraph);
+        super(scilabGraph);
     }
 
     /**
-     * @param scilabGraph graph
+     * @param scilabGraph
+     *            graph
      * @return push button
      */
     public static PushButton dumpButton(ScilabGraph scilabGraph) {
-       return createButton(scilabGraph, DumpAction.class);
+        return createButton(scilabGraph, DumpAction.class);
     }
 
     /**
-     * @param scilabGraph graph
+     * @param scilabGraph
+     *            graph
      * @return menu item
      */
     public static MenuItem dumpMenu(ScilabGraph scilabGraph) {
-       return createMenu(scilabGraph, DumpAction.class);
+        return createMenu(scilabGraph, DumpAction.class);
     }
 
     /**
      * Do action !!!
-     * @param e params
+     * 
+     * @param e
+     *            params
      * @see org.scilab.modules.gui.events.callback.CallBack#actionPerformed(java.awt.event.ActionEvent)
      */
-       @Override
+    @Override
     public void actionPerformed(ActionEvent e) {
-               try {
-                   String temp = FileUtils.createTempFile();
-                   new File(temp).deleteOnExit();
-                   ((XcosDiagram) getGraph(e)).dumpToHdf5File(temp);
-                   try {
-                       String cmd = buildCall("import_from_hdf5", temp);
-                       cmd += buildCall("deletefile", temp);
-                       ScilabInterpreterManagement.synchronousScilabExec(cmd);
-                   } catch (InterpreterException e1) {
-                               LogFactory.getLog(DumpAction.class).error(e1);
-                       }
-               } catch (IOException e1) {
-                       LogFactory.getLog(DumpAction.class).error(e1);
-               }
+        try {
+            String temp = FileUtils.createTempFile();
+            new File(temp).deleteOnExit();
+            ((XcosDiagram) getGraph(e)).dumpToHdf5File(temp);
+            try {
+                String cmd = buildCall("import_from_hdf5", temp);
+                cmd += buildCall("deletefile", temp);
+                ScilabInterpreterManagement.synchronousScilabExec(cmd);
+            } catch (InterpreterException e1) {
+                LogFactory.getLog(DumpAction.class).error(e1);
+            }
+        } catch (IOException e1) {
+            LogFactory.getLog(DumpAction.class).error(e1);
+        }
     }
 }
index 6a26636..35c223d 100644 (file)
@@ -54,786 +54,942 @@ import com.mxgraph.util.mxUtils;
  * Customize the block representation.
  */
 public class EditFormatAction extends DefaultAction {
-       /**
-        * Name of the action
-        */
-       public static final String NAME = XcosMessages.EDIT + XcosMessages.DOTS;
-       /**
-        * Icon of the action
-        */
-       public static final String SMALL_ICON = "select-by-color.png";
-       /**
-        * Mnemonic key for the action
-        */
-       public static final int MNEMONIC_KEY = KeyEvent.VK_F2;
-       /**
-        * Accelerator key for the action
-        */
-       public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
-
-       /**
-        * Prefix used to tag text node. 
-        */
-       public static final String HASH_IDENTIFIER = "#identifier";
-       
-       /**
-        * The default color used on non initialized border color.
-        */
-       private static final Color DEFAULT_BORDERCOLOR = Color.BLACK;
-       /**
-        * The default color used on non initialized filled color.
-        */
-       private static final Color DEFAULT_FILLCOLOR = Color.WHITE;
-       /**
-        * Default geometry used while adding a label to a block
-        * (on the middle and below the bottom of the parent block)
-        */
-       private static final mxGeometry DEFAULT_LABEL_GEOMETRY = new mxGeometry(0.5, 1.1, 0.0, 0.0);
-
-       /**
-        * Default constructor
-        * @param scilabGraph the current graph
-        */
-       public EditFormatAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
-
-       /**
-        * Menu added to the menubar
-        * @param scilabGraph associated diagram
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, EditFormatAction.class);
-       }
-       
-       /**
-        * Create a new dialog for editing this cell
-        * @param c the current component 
-        * @param name the window name
-        * @param selectedCell the selected cell
-        * @param graph the current graph
-        */
-       public static void showDialog(ScilabComponent c, String name, mxCell selectedCell, XcosDiagram graph) {
-               /*
-                * Looking for the parent window
-                */
-               final Frame window = javax.swing.JOptionPane.getFrameForComponent(c);
-               
-               /*
-                * Create and show the dialog
-                */
-               EditFormatDialog dialog = createDialog(selectedCell, graph, window);
-               dialog.setName(name);
-               dialog.setVisible(true);
-       }
-
-       /**
-        * Create the dialog and set the default values
-        * @param cell the current selected cell
-        * @param graph the current graph
-        * @param window the current windows
-        * @return the instantiated dialog
-        */
-       // CSOFF: NPathComplexity
-       // CSOFF: JavaNCSS
-       private static EditFormatDialog createDialog(final mxCell cell, final XcosDiagram graph, 
-                       final Frame window) {
-               String working;
-               Color border;
-               Color fill;
-               String font;
-               int fontSize;
-               int fontStyle;
-               Color textColor;
-               String text;
-               String image = null;
-               
-               final mxGraphModel model = (mxGraphModel) graph.getModel();
-               final StyleMap cellStyle = new StyleMap(cell.getStyle());
-               
-               final mxCell identifier;
-               final StyleMap identifierStyle;
-               if (cell instanceof TextBlock) {
-                       identifier = cell;
-                       identifierStyle = cellStyle;
-               } else {
-                       identifier = getCellIdentifier(cell, model);
-                       identifierStyle = new StyleMap(identifier.getStyle());
-               }
-               
-               /*
-                * Stroke color
-                */
-               working = cellStyle.get(mxConstants.STYLE_STROKECOLOR);
-               if (working == null) {
-                       border = DEFAULT_BORDERCOLOR;
-               } else {
-                       border = mxUtils.parseColor(working);
-               }
-               
-               /*
-                * Fill color
-                */
-               working = cellStyle.get(mxConstants.STYLE_FILLCOLOR);
-               if (working == null) {
-                       fill = DEFAULT_FILLCOLOR;
-               } else {
-                       fill = mxUtils.parseColor(working);
-               }
-               
-               /*
-                * Font
-                */
-               working = identifierStyle.get(mxConstants.STYLE_FONTFAMILY);
-               if (working == null) {
-                       font = mxConstants.DEFAULT_FONTFAMILY;
-               } else {
-                       font = working;
-               }
-               
-               /*
-                * Font size
-                */
-               working = identifierStyle.get(mxConstants.STYLE_FONTSIZE);
-               if (working == null) {
-                       fontSize = mxConstants.DEFAULT_FONTSIZE;
-               } else {
-                       fontSize = Integer.parseInt(working);
-               }
-
-               /*
-                * Font modifier
-                */
-               working = identifierStyle.get(mxConstants.STYLE_FONTSTYLE);
-               if (working == null) {
-                       fontStyle = 0;
-               } else {
-                       fontStyle = Integer.parseInt(working);
-               }
-               
-               /*
-                * Font color
-                */
-               working = identifierStyle.get(mxConstants.STYLE_FONTCOLOR);
-               if (working == null) {
-                       textColor = Color.BLACK;
-               } else {
-                       textColor = mxUtils.parseColor(working);
-               }
-               
-               /*
-                * Image
-                */
-               working = cellStyle.get(mxConstants.STYLE_IMAGE);
-               if (working != null) {
-                       image = working;
-               }
-
-               /*
-                * Text
-                */
-               final Object current = model.getValue(identifier);
-               if (current == null) {
-                       text = "";
-               } else {
-                       text = mxUtils.getBodyMarkup(current.toString(), false);
-               }
-               
-               EditFormatDialog dialog = new EditFormatDialog(window);
-               dialog.setValues(border, fill, font, fontSize, fontStyle, textColor, text, image);
-               dialog.setGraph(graph);
-               dialog.setCell(cell);
-               return dialog;
-       }
-       // CSON: JavaNCSS
-       // CSON: NPathComplexity
-
-       /**
-        * Return the identifier for the cell
-        * 
-        * @param cell the cell to check
-        * @param model the current model
-        * @return the identifier cell
-        */
-       private static mxCell getCellIdentifier(final mxCell cell,
-                       final mxGraphModel model) {
-               final mxCell identifier;
-               final String cellId = cell.getId() + HASH_IDENTIFIER;
-               if (model.getCell(cellId) == null) {
-                       // create the identifier
-                       identifier = new mxCell(null, (mxGeometry) DEFAULT_LABEL_GEOMETRY.clone(), "noLabel=0;opacity=0;");
-                       identifier.getGeometry().setRelative(true);
-                       identifier.setVertex(true);
-                       identifier.setConnectable(false);
-                       identifier.setId(cellId);
-                       
-                       // add the identifier
-                       model.add(cell, identifier, cell.getChildCount());
-               } else {
-                       identifier = (mxCell) model.getCell(cellId);
-               }
-               return identifier;
-       }
-       
-       /**
-        * Update the cell value from the dialog ones.
-        * 
-        * @param dialog the current dialog
-        * @param borderColor the selected border color
-        * @param backgroundColor the selected background color
-        * @param fontName the selected font name
-        * @param fontSize the selected font size
-        * @param isBold is the text bold ?
-        * @param isItalic is the text italic ?
-        * @param textColor the selected color
-        * @param text the typed text
-        * @param image the image URL
-        */
-       // CSOFF: NPathComplexity
-       private static void updateFromDialog(EditFormatDialog dialog, Color borderColor, Color backgroundColor, 
-                               String fontName, int fontSize, Color textColor, boolean isBold, boolean isItalic, String text, String image) {
-               final XcosDiagram graph = dialog.getGraph();
-               final mxGraphModel model = (mxGraphModel) graph.getModel();
-               
-               final mxCell cell = dialog.getCell();
-               final StyleMap cellStyle = new StyleMap(cell.getStyle());
-               
-               final mxCell identifier; 
-               final StyleMap identifierStyle;
-               if (cell instanceof TextBlock) {
-                       identifier = cell;
-                       identifierStyle = cellStyle;
-               } else {
-                       identifier = getCellIdentifier(cell, model);
-                       identifierStyle = new StyleMap(identifier.getStyle());
-               }
-               
-               if (!borderColor.equals(DEFAULT_BORDERCOLOR)) {
-                       cellStyle.put(mxConstants.STYLE_STROKECOLOR, mxUtils.hexString(borderColor));
-               }
-               
-               if (!backgroundColor.equals(DEFAULT_FILLCOLOR)) {
-                       cellStyle.put(mxConstants.STYLE_FILLCOLOR, mxUtils.hexString(backgroundColor));
-               }
-               
-               if (!fontName.equals(mxConstants.DEFAULT_FONTFAMILY)) {
-                       identifierStyle.put(mxConstants.STYLE_FONTFAMILY, fontName);
-               }
-               
-               applyFontStyle(isBold, isItalic, identifierStyle);
-               
-               if (fontSize != mxConstants.DEFAULT_FONTSIZE) {
-                       identifierStyle.put(mxConstants.STYLE_FONTSIZE, Integer.toString(fontSize));
-               }
-               
-               if (!textColor.equals(DEFAULT_BORDERCOLOR)) {
-                       identifierStyle.put(mxConstants.STYLE_FONTCOLOR, mxUtils.hexString(textColor));
-               }
-
-               applyImage(image, cellStyle);
-                       
-               model.setStyle(cell, cellStyle.toString());
-               if (cell != identifier) {
-                       model.setStyle(identifier, identifierStyle.toString());
-               }
-               
-               graph.cellLabelChanged(identifier, text, false);
-               graph.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED,
-                               "cell", identifier, "value", text, "parent", cell));
-               
-               /*
-                * Should also update diagram title
-                */
-               if (cell instanceof SuperBlock) {
-                       graph.cellLabelChanged(cell, text, false);
-               }
-       }
-       // CSON: NPathComplexity
-
-       /**
-        * Apply image to the identifier style
-        * 
-        * @param image the image path
-        * @param cellStyle the cell style
-        */
-       private static void applyImage(String image, final StyleMap cellStyle) {
-               if (image != null && !image.isEmpty()) {
-                       String path;
-                       try {
-                               URL url = new URL(image);
-                               path = url.toExternalForm();
-                       } catch (MalformedURLException e) {
-                               path = image;
-                       }
-
-                       cellStyle.put(mxConstants.STYLE_IMAGE, path);
-               } else {
-                       cellStyle.remove(mxConstants.STYLE_IMAGE);
-               }
-       }
-
-       /**
-        * Apply font style to the identifier style
-        * 
-        * @param isBold true if the font is bold
-        * @param isItalic true is the font is italic
-        * @param identifierStyle the identifier style 
-        */
-       private static void applyFontStyle(boolean isBold, boolean isItalic,
-                       final StyleMap identifierStyle) {
-               int fontStyle = 0;
-               if (isBold) {
-                       fontStyle |= mxConstants.FONT_BOLD;
-               }
-               if (isItalic) {
-                       fontStyle |= mxConstants.FONT_ITALIC;
-               }
-               
-               identifierStyle.put(mxConstants.STYLE_FONTSTYLE, Integer.toString(fontStyle));
-       }
-       
-       /**
-        * Open a dialog to set the parameters
-        * @param e the current event
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               XcosDiagram graph = (XcosDiagram) getGraph(null);
-               final Object selectedCell = graph.getSelectionCell();
-               
-               if (selectedCell == null) {
-                       return;
-               }
-               
-               EditFormatAction.showDialog((ScilabComponent) graph
-                               .getAsComponent(), NAME, (mxCell) selectedCell, graph);
-               
-               graph.getView().clear(selectedCell, true, true);
-               graph.refresh();
-       }
-       
-       /**
-        * Dialog used to edit the current cell.
-        * 
-        * This class perform UI instantiation and thus doesn't pass checkstyle
-        * metrics.
-        */
-       // CSOFF: ClassDataAbstractionCoupling
-       // CSOFF: ClassFanOutComplexity
-       private static final class EditFormatDialog extends javax.swing.JDialog  {
-               private static final int TEXT_AREA_ROWS = 5;
-               private static final int TEXT_AREA_COLUMNS = 20;
-               
-               /**
-                * The default model used to set a font size. 
-                */
-               private static final SpinnerModel FONTSIZE_MODEL = new javax.swing.SpinnerNumberModel(10, 0, 100, 1);
-               /**
-                * The default border size used to separate buttons
-                */
-               private static final int BORDER_SIZE = 10;
-               
-           private javax.swing.JColorChooser backgroundColorChooser;
-           private javax.swing.JColorChooser borderColorChooser;
-           private javax.swing.JColorChooser textColorChooser;
-           private javax.swing.JComboBox fontNameComboBox;
-           private javax.swing.JLabel fontNameLabel;
-           private javax.swing.JSpinner fontSizeSpinner;
-           private javax.swing.JLabel fontSizeLabel;
-           private javax.swing.JCheckBox fontStyleBold;
-           private javax.swing.JCheckBox fontStyleItalic;
-           private javax.swing.JLabel fontStyleLabel;
-           private javax.swing.JPanel backgroundPane;
-           
-           private javax.swing.JLabel imagePathLabel;
-           private javax.swing.JTextField imagePath;
-           private javax.swing.JButton imageFileChooserBtn;
-           
-           private javax.swing.JPanel jPanel2;
-           private javax.swing.JScrollPane jScrollPane1;
-           private javax.swing.JTabbedPane mainTab;
-           private javax.swing.JTextArea textArea;
-           private javax.swing.JPanel textFormat;
-           
-           private javax.swing.JButton cancelButton;
-           private javax.swing.JButton okButton;
-           private javax.swing.JPanel buttonPane;
-           
-           private XcosDiagram graph;
-           private mxCell cell;
-               
-           private final transient ChangeListener defaultChangeListener = new ChangeListener() {
-               /**
-                * Update the text area font
-                * @param e the event parameters
-                * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
-                */
-                       @Override
-                       public void stateChanged(ChangeEvent e) {
-                               updateFont();
-                       }
-               };
-               
-               private final transient ActionListener defaultActionListener = new ActionListener() {
-               /**
-                * Update the text area font
-                * @param e the event parameters
-                * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
-                */
-                       @Override
-                       public void actionPerformed(ActionEvent e) {
-                               updateFont();
-                       }
-               };
-               
-               /**
-                * Construct the dialog
-                * 
-                * @param f the current graph frame
-                */
-               public EditFormatDialog(Frame f) {
-                       super(f, true);
-                       setDefaultCloseOperation(DISPOSE_ON_CLOSE);
-                       setLocationRelativeTo(f);
-                       
-                       initComponents();
-               }
-
-               /**
-                * Initialize the dialog parameters
-                * 
-                * @param borderColor the default border color
-                * @param backgroundColor the default background color
-                * @param fontName The default font name
-                * @param fontSize the default font size
-                * @param fontStyle the current font style
-                * @param textColor the current text color
-                * @param text the current text
-                * @param image the current URL of the image (may be null, absolute or relative)
-                */
-               public void setValues(Color borderColor, Color backgroundColor, 
-                               String fontName, int fontSize, int fontStyle, Color textColor, 
-                               String text, String image) {
-                       borderColorChooser.setColor(borderColor);
-                       backgroundColorChooser.setColor(backgroundColor);
-                       textColorChooser.setColor(textColor);
-                       
-                       fontNameComboBox.getModel().setSelectedItem(fontName);
-                       fontSizeSpinner.getModel().setValue(fontSize);
-                       
-                       fontStyleBold.setSelected((fontStyle & mxConstants.FONT_BOLD) != 0);
-                       fontStyleItalic.setSelected((fontStyle & mxConstants.FONT_ITALIC) != 0);
-                       
-                       textArea.setText(text);
-                       if (image != null) {
-                               imagePath.setText(image);
-                       }
-               }
-               
-               /**
-                * @param graph the current graph to set
-                */
-               public void setGraph(XcosDiagram graph) {
-                       this.graph = graph;
-               }
-               
-               /**
-                * @return the current graph
-                */
-               public XcosDiagram getGraph() {
-                       return graph;
-               }
-               
-               /**
-                * Set the currently selected cell
-                * @param selectedCell the current cell
-                */
-               public void setCell(mxCell selectedCell) {
-                       cell = selectedCell;
-                       
-                       // enable/disable the fill color pane
-                       if (selectedCell.isVertex()) {
-                               mainTab.addTab(XcosMessages.FILL_COLOR, backgroundPane);
-                       } else {
-                               mainTab.remove(backgroundPane);
-                       }
-                       
-                       pack();
-               }
-               
-               /** 
-                * @return the currently selected cell
-                */
-               public mxCell getCell() {
-                       return cell;
-               }
-
-               /**
-                * @return the current dialog
-                */
-               public EditFormatDialog getDialog() {
-                       return this;
-               }
-               
-               /**
-                * Initialize the dialog.
-                * 
-                * This code is UI initialization and thus doesn't pass checkstyle
-                * metrics.
-                */
-               // CSOFF: JavaNCSS
-               // CSOFF: LineLength
-               // CSOFF: MethodLength
-               private void initComponents() {
-                       
-               mainTab = new javax.swing.JTabbedPane();
-               borderColorChooser = new javax.swing.JColorChooser();
-               backgroundColorChooser = new javax.swing.JColorChooser();
-               textColorChooser = new javax.swing.JColorChooser();
-               textFormat = new javax.swing.JPanel();
-               jPanel2 = new javax.swing.JPanel();
-               fontSizeLabel = new javax.swing.JLabel();
-               fontSizeSpinner = new javax.swing.JSpinner();
-               fontNameLabel = new javax.swing.JLabel();
-               fontNameComboBox = new javax.swing.JComboBox();
-               fontStyleBold = new javax.swing.JCheckBox();
-               fontStyleItalic = new javax.swing.JCheckBox();
-               fontStyleLabel = new javax.swing.JLabel();
-               imageFileChooserBtn = new javax.swing.JButton(XcosMessages.DOTS);
-               imagePathLabel = new javax.swing.JLabel();
-               imagePath = new javax.swing.JTextField(TEXT_AREA_COLUMNS);
-               backgroundPane = new javax.swing.JPanel();
-               
-               jScrollPane1 = new javax.swing.JScrollPane();
-               textArea = new javax.swing.JTextArea();
-               
-               textArea.setColumns(TEXT_AREA_COLUMNS);
-               textArea.setRows(TEXT_AREA_ROWS);
-               textArea.setLineWrap(true);
-               textArea.setWrapStyleWord(true);
-               
-               cancelButton = new javax.swing.JButton(XcosMessages.CANCEL);
-               okButton = new javax.swing.JButton(XcosMessages.OK);
-               buttonPane = new javax.swing.JPanel();
-
-               backgroundPane.setLayout(new java.awt.BorderLayout());
-               textFormat.setLayout(new java.awt.BorderLayout());
-
-               fontSizeLabel.setText(XcosMessages.FONT_SIZE);
-
-               fontSizeSpinner.setModel(FONTSIZE_MODEL);
-               fontSizeSpinner.addChangeListener(defaultChangeListener);
-
-               fontNameLabel.setText(XcosMessages.FONT_NAME);
-
-                       fontNameComboBox.setModel(new javax.swing.DefaultComboBoxModel(
-                                       GraphicsEnvironment.getLocalGraphicsEnvironment()
-                                                       .getAvailableFontFamilyNames()));
-                       
-               fontNameComboBox.addActionListener(defaultActionListener);
-               
-               fontStyleLabel.setText(XcosMessages.FONT_STYLE);
-               
-               fontStyleBold.setText(XcosMessages.BOLD);
-               fontStyleBold.addChangeListener(defaultChangeListener);
-               
-               fontStyleItalic.setText(XcosMessages.ITALIC);
-               fontStyleItalic.addChangeListener(defaultChangeListener);
-               
-               imagePathLabel.setText(XcosMessages.IMAGE_PATH);
-               
-               javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
-               jPanel2.setLayout(jPanel2Layout);
-               jPanel2Layout.setHorizontalGroup(
-                   jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-                   .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
-                       .addContainerGap()
-                       .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
-                           .addComponent(fontNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-                           .addComponent(fontSizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
-                           .addComponent(fontStyleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-                       .addGap(BORDER_SIZE)
-                       .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
-                           .addComponent(fontNameComboBox, 0, javax.swing.GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
-                           .addComponent(fontSizeSpinner, 0, javax.swing.GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
-                           .addGroup(jPanel2Layout.createSequentialGroup()
-                               .addComponent(fontStyleBold)
-                               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                               .addComponent(fontStyleItalic)))
-                       .addContainerGap())
-               );
-               jPanel2Layout.setVerticalGroup(
-                   jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-                   .addGroup(jPanel2Layout.createSequentialGroup()
-                       .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-                           .addComponent(fontSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-                           .addComponent(fontSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
-                       .addGap(BORDER_SIZE)
-                       .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-                           .addComponent(fontNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-                           .addComponent(fontNameComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
-                       .addGap(BORDER_SIZE)
-                       .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-                           .addComponent(fontStyleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-                           .addComponent(fontStyleBold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
-                           .addComponent(fontStyleItalic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
-                       .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-               );
-
-               textFormat.add(jPanel2, java.awt.BorderLayout.PAGE_END);
-
-               jScrollPane1.setViewportView(textArea);
-               jScrollPane1.setBackground(Color.WHITE);
-
-               textFormat.add(jScrollPane1, java.awt.BorderLayout.CENTER);
-               
-               backgroundPane.add(backgroundColorChooser, java.awt.BorderLayout.CENTER);
-               javax.swing.JPanel filePane = new javax.swing.JPanel();
-               filePane.setBorder(BorderFactory.createEtchedBorder());
-               filePane.add(imagePathLabel);
-               filePane.add(imagePath);
-               filePane.add(imageFileChooserBtn);
-               backgroundPane.add(filePane, java.awt.BorderLayout.SOUTH);
-
-               mainTab.addTab(XcosMessages.TEXT_SETTINGS, textFormat);
-               mainTab.addTab(XcosMessages.BORDER_COLOR, borderColorChooser);
-               mainTab.addTab(XcosMessages.TEXT_COLOR, textColorChooser);
-               // backgroundColorChooser is added on the setCell method only if the cell is a vertex
-               // mainTab.addTab(XcosMessages.FILL_COLOR, backgroundColorChooser);
-
-               mainTab.addChangeListener(defaultChangeListener);
-               
-                       cancelButton.addActionListener(new ActionListener() {
-                               /**
-                                * On cancel close the window
-                                * 
-                                * @param e
-                                *            the current event parameter
-                                * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
-                                */
-                               @Override
-                               public void actionPerformed(ActionEvent e) {
-                                       getDialog().dispose();
-                               }
-                       });
-
-                       okButton.addActionListener(new ActionListener() {
-                               /**
-                                * On OK, set the current parameter on the cell
-                                * 
-                                * @param e
-                                *            the current parameters
-                                * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
-                                */
-                               @Override
-                               public void actionPerformed(ActionEvent e) {
-                                       graph.getModel().beginUpdate();
-                                       EditFormatAction.updateFromDialog(getDialog(),
-                                                       borderColorChooser.getColor(),
-                                                       backgroundColorChooser.getColor(),
-                                                       (String) fontNameComboBox.getSelectedItem(),
-                                                       (Integer) fontSizeSpinner.getValue(), 
-                                                       textColorChooser.getColor(),
-                                                       fontStyleBold.isSelected(),
-                                                       fontStyleItalic.isSelected(),
-                                                       textArea.getText(),
-                                                       imagePath.getText());
-                                       graph.getModel().endUpdate();
-                                       getDialog().dispose();
-                               }
-                       });
-                       
-                       imageFileChooserBtn.addActionListener(new ActionListener() {
-                               /**
-                                * On file chooser open the file chooser with image filter.
-                                * @param e the event
-                                * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
-                                */
-                               @Override
-                               public void actionPerformed(ActionEvent e) {
-                                       javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
-                                       javax.swing.filechooser.FileNameExtensionFilter filter = new javax.swing.filechooser.FileNameExtensionFilter(
-                                               "Images", "jpg", "png", "svg", "gif");
-                                       chooser.setFileFilter(filter);
-                                       
-                                       final String current = imagePath.getText();
-                                       final File savedFile = getGraph().getSavedFile();
-                                       if (current != null && !current.isEmpty()) {
-                                               try {
-                                                       // try to handle an absolute URL
-                                                       final URI uri = new URI(current);
-                                                       chooser.setSelectedFile(new File(uri));
-                                               } catch (URISyntaxException e1) {
-                                                       // this is a relative path
-                                                       if (savedFile != null) {
-                                                               final File parent = savedFile.getParentFile();
-                                                               chooser.setSelectedFile(new File(parent, current));
-                                                       }
-                                               }
-                                       } else {
-                                               if (savedFile != null) {
-                                                       chooser.setCurrentDirectory(savedFile.getParentFile());
-                                               }
-                                       }
-                                       
-                                   int returnVal = chooser.showOpenDialog(mainTab);
-                                   if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
-                                               if (savedFile != null) {
-                                                       final String relativeChild = savedFile.getParentFile().toURI()
-                                                               .relativize(chooser.getSelectedFile()
-                                                                       .toURI()).toASCIIString();
-                                                       imagePath.setText(relativeChild);
-                                               } else {
-                                                       final String uri = chooser.getSelectedFile().toURI().toASCIIString();
-                                                       imagePath.setText(uri);
-                                               }
-                                   }
-                               }
-                       });
-                       
-               getRootPane().setDefaultButton(okButton);
-               
-               buttonPane.setLayout(new javax.swing.BoxLayout(buttonPane, javax.swing.BoxLayout.LINE_AXIS));
-                       buttonPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(
-                                       BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
-               buttonPane.add(javax.swing.Box.createHorizontalGlue());
-               buttonPane.add(cancelButton);
-                       buttonPane.add(javax.swing.Box.createRigidArea(new Dimension(
-                                       BORDER_SIZE, 0)));
-               buttonPane.add(okButton);
-
-               java.awt.Container contentPane = getContentPane();
-               contentPane.add(mainTab, java.awt.BorderLayout.CENTER);
-               contentPane.add(buttonPane, java.awt.BorderLayout.PAGE_END);
-               }
-               // CSON: JavaNCSS
-               // CSON: LineLength
-               // CSON: MethodLength
-
-               /**
-                * Update the text area from the font
-                */
-               protected void updateFont() {
-                       int style = 0;
-                       if (fontStyleBold.isSelected()) {
-                               style |= Font.BOLD;
-                       }
-                       if (fontStyleItalic.isSelected()) {
-                               style |= Font.ITALIC;
-                       }
-                       
-                       Font f = new Font((String) fontNameComboBox.getSelectedItem(), style,
-                                       (Integer) fontSizeSpinner.getValue());
-                       textArea.setFont(f);
-                       textArea.setBackground(backgroundColorChooser.getColor());
-                       textArea.setForeground(textColorChooser.getColor());
-                       
-                       // Repaint the parent scroll pane to force a full redraw call. 
-                       jScrollPane1.repaint();
-               }
-       }
-       // CSON: ClassDataAbstractionCoupling
-       // CSON: ClassFanOutComplexity
+    /**
+     * Name of the action
+     */
+    public static final String NAME = XcosMessages.EDIT + XcosMessages.DOTS;
+    /**
+     * Icon of the action
+     */
+    public static final String SMALL_ICON = "select-by-color.png";
+    /**
+     * Mnemonic key for the action
+     */
+    public static final int MNEMONIC_KEY = KeyEvent.VK_F2;
+    /**
+     * Accelerator key for the action
+     */
+    public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit()
+            .getMenuShortcutKeyMask();
+
+    /**
+     * Prefix used to tag text node.
+     */
+    public static final String HASH_IDENTIFIER = "#identifier";
+
+    /**
+     * The default color used on non initialized border color.
+     */
+    private static final Color DEFAULT_BORDERCOLOR = Color.BLACK;
+    /**
+     * The default color used on non initialized filled color.
+     */
+    private static final Color DEFAULT_FILLCOLOR = Color.WHITE;
+    /**
+     * Default geometry used while adding a label to a block (on the middle and
+     * below the bottom of the parent block)
+     */
+    private static final mxGeometry DEFAULT_LABEL_GEOMETRY = new mxGeometry(
+            0.5, 1.1, 0.0, 0.0);
+
+    /**
+     * Default constructor
+     * 
+     * @param scilabGraph
+     *            the current graph
+     */
+    public EditFormatAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
+
+    /**
+     * Menu added to the menubar
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, EditFormatAction.class);
+    }
+
+    /**
+     * Create a new dialog for editing this cell
+     * 
+     * @param c
+     *            the current component
+     * @param name
+     *            the window name
+     * @param selectedCell
+     *            the selected cell
+     * @param graph
+     *            the current graph
+     */
+    public static void showDialog(ScilabComponent c, String name,
+            mxCell selectedCell, XcosDiagram graph) {
+        /*
+         * Looking for the parent window
+         */
+        final Frame window = javax.swing.JOptionPane.getFrameForComponent(c);
+
+        /*
+         * Create and show the dialog
+         */
+        EditFormatDialog dialog = createDialog(selectedCell, graph, window);
+        dialog.setName(name);
+        dialog.setVisible(true);
+    }
+
+    /**
+     * Create the dialog and set the default values
+     * 
+     * @param cell
+     *            the current selected cell
+     * @param graph
+     *            the current graph
+     * @param window
+     *            the current windows
+     * @return the instantiated dialog
+     */
+    // CSOFF: NPathComplexity
+    // CSOFF: JavaNCSS
+    private static EditFormatDialog createDialog(final mxCell cell,
+            final XcosDiagram graph, final Frame window) {
+        String working;
+        Color border;
+        Color fill;
+        String font;
+        int fontSize;
+        int fontStyle;
+        Color textColor;
+        String text;
+        String image = null;
+
+        final mxGraphModel model = (mxGraphModel) graph.getModel();
+        final StyleMap cellStyle = new StyleMap(cell.getStyle());
+
+        final mxCell identifier;
+        final StyleMap identifierStyle;
+        if (cell instanceof TextBlock) {
+            identifier = cell;
+            identifierStyle = cellStyle;
+        } else {
+            identifier = getCellIdentifier(cell, model);
+            identifierStyle = new StyleMap(identifier.getStyle());
+        }
+
+        /*
+         * Stroke color
+         */
+        working = cellStyle.get(mxConstants.STYLE_STROKECOLOR);
+        if (working == null) {
+            border = DEFAULT_BORDERCOLOR;
+        } else {
+            border = mxUtils.parseColor(working);
+        }
+
+        /*
+         * Fill color
+         */
+        working = cellStyle.get(mxConstants.STYLE_FILLCOLOR);
+        if (working == null) {
+            fill = DEFAULT_FILLCOLOR;
+        } else {
+            fill = mxUtils.parseColor(working);
+        }
+
+        /*
+         * Font
+         */
+        working = identifierStyle.get(mxConstants.STYLE_FONTFAMILY);
+        if (working == null) {
+            font = mxConstants.DEFAULT_FONTFAMILY;
+        } else {
+            font = working;
+        }
+
+        /*
+         * Font size
+         */
+        working = identifierStyle.get(mxConstants.STYLE_FONTSIZE);
+        if (working == null) {
+            fontSize = mxConstants.DEFAULT_FONTSIZE;
+        } else {
+            fontSize = Integer.parseInt(working);
+        }
+
+        /*
+         * Font modifier
+         */
+        working = identifierStyle.get(mxConstants.STYLE_FONTSTYLE);
+        if (working == null) {
+            fontStyle = 0;
+        } else {
+            fontStyle = Integer.parseInt(working);
+        }
+
+        /*
+         * Font color
+         */
+        working = identifierStyle.get(mxConstants.STYLE_FONTCOLOR);
+        if (working == null) {
+            textColor = Color.BLACK;
+        } else {
+            textColor = mxUtils.parseColor(working);
+        }
+
+        /*
+         * Image
+         */
+        working = cellStyle.get(mxConstants.STYLE_IMAGE);
+        if (working != null) {
+            image = working;
+        }
+
+        /*
+         * Text
+         */
+        final Object current = model.getValue(identifier);
+        if (current == null) {
+            text = "";
+        } else {
+            text = mxUtils.getBodyMarkup(current.toString(), false);
+        }
+
+        EditFormatDialog dialog = new EditFormatDialog(window);
+        dialog.setValues(border, fill, font, fontSize, fontStyle, textColor,
+                text, image);
+        dialog.setGraph(graph);
+        dialog.setCell(cell);
+        return dialog;
+    }
+
+    // CSON: JavaNCSS
+    // CSON: NPathComplexity
+
+    /**
+     * Return the identifier for the cell
+     * 
+     * @param cell
+     *            the cell to check
+     * @param model
+     *            the current model
+     * @return the identifier cell
+     */
+    private static mxCell getCellIdentifier(final mxCell cell,
+            final mxGraphModel model) {
+        final mxCell identifier;
+        final String cellId = cell.getId() + HASH_IDENTIFIER;
+        if (model.getCell(cellId) == null) {
+            // create the identifier
+            identifier = new mxCell(null,
+                    (mxGeometry) DEFAULT_LABEL_GEOMETRY.clone(),
+                    "noLabel=0;opacity=0;");
+            identifier.getGeometry().setRelative(true);
+            identifier.setVertex(true);
+            identifier.setConnectable(false);
+            identifier.setId(cellId);
+
+            // add the identifier
+            model.add(cell, identifier, cell.getChildCount());
+        } else {
+            identifier = (mxCell) model.getCell(cellId);
+        }
+        return identifier;
+    }
+
+    /**
+     * Update the cell value from the dialog ones.
+     * 
+     * @param dialog
+     *            the current dialog
+     * @param borderColor
+     *            the selected border color
+     * @param backgroundColor
+     *            the selected background color
+     * @param fontName
+     *            the selected font name
+     * @param fontSize
+     *            the selected font size
+     * @param isBold
+     *            is the text bold ?
+     * @param isItalic
+     *            is the text italic ?
+     * @param textColor
+     *            the selected color
+     * @param text
+     *            the typed text
+     * @param image
+     *            the image URL
+     */
+    // CSOFF: NPathComplexity
+    private static void updateFromDialog(EditFormatDialog dialog,
+            Color borderColor, Color backgroundColor, String fontName,
+            int fontSize, Color textColor, boolean isBold, boolean isItalic,
+            String text, String image) {
+        final XcosDiagram graph = dialog.getGraph();
+        final mxGraphModel model = (mxGraphModel) graph.getModel();
+
+        final mxCell cell = dialog.getCell();
+        final StyleMap cellStyle = new StyleMap(cell.getStyle());
+
+        final mxCell identifier;
+        final StyleMap identifierStyle;
+        if (cell instanceof TextBlock) {
+            identifier = cell;
+            identifierStyle = cellStyle;
+        } else {
+            identifier = getCellIdentifier(cell, model);
+            identifierStyle = new StyleMap(identifier.getStyle());
+        }
+
+        if (!borderColor.equals(DEFAULT_BORDERCOLOR)) {
+            cellStyle.put(mxConstants.STYLE_STROKECOLOR,
+                    mxUtils.hexString(borderColor));
+        }
+
+        if (!backgroundColor.equals(DEFAULT_FILLCOLOR)) {
+            cellStyle.put(mxConstants.STYLE_FILLCOLOR,
+                    mxUtils.hexString(backgroundColor));
+        }
+
+        if (!fontName.equals(mxConstants.DEFAULT_FONTFAMILY)) {
+            identifierStyle.put(mxConstants.STYLE_FONTFAMILY, fontName);
+        }
+
+        applyFontStyle(isBold, isItalic, identifierStyle);
+
+        if (fontSize != mxConstants.DEFAULT_FONTSIZE) {
+            identifierStyle.put(mxConstants.STYLE_FONTSIZE,
+                    Integer.toString(fontSize));
+        }
+
+        if (!textColor.equals(DEFAULT_BORDERCOLOR)) {
+            identifierStyle.put(mxConstants.STYLE_FONTCOLOR,
+                    mxUtils.hexString(textColor));
+        }
+
+        applyImage(image, cellStyle);
+
+        model.setStyle(cell, cellStyle.toString());
+        if (cell != identifier) {
+            model.setStyle(identifier, identifierStyle.toString());
+        }
+
+        graph.cellLabelChanged(identifier, text, false);
+        graph.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED, "cell",
+                identifier, "value", text, "parent", cell));
+
+        /*
+         * Should also update diagram title
+         */
+        if (cell instanceof SuperBlock) {
+            graph.cellLabelChanged(cell, text, false);
+        }
+    }
+
+    // CSON: NPathComplexity
+
+    /**
+     * Apply image to the identifier style
+     * 
+     * @param image
+     *            the image path
+     * @param cellStyle
+     *            the cell style
+     */
+    private static void applyImage(String image, final StyleMap cellStyle) {
+        if (image != null && !image.isEmpty()) {
+            String path;
+            try {
+                URL url = new URL(image);
+                path = url.toExternalForm();
+            } catch (MalformedURLException e) {
+                path = image;
+            }
+
+            cellStyle.put(mxConstants.STYLE_IMAGE, path);
+        } else {
+            cellStyle.remove(mxConstants.STYLE_IMAGE);
+        }
+    }
+
+    /**
+     * Apply font style to the identifier style
+     * 
+     * @param isBold
+     *            true if the font is bold
+     * @param isItalic
+     *            true is the font is italic
+     * @param identifierStyle
+     *            the identifier style
+     */
+    private static void applyFontStyle(boolean isBold, boolean isItalic,
+            final StyleMap identifierStyle) {
+        int fontStyle = 0;
+        if (isBold) {
+            fontStyle |= mxConstants.FONT_BOLD;
+        }
+        if (isItalic) {
+            fontStyle |= mxConstants.FONT_ITALIC;
+        }
+
+        identifierStyle.put(mxConstants.STYLE_FONTSTYLE,
+                Integer.toString(fontStyle));
+    }
+
+    /**
+     * Open a dialog to set the parameters
+     * 
+     * @param e
+     *            the current event
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        XcosDiagram graph = (XcosDiagram) getGraph(null);
+        final Object selectedCell = graph.getSelectionCell();
+
+        if (selectedCell == null) {
+            return;
+        }
+
+        EditFormatAction.showDialog((ScilabComponent) graph.getAsComponent(),
+                NAME, (mxCell) selectedCell, graph);
+
+        graph.getView().clear(selectedCell, true, true);
+        graph.refresh();
+    }
+
+    /**
+     * Dialog used to edit the current cell.
+     * 
+     * This class perform UI instantiation and thus doesn't pass checkstyle
+     * metrics.
+     */
+    // CSOFF: ClassDataAbstractionCoupling
+    // CSOFF: ClassFanOutComplexity
+    private static final class EditFormatDialog extends javax.swing.JDialog {
+        private static final int TEXT_AREA_ROWS = 5;
+        private static final int TEXT_AREA_COLUMNS = 20;
+
+        /**
+         * The default model used to set a font size.
+         */
+        private static final SpinnerModel FONTSIZE_MODEL = new javax.swing.SpinnerNumberModel(
+                10, 0, 100, 1);
+        /**
+         * The default border size used to separate buttons
+         */
+        private static final int BORDER_SIZE = 10;
+
+        private javax.swing.JColorChooser backgroundColorChooser;
+        private javax.swing.JColorChooser borderColorChooser;
+        private javax.swing.JColorChooser textColorChooser;
+        private javax.swing.JComboBox fontNameComboBox;
+        private javax.swing.JLabel fontNameLabel;
+        private javax.swing.JSpinner fontSizeSpinner;
+        private javax.swing.JLabel fontSizeLabel;
+        private javax.swing.JCheckBox fontStyleBold;
+        private javax.swing.JCheckBox fontStyleItalic;
+        private javax.swing.JLabel fontStyleLabel;
+        private javax.swing.JPanel backgroundPane;
+
+        private javax.swing.JLabel imagePathLabel;
+        private javax.swing.JTextField imagePath;
+        private javax.swing.JButton imageFileChooserBtn;
+
+        private javax.swing.JPanel jPanel2;
+        private javax.swing.JScrollPane jScrollPane1;
+        private javax.swing.JTabbedPane mainTab;
+        private javax.swing.JTextArea textArea;
+        private javax.swing.JPanel textFormat;
+
+        private javax.swing.JButton cancelButton;
+        private javax.swing.JButton okButton;
+        private javax.swing.JPanel buttonPane;
+
+        private XcosDiagram graph;
+        private mxCell cell;
+
+        private final transient ChangeListener defaultChangeListener = new ChangeListener() {
+            /**
+             * Update the text area font
+             * 
+             * @param e
+             *            the event parameters
+             * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
+             */
+            @Override
+            public void stateChanged(ChangeEvent e) {
+                updateFont();
+            }
+        };
+
+        private final transient ActionListener defaultActionListener = new ActionListener() {
+            /**
+             * Update the text area font
+             * 
+             * @param e
+             *            the event parameters
+             * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
+             */
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                updateFont();
+            }
+        };
+
+        /**
+         * Construct the dialog
+         * 
+         * @param f
+         *            the current graph frame
+         */
+        public EditFormatDialog(Frame f) {
+            super(f, true);
+            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+            setLocationRelativeTo(f);
+
+            initComponents();
+        }
+
+        /**
+         * Initialize the dialog parameters
+         * 
+         * @param borderColor
+         *            the default border color
+         * @param backgroundColor
+         *            the default background color
+         * @param fontName
+         *            The default font name
+         * @param fontSize
+         *            the default font size
+         * @param fontStyle
+         *            the current font style
+         * @param textColor
+         *            the current text color
+         * @param text
+         *            the current text
+         * @param image
+         *            the current URL of the image (may be null, absolute or
+         *            relative)
+         */
+        public void setValues(Color borderColor, Color backgroundColor,
+                String fontName, int fontSize, int fontStyle, Color textColor,
+                String text, String image) {
+            borderColorChooser.setColor(borderColor);
+            backgroundColorChooser.setColor(backgroundColor);
+            textColorChooser.setColor(textColor);
+
+            fontNameComboBox.getModel().setSelectedItem(fontName);
+            fontSizeSpinner.getModel().setValue(fontSize);
+
+            fontStyleBold.setSelected((fontStyle & mxConstants.FONT_BOLD) != 0);
+            fontStyleItalic
+                    .setSelected((fontStyle & mxConstants.FONT_ITALIC) != 0);
+
+            textArea.setText(text);
+            if (image != null) {
+                imagePath.setText(image);
+            }
+        }
+
+        /**
+         * @param graph
+         *            the current graph to set
+         */
+        public void setGraph(XcosDiagram graph) {
+            this.graph = graph;
+        }
+
+        /**
+         * @return the current graph
+         */
+        public XcosDiagram getGraph() {
+            return graph;
+        }
+
+        /**
+         * Set the currently selected cell
+         * 
+         * @param selectedCell
+         *            the current cell
+         */
+        public void setCell(mxCell selectedCell) {
+            cell = selectedCell;
+
+            // enable/disable the fill color pane
+            if (selectedCell.isVertex()) {
+                mainTab.addTab(XcosMessages.FILL_COLOR, backgroundPane);
+            } else {
+                mainTab.remove(backgroundPane);
+            }
+
+            pack();
+        }
+
+        /**
+         * @return the currently selected cell
+         */
+        public mxCell getCell() {
+            return cell;
+        }
+
+        /**
+         * @return the current dialog
+         */
+        public EditFormatDialog getDialog() {
+            return this;
+        }
+
+        /**
+         * Initialize the dialog.
+         * 
+         * This code is UI initialization and thus doesn't pass checkstyle
+         * metrics.
+         */
+        // CSOFF: JavaNCSS
+        // CSOFF: LineLength
+        // CSOFF: MethodLength
+        private void initComponents() {
+
+            mainTab = new javax.swing.JTabbedPane();
+            borderColorChooser = new javax.swing.JColorChooser();
+            backgroundColorChooser = new javax.swing.JColorChooser();
+            textColorChooser = new javax.swing.JColorChooser();
+            textFormat = new javax.swing.JPanel();
+            jPanel2 = new javax.swing.JPanel();
+            fontSizeLabel = new javax.swing.JLabel();
+            fontSizeSpinner = new javax.swing.JSpinner();
+            fontNameLabel = new javax.swing.JLabel();
+            fontNameComboBox = new javax.swing.JComboBox();
+            fontStyleBold = new javax.swing.JCheckBox();
+            fontStyleItalic = new javax.swing.JCheckBox();
+            fontStyleLabel = new javax.swing.JLabel();
+            imageFileChooserBtn = new javax.swing.JButton(XcosMessages.DOTS);
+            imagePathLabel = new javax.swing.JLabel();
+            imagePath = new javax.swing.JTextField(TEXT_AREA_COLUMNS);
+            backgroundPane = new javax.swing.JPanel();
+
+            jScrollPane1 = new javax.swing.JScrollPane();
+            textArea = new javax.swing.JTextArea();
+
+            textArea.setColumns(TEXT_AREA_COLUMNS);
+            textArea.setRows(TEXT_AREA_ROWS);
+            textArea.setLineWrap(true);
+            textArea.setWrapStyleWord(true);
+
+            cancelButton = new javax.swing.JButton(XcosMessages.CANCEL);
+            okButton = new javax.swing.JButton(XcosMessages.OK);
+            buttonPane = new javax.swing.JPanel();
+
+            backgroundPane.setLayout(new java.awt.BorderLayout());
+            textFormat.setLayout(new java.awt.BorderLayout());
+
+            fontSizeLabel.setText(XcosMessages.FONT_SIZE);
+
+            fontSizeSpinner.setModel(FONTSIZE_MODEL);
+            fontSizeSpinner.addChangeListener(defaultChangeListener);
+
+            fontNameLabel.setText(XcosMessages.FONT_NAME);
+
+            fontNameComboBox.setModel(new javax.swing.DefaultComboBoxModel(
+                    GraphicsEnvironment.getLocalGraphicsEnvironment()
+                            .getAvailableFontFamilyNames()));
+
+            fontNameComboBox.addActionListener(defaultActionListener);
+
+            fontStyleLabel.setText(XcosMessages.FONT_STYLE);
+
+            fontStyleBold.setText(XcosMessages.BOLD);
+            fontStyleBold.addChangeListener(defaultChangeListener);
+
+            fontStyleItalic.setText(XcosMessages.ITALIC);
+            fontStyleItalic.addChangeListener(defaultChangeListener);
+
+            imagePathLabel.setText(XcosMessages.IMAGE_PATH);
+
+            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
+                    jPanel2);
+            jPanel2.setLayout(jPanel2Layout);
+            jPanel2Layout
+                    .setHorizontalGroup(jPanel2Layout
+                            .createParallelGroup(
+                                    javax.swing.GroupLayout.Alignment.LEADING)
+                            .addGroup(
+                                    javax.swing.GroupLayout.Alignment.TRAILING,
+                                    jPanel2Layout
+                                            .createSequentialGroup()
+                                            .addContainerGap()
+                                            .addGroup(
+                                                    jPanel2Layout
+                                                            .createParallelGroup(
+                                                                    javax.swing.GroupLayout.Alignment.LEADING,
+                                                                    false)
+                                                            .addComponent(
+                                                                    fontNameLabel,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    Short.MAX_VALUE)
+                                                            .addComponent(
+                                                                    fontSizeLabel,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    Short.MAX_VALUE)
+                                                            .addComponent(
+                                                                    fontStyleLabel,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    Short.MAX_VALUE))
+                                            .addGap(BORDER_SIZE)
+                                            .addGroup(
+                                                    jPanel2Layout
+                                                            .createParallelGroup(
+                                                                    javax.swing.GroupLayout.Alignment.TRAILING)
+                                                            .addComponent(
+                                                                    fontNameComboBox,
+                                                                    0,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    Short.MAX_VALUE)
+                                                            .addComponent(
+                                                                    fontSizeSpinner,
+                                                                    0,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    Short.MAX_VALUE)
+                                                            .addGroup(
+                                                                    jPanel2Layout
+                                                                            .createSequentialGroup()
+                                                                            .addComponent(
+                                                                                    fontStyleBold)
+                                                                            .addPreferredGap(
+                                                                                    javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                                                                            .addComponent(
+                                                                                    fontStyleItalic)))
+                                            .addContainerGap()));
+            jPanel2Layout
+                    .setVerticalGroup(jPanel2Layout
+                            .createParallelGroup(
+                                    javax.swing.GroupLayout.Alignment.LEADING)
+                            .addGroup(
+                                    jPanel2Layout
+                                            .createSequentialGroup()
+                                            .addGroup(
+                                                    jPanel2Layout
+                                                            .createParallelGroup(
+                                                                    javax.swing.GroupLayout.Alignment.BASELINE)
+                                                            .addComponent(
+                                                                    fontSizeLabel,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
+                                                            .addComponent(
+                                                                    fontSizeSpinner,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE))
+                                            .addGap(BORDER_SIZE)
+                                            .addGroup(
+                                                    jPanel2Layout
+                                                            .createParallelGroup(
+                                                                    javax.swing.GroupLayout.Alignment.BASELINE)
+                                                            .addComponent(
+                                                                    fontNameLabel,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
+                                                            .addComponent(
+                                                                    fontNameComboBox,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE))
+                                            .addGap(BORDER_SIZE)
+                                            .addGroup(
+                                                    jPanel2Layout
+                                                            .createParallelGroup(
+                                                                    javax.swing.GroupLayout.Alignment.BASELINE)
+                                                            .addComponent(
+                                                                    fontStyleLabel,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
+                                                            .addComponent(
+                                                                    fontStyleBold,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
+                                                            .addComponent(
+                                                                    fontStyleItalic,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
+                                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                                    javax.swing.GroupLayout.PREFERRED_SIZE))
+                                            .addContainerGap(
+                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
+                                                    Short.MAX_VALUE)));
+
+            textFormat.add(jPanel2, java.awt.BorderLayout.PAGE_END);
+
+            jScrollPane1.setViewportView(textArea);
+            jScrollPane1.setBackground(Color.WHITE);
+
+            textFormat.add(jScrollPane1, java.awt.BorderLayout.CENTER);
+
+            backgroundPane.add(backgroundColorChooser,
+                    java.awt.BorderLayout.CENTER);
+            javax.swing.JPanel filePane = new javax.swing.JPanel();
+            filePane.setBorder(BorderFactory.createEtchedBorder());
+            filePane.add(imagePathLabel);
+            filePane.add(imagePath);
+            filePane.add(imageFileChooserBtn);
+            backgroundPane.add(filePane, java.awt.BorderLayout.SOUTH);
+
+            mainTab.addTab(XcosMessages.TEXT_SETTINGS, textFormat);
+            mainTab.addTab(XcosMessages.BORDER_COLOR, borderColorChooser);
+            mainTab.addTab(XcosMessages.TEXT_COLOR, textColorChooser);
+            // backgroundColorChooser is added on the setCell method only if the
+            // cell is a vertex
+            // mainTab.addTab(XcosMessages.FILL_COLOR, backgroundColorChooser);
+
+            mainTab.addChangeListener(defaultChangeListener);
+
+            cancelButton.addActionListener(new ActionListener() {
+                /**
+                 * On cancel close the window
+                 * 
+                 * @param e
+                 *            the current event parameter
+                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+                 */
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    getDialog().dispose();
+                }
+            });
+
+            okButton.addActionListener(new ActionListener() {
+                /**
+                 * On OK, set the current parameter on the cell
+                 * 
+                 * @param e
+                 *            the current parameters
+                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+                 */
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    graph.getModel().beginUpdate();
+                    EditFormatAction.updateFromDialog(getDialog(),
+                            borderColorChooser.getColor(),
+                            backgroundColorChooser.getColor(),
+                            (String) fontNameComboBox.getSelectedItem(),
+                            (Integer) fontSizeSpinner.getValue(),
+                            textColorChooser.getColor(),
+                            fontStyleBold.isSelected(),
+                            fontStyleItalic.isSelected(), textArea.getText(),
+                            imagePath.getText());
+                    graph.getModel().endUpdate();
+                    getDialog().dispose();
+                }
+            });
+
+            imageFileChooserBtn.addActionListener(new ActionListener() {
+                /**
+                 * On file chooser open the file chooser with image filter.
+                 * 
+                 * @param e
+                 *            the event
+                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+                 */
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
+                    javax.swing.filechooser.FileNameExtensionFilter filter = new javax.swing.filechooser.FileNameExtensionFilter(
+                            "Images", "jpg", "png", "svg", "gif");
+                    chooser.setFileFilter(filter);
+
+                    final String current = imagePath.getText();
+                    final File savedFile = getGraph().getSavedFile();
+                    if (current != null && !current.isEmpty()) {
+                        try {
+                            // try to handle an absolute URL
+                            final URI uri = new URI(current);
+                            chooser.setSelectedFile(new File(uri));
+                        } catch (URISyntaxException e1) {
+                            // this is a relative path
+                            if (savedFile != null) {
+                                final File parent = savedFile.getParentFile();
+                                chooser.setSelectedFile(new File(parent,
+                                        current));
+                            }
+                        }
+                    } else {
+                        if (savedFile != null) {
+                            chooser.setCurrentDirectory(savedFile
+                                    .getParentFile());
+                        }
+                    }
+
+                    int returnVal = chooser.showOpenDialog(mainTab);
+                    if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
+                        if (savedFile != null) {
+                            final String relativeChild = savedFile
+                                    .getParentFile()
+                                    .toURI()
+                                    .relativize(
+                                            chooser.getSelectedFile().toURI())
+                                    .toASCIIString();
+                            imagePath.setText(relativeChild);
+                        } else {
+                            final String uri = chooser.getSelectedFile()
+                                    .toURI().toASCIIString();
+                            imagePath.setText(uri);
+                        }
+                    }
+                }
+            });
+
+            getRootPane().setDefaultButton(okButton);
+
+            buttonPane.setLayout(new javax.swing.BoxLayout(buttonPane,
+                    javax.swing.BoxLayout.LINE_AXIS));
+            buttonPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(
+                    BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
+            buttonPane.add(javax.swing.Box.createHorizontalGlue());
+            buttonPane.add(cancelButton);
+            buttonPane.add(javax.swing.Box.createRigidArea(new Dimension(
+                    BORDER_SIZE, 0)));
+            buttonPane.add(okButton);
+
+            java.awt.Container contentPane = getContentPane();
+            contentPane.add(mainTab, java.awt.BorderLayout.CENTER);
+            contentPane.add(buttonPane, java.awt.BorderLayout.PAGE_END);
+        }
+
+        // CSON: JavaNCSS
+        // CSON: LineLength
+        // CSON: MethodLength
+
+        /**
+         * Update the text area from the font
+         */
+        protected void updateFont() {
+            int style = 0;
+            if (fontStyleBold.isSelected()) {
+                style |= Font.BOLD;
+            }
+            if (fontStyleItalic.isSelected()) {
+                style |= Font.ITALIC;
+            }
+
+            Font f = new Font((String) fontNameComboBox.getSelectedItem(),
+                    style, (Integer) fontSizeSpinner.getValue());
+            textArea.setFont(f);
+            textArea.setBackground(backgroundColorChooser.getColor());
+            textArea.setForeground(textColorChooser.getColor());
+
+            // Repaint the parent scroll pane to force a full redraw call.
+            jScrollPane1.repaint();
+        }
+    }
+    // CSON: ClassDataAbstractionCoupling
+    // CSON: ClassFanOutComplexity
 }
index 0a210d0..a0151ae 100644 (file)
@@ -57,215 +57,246 @@ import com.mxgraph.util.mxUtils;
  * Diagram export management
  */
 public final class ExportAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.EXPORT;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = KeyEvent.VK_E;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
-       
-       private static final String HTML = "html";
-       private static final String VML = "vml";
-       private static final String SVG = "svg";
-       
-       /**
-        * Constructor
-        * @param scilabGraph associated Scilab Graph
-        */
-       public ExportAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
-
-       /**
-        * Create export menu
-        * @param scilabGraph associated Scilab Graph
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, ExportAction.class);
-       }
-
-       /**
-        * Action !!!
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-
-           XcosDiagram graph = (XcosDiagram) getGraph(null);
-
-               // Adds a filter for each supported image format
-               Collection<String> imageFormats = Arrays.asList(ImageIO.getWriterFileSuffixes());
-
-               // The mask ordered collection
-               Set<String> mask = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
-               
-               mask.add(SVG);
-               mask.add(HTML);
-               mask.add(VML);
-               mask.addAll(imageFormats);
-               
-               JFileChooser fc = new JFileChooser();
-               fc.setDialogTitle(XcosMessages.EXPORT);
-               fc.setApproveButtonText(XcosMessages.EXPORT);
-               fc.setAcceptAllFileFilterUsed(true);
-               
-               for (String string : mask) {
-                       fc.addChoosableFileFilter(new FileMask(string, string.toUpperCase()));
-               }
-
-               ConfigurationManager.configureCurrentDirectory(fc);
-               
-               JPanel panelPreview = new JPanel();
-               
-        //Title for preview panel
+    /** Name of the action */
+    public static final String NAME = XcosMessages.EXPORT;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = KeyEvent.VK_E;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit()
+            .getMenuShortcutKeyMask();
+
+    private static final String HTML = "html";
+    private static final String VML = "vml";
+    private static final String SVG = "svg";
+
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     */
+    public ExportAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
+
+    /**
+     * Create export menu
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, ExportAction.class);
+    }
+
+    /**
+     * Action !!!
+     * 
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+
+        XcosDiagram graph = (XcosDiagram) getGraph(null);
+
+        // Adds a filter for each supported image format
+        Collection<String> imageFormats = Arrays.asList(ImageIO
+                .getWriterFileSuffixes());
+
+        // The mask ordered collection
+        Set<String> mask = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+
+        mask.add(SVG);
+        mask.add(HTML);
+        mask.add(VML);
+        mask.addAll(imageFormats);
+
+        JFileChooser fc = new JFileChooser();
+        fc.setDialogTitle(XcosMessages.EXPORT);
+        fc.setApproveButtonText(XcosMessages.EXPORT);
+        fc.setAcceptAllFileFilterUsed(true);
+
+        for (String string : mask) {
+            fc.addChoosableFileFilter(new FileMask(string, string.toUpperCase()));
+        }
+
+        ConfigurationManager.configureCurrentDirectory(fc);
+
+        JPanel panelPreview = new JPanel();
+
+        // Title for preview panel
         TitledBorder titlePreview;
-        titlePreview = BorderFactory.createTitledBorder(Messages.gettext("Preview"));
+        titlePreview = BorderFactory.createTitledBorder(Messages
+                .gettext("Preview"));
         panelPreview.setBorder(titlePreview);
-        
-        //add preview image
-               panelPreview.add(new ImagePreview(fc));         
-               
-               //Main panel contains extensionTable panel & preview panel
-               JPanel accessoryPanel = new JPanel();
-               
-               //accessoryPanel.add(scrollPane);               
-               accessoryPanel.add(panelPreview);
-               accessoryPanel.setVisible(true);        
-               fc.setAccessory(accessoryPanel);
-               
-               int selection = fc.showSaveDialog(graph.getAsComponent());
-               if (selection == JFileChooser.APPROVE_OPTION) {
-                       File selected = fc.getSelectedFile();
-                       
-                       /* getting the format */
-                       String format = getFormat(graph, fc, selected);
-                       while (format == null) {
-                               selection = fc.showSaveDialog(graph.getAsComponent());
-                               if (selection == JFileChooser.APPROVE_OPTION) {
-                                       selected = fc.getSelectedFile();
-                                       format = getFormat(graph, fc, selected);
-                               } else {
-                                       return;
-                               }
-                       }
-                       
-                       try  {
-                               /* Add an extension if no one is set */
-                               if (FileMask.getExtension(selected) == null
-                                               || FileMask.getExtension(selected).isEmpty()) {
-                                       selected = new File(selected.getCanonicalPath() + '.' + format);
-                               }
-                       
-                               /* Export the file */
-                               if (selected.exists()) {
-                                       final boolean overwrite = ScilabModalDialog.show(
-                                                       graph.getParentTab(),
-                                                       XcosMessages.OVERWRITE_EXISTING_FILE,
-                                                       XcosMessages.XCOS, IconType.QUESTION_ICON,
-                                                       ButtonType.YES_NO) == AnswerOption.YES_OPTION;
-                                       
-                                       if (overwrite) {
-                                               export(graph, selected, format);
-                                       } else {
-                                               return;
-                                       }
-                               } else {
-                                       export(graph, selected, format);
-                               }
-                       } catch (IOException ex) {
-                               LogFactory.getLog(ExportAction.class).error(ex);
-                       }
-               }
-       }
-
-       /**
-        * Get the file format
-        * 
-        * @param graph the current graph
-        * @param fc the file chooser
-        * @param selected the selected file
-        * @return the format or null
-        */
-       private String getFormat(XcosDiagram graph, JFileChooser fc,
-                       final File selected) {
-               final String format;
-               if (fc.getFileFilter() == fc.getAcceptAllFileFilter()) { // reference equality works here
-                       if (FileMask.getExtension(selected) == null
-                                       || FileMask.getExtension(selected).isEmpty()) {
-                               JOptionPane.showMessageDialog(graph.getAsComponent(),
-                                               Messages.gettext("Please specify a file format"),
-                                               Messages.gettext("Error on export"),
-                                               JOptionPane.ERROR_MESSAGE);
-                               return null;
-                       } else {
-                               format = FileMask.getExtension(selected);
-                       }
-               } else {
-                       format = ((FileMask) fc.getFileFilter()).getExtensionFromFilter();
-               }
-               return format;
-       }
-
-       /**
-        * Export the graph into the filename.
-        * 
-        * The filename extension is used find export format.
-        * 
-        * @param graph the current graph
-        * @param filename the filename
-        * @param fileFormat the format to save
-        * @throws IOException when a write problem occurs. 
-        */
-       private void export(XcosDiagram graph, File filename, String fileFormat) throws IOException {
-               if (fileFormat.equalsIgnoreCase(SVG)) {
-                   ScilabGraphRenderer.createSvgDocument(graph, null, 1, null, null, filename.getCanonicalPath());
-               } else if (fileFormat.equalsIgnoreCase(VML)) {
-                   Document doc = mxCellRenderer.createVmlDocument(graph, null, 1, null, null);
-                   if (doc != null) {
-                       mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename.getCanonicalPath());
-                   }
-               } else if (fileFormat.equalsIgnoreCase(HTML)) {
-                   Document doc = mxCellRenderer.createHtmlDocument(graph, null, 1, null, null);
-                   if (doc != null) {
-                       mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename.getCanonicalPath());
-                   }
-               } else  {
-                       exportBufferedImage(graph, filename, fileFormat);
-               }
-       }
-
-       /**
-        * Use the Java image capabilities to export the diagram
-        * 
-        * @param graph the current diagram
-        * @param filename the current filename
-        * @param fileFormat the file format
-        * @throws IOException when an error occurs
-        */
-       private void exportBufferedImage(XcosDiagram graph, File filename, String fileFormat)
-                       throws IOException {
-               final mxGraphComponent graphComponent = graph.getAsComponent();
-               
-               Color bg = null;
-
-               if ((!fileFormat.equalsIgnoreCase("png"))
-                       || ScilabModalDialog.show(graph.getParentTab(), XcosMessages.TRANSPARENT_BACKGROUND, XcosMessages.XCOS, 
-                               IconType.QUESTION_ICON, ButtonType.YES_NO) != AnswerOption.YES_OPTION) {
-                       bg = graphComponent.getBackground();
-               }
-
-               BufferedImage image = mxCellRenderer.createBufferedImage(
-                               graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas());
-
-               if (image != null) {
-                       ImageIO.write(image, fileFormat, filename);
-               } else  {
-                       JOptionPane.showMessageDialog(graphComponent, XcosMessages.NO_IMAGE_DATA);
-               }
-       }
-}
 
+        // add preview image
+        panelPreview.add(new ImagePreview(fc));
+
+        // Main panel contains extensionTable panel & preview panel
+        JPanel accessoryPanel = new JPanel();
+
+        // accessoryPanel.add(scrollPane);
+        accessoryPanel.add(panelPreview);
+        accessoryPanel.setVisible(true);
+        fc.setAccessory(accessoryPanel);
+
+        int selection = fc.showSaveDialog(graph.getAsComponent());
+        if (selection == JFileChooser.APPROVE_OPTION) {
+            File selected = fc.getSelectedFile();
+
+            /* getting the format */
+            String format = getFormat(graph, fc, selected);
+            while (format == null) {
+                selection = fc.showSaveDialog(graph.getAsComponent());
+                if (selection == JFileChooser.APPROVE_OPTION) {
+                    selected = fc.getSelectedFile();
+                    format = getFormat(graph, fc, selected);
+                } else {
+                    return;
+                }
+            }
+
+            try {
+                /* Add an extension if no one is set */
+                if (FileMask.getExtension(selected) == null
+                        || FileMask.getExtension(selected).isEmpty()) {
+                    selected = new File(selected.getCanonicalPath() + '.'
+                            + format);
+                }
+
+                /* Export the file */
+                if (selected.exists()) {
+                    final boolean overwrite = ScilabModalDialog.show(
+                            graph.getParentTab(),
+                            XcosMessages.OVERWRITE_EXISTING_FILE,
+                            XcosMessages.XCOS, IconType.QUESTION_ICON,
+                            ButtonType.YES_NO) == AnswerOption.YES_OPTION;
+
+                    if (overwrite) {
+                        export(graph, selected, format);
+                    } else {
+                        return;
+                    }
+                } else {
+                    export(graph, selected, format);
+                }
+            } catch (IOException ex) {
+                LogFactory.getLog(ExportAction.class).error(ex);
+            }
+        }
+    }
+
+    /**
+     * Get the file format
+     * 
+     * @param graph
+     *            the current graph
+     * @param fc
+     *            the file chooser
+     * @param selected
+     *            the selected file
+     * @return the format or null
+     */
+    private String getFormat(XcosDiagram graph, JFileChooser fc,
+            final File selected) {
+        final String format;
+        if (fc.getFileFilter() == fc.getAcceptAllFileFilter()) { // reference
+                                                                 // equality
+                                                                 // works here
+            if (FileMask.getExtension(selected) == null
+                    || FileMask.getExtension(selected).isEmpty()) {
+                JOptionPane.showMessageDialog(graph.getAsComponent(),
+                        Messages.gettext("Please specify a file format"),
+                        Messages.gettext("Error on export"),
+                        JOptionPane.ERROR_MESSAGE);
+                return null;
+            } else {
+                format = FileMask.getExtension(selected);
+            }
+        } else {
+            format = ((FileMask) fc.getFileFilter()).getExtensionFromFilter();
+        }
+        return format;
+    }
+
+    /**
+     * Export the graph into the filename.
+     * 
+     * The filename extension is used find export format.
+     * 
+     * @param graph
+     *            the current graph
+     * @param filename
+     *            the filename
+     * @param fileFormat
+     *            the format to save
+     * @throws IOException
+     *             when a write problem occurs.
+     */
+    private void export(XcosDiagram graph, File filename, String fileFormat)
+            throws IOException {
+        if (fileFormat.equalsIgnoreCase(SVG)) {
+            ScilabGraphRenderer.createSvgDocument(graph, null, 1, null, null,
+                    filename.getCanonicalPath());
+        } else if (fileFormat.equalsIgnoreCase(VML)) {
+            Document doc = mxCellRenderer.createVmlDocument(graph, null, 1,
+                    null, null);
+            if (doc != null) {
+                mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()),
+                        filename.getCanonicalPath());
+            }
+        } else if (fileFormat.equalsIgnoreCase(HTML)) {
+            Document doc = mxCellRenderer.createHtmlDocument(graph, null, 1,
+                    null, null);
+            if (doc != null) {
+                mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()),
+                        filename.getCanonicalPath());
+            }
+        } else {
+            exportBufferedImage(graph, filename, fileFormat);
+        }
+    }
+
+    /**
+     * Use the Java image capabilities to export the diagram
+     * 
+     * @param graph
+     *            the current diagram
+     * @param filename
+     *            the current filename
+     * @param fileFormat
+     *            the file format
+     * @throws IOException
+     *             when an error occurs
+     */
+    private void exportBufferedImage(XcosDiagram graph, File filename,
+            String fileFormat) throws IOException {
+        final mxGraphComponent graphComponent = graph.getAsComponent();
+
+        Color bg = null;
+
+        if ((!fileFormat.equalsIgnoreCase("png"))
+                || ScilabModalDialog.show(graph.getParentTab(),
+                        XcosMessages.TRANSPARENT_BACKGROUND, XcosMessages.XCOS,
+                        IconType.QUESTION_ICON, ButtonType.YES_NO) != AnswerOption.YES_OPTION) {
+            bg = graphComponent.getBackground();
+        }
+
+        BufferedImage image = mxCellRenderer.createBufferedImage(graph, null,
+                1, bg, graphComponent.isAntiAlias(), null,
+                graphComponent.getCanvas());
+
+        if (image != null) {
+            ImageIO.write(image, fileFormat, filename);
+        } else {
+            JOptionPane.showMessageDialog(graphComponent,
+                    XcosMessages.NO_IMAGE_DATA);
+        }
+    }
+}
index a8487cb..14e656c 100644 (file)
@@ -26,62 +26,69 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * Use maximum of space inside the diagram
  */
 public final class FitDiagramToViewAction extends OneBlockDependantAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.FIT_DIAGRAM_TO_VIEW;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "zoom-fit-drawing";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = 0;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = 0;
+    /** Name of the action */
+    public static final String NAME = XcosMessages.FIT_DIAGRAM_TO_VIEW;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "zoom-fit-drawing";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = 0;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = 0;
 
-       /**
-        * Constructor
-        * @param scilabGraph associated diagram
-        */
-       public FitDiagramToViewAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     */
+    public FitDiagramToViewAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
 
-       /**
-        * Menu to add to the menubar
-        * @param scilabGraph associated diagram
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, FitDiagramToViewAction.class);
-       }
-       
-       /**
-        * Button to add to the toolbar
-        * @param scilabGraph associated diagram
-        * @return the button
-        */
-       public static PushButton createButton(ScilabGraph scilabGraph) {
-               return createButton(scilabGraph, FitDiagramToViewAction.class);
-       }
+    /**
+     * Menu to add to the menubar
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, FitDiagramToViewAction.class);
+    }
 
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               // If diagram is empty (has one default child) : do nothing.
-               if (getGraph(null).getModel().getChildCount(
-                               getGraph(null).getDefaultParent()) < 1) {
-                       return;
-               }
+    /**
+     * Button to add to the toolbar
+     * 
+     * @param scilabGraph
+     *            associated diagram
+     * @return the button
+     */
+    public static PushButton createButton(ScilabGraph scilabGraph) {
+        return createButton(scilabGraph, FitDiagramToViewAction.class);
+    }
 
-               ScilabComponent comp = ((ScilabComponent) getGraph(null)
-                               .getAsComponent());
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        // If diagram is empty (has one default child) : do nothing.
+        if (getGraph(null).getModel().getChildCount(
+                getGraph(null).getDefaultParent()) < 1) {
+            return;
+        }
 
-               /* Save the configuration */
-               double oldZoomFactor = comp.getZoomFactor();
+        ScilabComponent comp = ((ScilabComponent) getGraph(null)
+                .getAsComponent());
 
-               comp.zoomAndCenterToCells();
+        /* Save the configuration */
+        double oldZoomFactor = comp.getZoomFactor();
 
-               /* Restore previous configuration */
-               comp.setZoomFactor(oldZoomFactor);
-       }
+        comp.zoomAndCenterToCells();
+
+        /* Restore previous configuration */
+        comp.setZoomFactor(oldZoomFactor);
+    }
 }
index f13583a..513534c 100644 (file)
@@ -32,72 +32,83 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * Launch the modelica compiler configuration TCL UI
  */
 public class InitModelicaAction extends DefaultAction {
-       /** the name */
+    /** the name */
     public static final String NAME = XcosMessages.INIT_MODELICA;
-       /** no icon */
+    /** no icon */
     public static final String SMALL_ICON = "";
-       /** no mnemonic */
+    /** no mnemonic */
     public static final int MNEMONIC_KEY = 0;
-       /** no accelerator */
+    /** no accelerator */
     public static final int ACCELERATOR_KEY = 0;
-    
+
     /**
      * Constructor
-     * @param scilabGraph corresponding Scilab Graph
+     * 
+     * @param scilabGraph
+     *            corresponding Scilab Graph
      */
     public InitModelicaAction(ScilabGraph scilabGraph) {
-       super(scilabGraph);
+        super(scilabGraph);
     }
+
     /**
      * Create a button for a graph toolbar
-     * @param scilabGraph corresponding Scilab Graph
+     * 
+     * @param scilabGraph
+     *            corresponding Scilab Graph
      * @return the button
      */
     public static PushButton createButton(ScilabGraph scilabGraph) {
-       return createButton(scilabGraph, InitModelicaAction.class);
+        return createButton(scilabGraph, InitModelicaAction.class);
     }
 
     /**
      * Create a menu for a graph menubar
-     * @param scilabGraph corresponding Scilab Graph
+     * 
+     * @param scilabGraph
+     *            corresponding Scilab Graph
      * @return the menu
      */
     public static MenuItem createMenu(ScilabGraph scilabGraph) {
-       return createMenu(scilabGraph, InitModelicaAction.class);
+        return createMenu(scilabGraph, InitModelicaAction.class);
     }
 
     /**
      * Action associated
-     * @param e the event
+     * 
+     * @param e
+     *            the event
      * @see org.scilab.modules.gui.events.callback.CallBack#actionPerformed(java.awt.event.ActionEvent)
      */
-       @Override
+    @Override
     public void actionPerformed(ActionEvent e) {
-       String temp;
+        String temp;
+
+        try {
+            ((XcosDiagram) getGraph(null))
+                    .info(XcosMessages.INITIALIZING_MODELICA_COMPILER);
+            temp = FileUtils.createTempFile();
+            ((XcosDiagram) getGraph(e)).getRootDiagram().dumpToHdf5File(temp);
+
+            String cmd = buildCall("import_from_hdf5", temp);
+            cmd += buildCall("xcosConfigureModelica");
+            cmd += buildCall("deletefile", temp);
 
-       try {
-           ((XcosDiagram) getGraph(null)).info(XcosMessages.INITIALIZING_MODELICA_COMPILER);
-           temp = FileUtils.createTempFile();
-           ((XcosDiagram) getGraph(e)).getRootDiagram().dumpToHdf5File(temp);
+            final ActionListener action = new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    ((XcosDiagram) getGraph(null))
+                            .info(XcosMessages.EMPTY_INFO);
+                }
+            };
 
-           String cmd = buildCall("import_from_hdf5", temp);
-           cmd += buildCall("xcosConfigureModelica");
-           cmd += buildCall("deletefile", temp);
-           
-           final ActionListener action = new ActionListener() {
-                       @Override
-                       public void actionPerformed(ActionEvent e) {
-                               ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
-                       }
-               };
-           
-           try {
-               asynchronousScilabExec(action, cmd);
-           } catch (InterpreterException e1) {
-               LogFactory.getLog(InitModelicaAction.class).error(e1);
-           }
-       } catch (IOException e1) {
-               LogFactory.getLog(InitModelicaAction.class).error(e1);
-       }  
+            try {
+                asynchronousScilabExec(action, cmd);
+            } catch (InterpreterException e1) {
+                LogFactory.getLog(InitModelicaAction.class).error(e1);
+            }
+        } catch (IOException e1) {
+            LogFactory.getLog(InitModelicaAction.class).error(e1);
+        }
     }
 }
index dc02878..aa9744c 100644 (file)
@@ -28,48 +28,56 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * New Diagram creation
  */
 public final class NewDiagramAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.NEW_DIAGRAM;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "document-new.png";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = KeyEvent.VK_N;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+    /** Name of the action */
+    public static final String NAME = XcosMessages.NEW_DIAGRAM;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "document-new.png";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = KeyEvent.VK_N;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit()
+            .getMenuShortcutKeyMask();
 
-       /**
-        * Constructor
-        * @param scilabGraph associated Scilab Graph
-        */
-       public NewDiagramAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     */
+    public NewDiagramAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
 
-       /**
-        * Create a menu item for the graph menubar
-        * @param scilabGraph associated Scilab Graph
-        * @return the menu item
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, NewDiagramAction.class);
-       }
+    /**
+     * Create a menu item for the graph menubar
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     * @return the menu item
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, NewDiagramAction.class);
+    }
 
-       /**
-        * Create a button for the graph toolbar
-        * @param scilabGraph associated Scilab Graph
-        * @return the button
-        */
-       public static PushButton createButton(ScilabGraph scilabGraph) {
-               return createButton(scilabGraph, NewDiagramAction.class);
-       }
-       
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               Xcos.getInstance().open(null);
-       }
+    /**
+     * Create a button for the graph toolbar
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     * @return the button
+     */
+    public static PushButton createButton(ScilabGraph scilabGraph) {
+        return createButton(scilabGraph, NewDiagramAction.class);
+    }
+
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        Xcos.getInstance().open(null);
+    }
 
 }
index 8716394..93f24ea 100644 (file)
@@ -24,39 +24,44 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * Back to normal size for diagram (100%)
  */
 public final class NormalViewAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.NORMAL_100;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "zoom-original";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = 0;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = 0;
-
-       /**
-        * Constructor
-        * @param scilabGraph associated Scilab Graph
-        */
-       public NormalViewAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
-
-       /**
-        * Create the menu for Scilab Graph menu bar
-        * @param scilabGraph associated Scilab Graph
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, NormalViewAction.class);
-       }
-       
-       /**
-        * @param e parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               ((XcosDiagram) getGraph(null)).getAsComponent().zoomActual();
-       }
+    /** Name of the action */
+    public static final String NAME = XcosMessages.NORMAL_100;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "zoom-original";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = 0;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = 0;
+
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     */
+    public NormalViewAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
+
+    /**
+     * Create the menu for Scilab Graph menu bar
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     * @return the menu
+     */
+    public static MenuItem createMenu(ScilabGraph scilabGraph) {
+        return createMenu(scilabGraph, NormalViewAction.class);
+    }
+
+    /**
+     * @param e
+     *            parameter
+     * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        ((XcosDiagram) getGraph(null)).getAsComponent().zoomActual();
+    }
 
 }
index b38d85a..9ef73c2 100644 (file)
@@ -41,93 +41,93 @@ import org.scilab.modules.xcos.utils.XcosMessages;
  * File opening management
  */
 public final class OpenAction extends DefaultAction {
-       /** Name of the action */
-       public static final String NAME = XcosMessages.OPEN;
-       /** Icon name of the action */
-       public static final String SMALL_ICON = "document-open.png";
-       /** Mnemonic key of the action */
-       public static final int MNEMONIC_KEY = KeyEvent.VK_O;
-       /** Accelerator key for the action */
-       public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit()
-                       .getMenuShortcutKeyMask();
-
-       /**
-        * Constructor
-        * 
-        * @param scilabGraph
-        *            associated Scilab Graph
-        */
-       public OpenAction(ScilabGraph scilabGraph) {
-               super(scilabGraph);
-       }
-
-       /**
-        * Create a menu to add in Scilab Graph menu bar
-        * 
-        * @param scilabGraph
-        *            associated Scilab Graph
-        * @return the menu
-        */
-       public static MenuItem createMenu(ScilabGraph scilabGraph) {
-               return createMenu(scilabGraph, OpenAction.class);
-       }
-
-       /**
-        * Create a button to add in Scilab Graph tool bar
-        * 
-        * @param scilabGraph
-        *            associated Scilab Graph
-        * @return the button
-        */
-       public static PushButton createButton(ScilabGraph scilabGraph) {
-               return createButton(scilabGraph, OpenAction.class);
-       }
-
-       /**
-        * @param e
-        *            parameter
-        * @see org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
-        */
-       @Override
-       public void actionPerformed(ActionEvent e) {
-               SwingScilabFileChooser fc = ((SwingScilabFileChooser) ScilabFileChooser
-                               .createFileChooser().getAsSimpleFileChooser());
-
-               fc.setTitle(XcosMessages.OPEN);
-               fc.setUiDialogType(JFileChooser.OPEN_DIALOG);
-               fc.setMultipleSelection(true);
-
-               /* Configure the file chooser */
-               configureFileFilters(fc);
-               ConfigurationManager.configureCurrentDirectory(fc);
-
-               int status = fc.showOpenDialog(getGraph(e).getAsComponent());
-               if (status != JFileChooser.APPROVE_OPTION) {
-                       return;
-               }
-
-               final File onlySelected = fc.getSelectedFile();
-               if (onlySelected != null) {
-                       Xcos.getInstance().open(onlySelected);
-               }
-
-               final File[] multiSelected = fc.getSelectedFiles();
-               for (File file : multiSelected) {
-                       Xcos.getInstance().open(file);
-               }
-       }
-
-       /*
-        * Helpers functions to configure file chooser
-        */
-
-       private static void configureFileFilters(JFileChooser fc) {
-               fc.setAcceptAllFileFilterUsed(true);
-
-               final FileFilter[] filters = XcosFileType.getValidFilters();
-               for (FileFilter fileFilter : filters) {
-                       fc.addChoosableFileFilter(fileFilter);
-               }
-               fc.setFileFilter(filters[0]);
-       }
+    /** Name of the action */
+    public static final String NAME = XcosMessages.OPEN;
+    /** Icon name of the action */
+    public static final String SMALL_ICON = "document-open.png";
+    /** Mnemonic key of the action */
+    public static final int MNEMONIC_KEY = KeyEvent.VK_O;
+    /** Accelerator key for the action */
+    public static final int ACCELERATOR_KEY = Toolkit.getDefaultToolkit()
+            .getMenuShortcutKeyMask();
+
+    /**
+     * Constructor
+     * 
+     * @param scilabGraph
+     *            associated Scilab Graph
+     */
+    public OpenAction(ScilabGraph scilabGraph) {
+        super(scilabGraph);
+    }
<