Fix misc. issues with Tab opening
[scilab.git] / scilab / modules / xcos / src / java / org / scilab / modules / xcos / XcosTab.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2010-2011 - DIGITEO - Clement DAVID
4  * Copyright (C) 2011-2017 - Scilab Enterprises - Clement DAVID
5  * Copyright (C) 2017-2018 - ESI Group - Clement DAVID
6  *
7  * Copyright (C) 2012 - 2016 - Scilab Enterprises
8  *
9  * This file is hereby licensed under the terms of the GNU GPL v2.0,
10  * pursuant to article 5.3.4 of the CeCILL v.2.1.
11  * This file was originally licensed under the terms of the CeCILL v2.1,
12  * and continues to be available under such terms.
13  * For more information, see the COPYING file which you should have received
14  * along with this program.
15  *
16  */
17
18 package org.scilab.modules.xcos;
19
20 import com.mxgraph.util.mxEvent;
21 import com.mxgraph.util.mxEventObject;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import java.lang.ref.WeakReference;
25 import java.net.MalformedURLException;
26 import java.net.URL;
27 import java.util.List;
28 import java.util.ListIterator;
29 import java.util.UUID;
30 import java.util.logging.Logger;
31
32 import javax.swing.JButton;
33 import javax.swing.JCheckBoxMenuItem;
34
35 import org.scilab.modules.graph.actions.CopyAction;
36 import org.scilab.modules.graph.actions.CutAction;
37 import org.scilab.modules.graph.actions.DeleteAction;
38 import org.scilab.modules.graph.actions.InvertSelectionAction;
39 import org.scilab.modules.graph.actions.PasteAction;
40 import org.scilab.modules.graph.actions.RedoAction;
41 import org.scilab.modules.graph.actions.SelectAllAction;
42 import org.scilab.modules.graph.actions.UndoAction;
43 import org.scilab.modules.graph.actions.ZoomInAction;
44 import org.scilab.modules.graph.actions.ZoomOutAction;
45 import org.scilab.modules.graph.event.ArrowKeyListener;
46 import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
47 import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
48 import org.scilab.modules.gui.bridge.tab.SwingScilabDockablePanel;
49 import org.scilab.modules.gui.bridge.toolbar.SwingScilabToolBar;
50 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
51 import org.scilab.modules.gui.checkboxmenuitem.CheckBoxMenuItem;
52 import org.scilab.modules.gui.menu.Menu;
53 import org.scilab.modules.gui.menu.ScilabMenu;
54 import org.scilab.modules.gui.menubar.MenuBar;
55 import org.scilab.modules.gui.menubar.ScilabMenuBar;
56 import org.scilab.modules.gui.menuitem.MenuItem;
57 import org.scilab.modules.gui.menuitem.ScilabMenuItem;
58 import org.scilab.modules.gui.tab.SimpleTab;
59 import org.scilab.modules.gui.tabfactory.ScilabTabFactory;
60 import org.scilab.modules.gui.textbox.ScilabTextBox;
61 import org.scilab.modules.gui.toolbar.ScilabToolBar;
62 import org.scilab.modules.gui.toolbar.ToolBar;
63 import org.scilab.modules.gui.utils.BarUpdater;
64 import org.scilab.modules.gui.utils.ClosingOperationsManager;
65 import org.scilab.modules.gui.utils.WindowsConfigurationManager;
66 import org.scilab.modules.xcos.actions.AboutXcosAction;
67 import org.scilab.modules.xcos.actions.CloseAction;
68 import org.scilab.modules.xcos.actions.CompileAction;
69 import org.scilab.modules.xcos.actions.DebugLevelAction;
70 import org.scilab.modules.xcos.actions.DiagramBackgroundAction;
71 import org.scilab.modules.xcos.actions.EditFormatAction;
72 import org.scilab.modules.xcos.actions.ExportAction;
73 import org.scilab.modules.xcos.actions.ExportAllAction;
74 import org.scilab.modules.xcos.actions.ExternalAction;
75 import org.scilab.modules.xcos.actions.FitDiagramToViewAction;
76 import org.scilab.modules.xcos.actions.InitModelicaAction;
77 import org.scilab.modules.xcos.actions.NewDiagramAction;
78 import org.scilab.modules.xcos.actions.NormalViewAction;
79 import org.scilab.modules.xcos.actions.OpenAction;
80 import org.scilab.modules.xcos.actions.OpenInSciAction;
81 import org.scilab.modules.xcos.actions.PrintAction;
82 import org.scilab.modules.xcos.actions.QuitAction;
83 import org.scilab.modules.xcos.actions.RecentFileAction;
84 import org.scilab.modules.xcos.actions.SaveAction;
85 import org.scilab.modules.xcos.actions.SaveAsAction;
86 import org.scilab.modules.xcos.actions.SetContextAction;
87 import org.scilab.modules.xcos.actions.SetupAction;
88 import org.scilab.modules.xcos.actions.ShowHideShadowAction;
89 import org.scilab.modules.xcos.actions.StartAction;
90 import org.scilab.modules.xcos.actions.StopAction;
91 import org.scilab.modules.xcos.actions.ViewDiagramBrowserAction;
92 import org.scilab.modules.xcos.actions.ViewDiagramTreeShowAction;
93 import org.scilab.modules.xcos.actions.ViewGridAction;
94 import org.scilab.modules.xcos.actions.ViewViewportAction;
95 import org.scilab.modules.xcos.actions.XcosDemonstrationsAction;
96 import org.scilab.modules.xcos.actions.XcosDocumentationAction;
97 import org.scilab.modules.xcos.block.actions.AutoPositionSplitBlockAction;
98 import org.scilab.modules.xcos.block.actions.BlockDocumentationAction;
99 import org.scilab.modules.xcos.block.actions.BlockParametersAction;
100 import org.scilab.modules.xcos.block.actions.BorderColorAction;
101 import org.scilab.modules.xcos.block.actions.CodeGenerationAction;
102 import org.scilab.modules.xcos.block.actions.FilledColorAction;
103 import org.scilab.modules.xcos.block.actions.FlipAction;
104 import org.scilab.modules.xcos.block.actions.MirrorAction;
105 import org.scilab.modules.xcos.block.actions.RegionToSuperblockAction;
106 import org.scilab.modules.xcos.block.actions.RotateAction;
107 import org.scilab.modules.xcos.block.actions.ViewDetailsAction;
108 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionBottom;
109 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionCenter;
110 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionLeft;
111 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionMiddle;
112 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionRight;
113 import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionTop;
114 import org.scilab.modules.xcos.configuration.ConfigurationManager;
115 import org.scilab.modules.xcos.configuration.model.DocumentType;
116 import org.scilab.modules.xcos.configuration.utils.ConfigurationConstants;
117 import org.scilab.modules.xcos.graph.XcosDiagram;
118 import org.scilab.modules.xcos.link.actions.StyleHorizontalAction;
119 import org.scilab.modules.xcos.link.actions.StyleOptimalAction;
120 import org.scilab.modules.xcos.link.actions.StyleStraightAction;
121 import org.scilab.modules.xcos.link.actions.StyleVerticalAction;
122 import org.scilab.modules.xcos.palette.actions.ViewPaletteBrowserAction;
123 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
124 import org.scilab.modules.xcos.preferences.XcosOptions;
125 import org.scilab.modules.xcos.utils.XcosMessages;
126
127 /**
128  * Xcos tab operations
129  *
130  * This class implement specific operation of an Xcos Tab.
131  */
132 // CSOFF: ClassFanOutComplexity
133 // CSOFF: ClassDataAbstractionCoupling
134 @SuppressWarnings(value = { "serial" })
135 public class XcosTab extends SwingScilabDockablePanel implements SimpleTab {
136     public static final String DEFAULT_WIN_UUID = "xcos-default-window";
137     public static final String DEFAULT_TAB_UUID = "xcos-default-tab";
138
139     /*
140      * Instance fields
141      */
142     private MenuBar menuBar;
143     private Menu fileMenu;
144     private Menu recentsMenu;
145     private Menu edit;
146     private Menu view;
147     private Menu simulate;
148     private Menu format;
149     private Menu alignMenu;
150     private Menu blockPosition;
151     private Menu linkStyle;
152     private Menu tools;
153     private Menu help;
154
155     private JCheckBoxMenuItem viewport;
156
157     private JButton openAction;
158     private JButton saveAction;
159     private JButton saveAsAction;
160     private JButton printAction;
161     private JButton newDiagramAction;
162     private JButton deleteAction;
163     private JButton undoAction;
164     private JButton redoAction;
165     private JButton fitDiagramToViewAction;
166     private JButton startAction;
167     private JButton stopAction;
168     private JButton zoomInAction;
169     private JButton zoomOutAction;
170     private JButton xcosDemonstrationAction;
171     private JButton xcosDocumentationAction;
172
173     private static class ClosingOperation implements org.scilab.modules.gui.utils.ClosingOperationsManager.ClosingOperation {
174         private final WeakReference<XcosDiagram> graph;
175
176         public ClosingOperation(XcosDiagram graph) {
177             this.graph = new WeakReference<XcosDiagram>(graph);
178         }
179
180         @Override
181         public int canClose() {
182             final XcosDiagram diag = graph.get();
183             if (diag == null) {
184                 return 1;
185             }
186
187             return Xcos.getInstance().canClose(diag) ? 1 : 0;
188         }
189
190         @Override
191         public void destroy() {
192             final XcosDiagram diag = graph.get();
193             if (diag == null) {
194                 return;
195             }
196
197             Xcos.getInstance().destroy(diag);
198         }
199
200         @Override
201         public String askForClosing(final List<SwingScilabDockablePanel> list) {
202             final XcosDiagram diag = graph.get();
203             if (diag == null) {
204                 return null;
205             }
206
207             return Xcos.getInstance().askForClosing(diag, list);
208         }
209
210         @Override
211         public void updateDependencies(List<SwingScilabDockablePanel> list, ListIterator<SwingScilabDockablePanel> it) {
212             final PaletteManagerView palette = PaletteManagerView.get();
213
214             /*
215              * if palette is not visible, then break
216              */
217             if (palette == null) {
218                 return;
219             }
220
221             /*
222              * If it already contains the palette, then break.
223              */
224             if (list.contains(palette)) {
225                 return;
226             }
227
228             final boolean wasLastOpened = Xcos.getInstance().wasLastOpened(list);
229
230             /*
231              * Append the palette if all the xcos files will be closed
232              */
233             if (wasLastOpened) {
234                 it.add(palette);
235             }
236
237         }
238     }
239
240     private static class EndedRestoration implements WindowsConfigurationManager.EndedRestoration {
241         private final WeakReference<XcosDiagram> graph;
242
243         public EndedRestoration(XcosDiagram graph) {
244             this.graph = new WeakReference<XcosDiagram>(graph);
245         }
246
247         @Override
248         public void finish() {
249             final XcosDiagram diag = graph.get();
250             if (diag == null) {
251                 return;
252             }
253
254             diag.updateTabTitle();
255
256             ConfigurationManager.getInstance().removeFromRecentTabs(diag.getGraphTab());
257         }
258     }
259
260     /**
261      * Default constructor
262      *
263      * @param diagram
264      *            The associated diagram
265      */
266     private XcosTab(XcosDiagram graph, String uuid) {
267         super(XcosMessages.XCOS, uuid);
268
269         setAssociatedXMLIDForHelp("xcos");
270
271         /** tab association */
272         graph.setGraphTab(uuid);
273         setWindowIcon(Xcos.ICON.getImage());
274
275         initComponents(graph);
276
277         graph.getAsComponent().addKeyListener(new ArrowKeyListener());
278         graph.getModel().addListener(mxEvent.CHANGE, (Object sender, mxEventObject evt) -> {
279             graph.setModified(true);
280             graph.updateTabTitle();
281         });
282     }
283
284     /*
285      * Static API for Tabs
286      */
287
288     /**
289      * Get the tab for a graph.
290      *
291      * @param graph
292      *            the graph
293      * @return the tab (can be null)
294      */
295     public static XcosTab get(XcosDiagram graph) {
296         final String uuid = graph.getGraphTab();
297         if (uuid == null) {
298             return null;
299         }
300
301         return (XcosTab) ScilabTabFactory.getInstance().getFromCache(uuid);
302     }
303
304     /**
305      * Restore or create the viewport tab for the graph
306      *
307      * @param graph
308      *            the graph
309      */
310     public static void restore(XcosDiagram graph) {
311         restore(graph, true);
312     }
313
314     /**
315      * Restore or create the tab for the graph
316      *
317      * @param graph
318      *            the graph
319      * @param visible
320      *            should the tab should be visible
321      */
322     public static void restore(final XcosDiagram graph, final boolean visible) {
323         String uuid = graph.getGraphTab();
324         if (uuid == null) {
325             uuid = UUID.randomUUID().toString();
326         }
327
328         // FIXME: fix a crash on DnD and Tab restore
329
330         final XcosTab tab = new XcosTab(graph, uuid);
331         ScilabTabFactory.getInstance().addToCache(tab);
332
333         if (visible) {
334             tab.createDefaultWindow().setVisible(true);
335
336             graph.fireEvent(new mxEventObject(mxEvent.ROOT));
337             graph.updateTabTitle();
338             BarUpdater.updateBars(tab.getParentWindowId(), tab.getMenuBar(), tab.getToolBar(), tab.getInfoBar(), tab.getName(), tab.getWindowIcon());
339         }
340
341         ClosingOperationsManager.addDependencyWithRoot(tab);
342         ClosingOperationsManager.registerClosingOperation(tab, new ClosingOperation(graph));
343         WindowsConfigurationManager.registerEndedRestoration(tab, new EndedRestoration(graph));
344     }
345
346     /*
347      * Specific implementation
348      */
349
350     /**
351      * Instantiate all the subcomponents of this Tab.
352      *
353      * @param diagram
354      *            the diagram
355      */
356     private void initComponents(final XcosDiagram diagram) {
357         /* Create the menu bar */
358         menuBar = createMenuBar(diagram);
359         setMenuBar(menuBar);
360
361         /* Create the toolbar */
362         final ToolBar toolBar = createToolBar(diagram);
363         setToolBar(toolBar);
364
365         // No SimpleTab.addMember(ScilabComponent ...) so perform a raw
366         // association.
367         setContentPane(diagram.getAsComponent());
368
369         /* Create the infoBar */
370         setInfoBar(ScilabTextBox.createTextBox());
371     }
372
373     /**
374      * Create the windows menu bar
375      *
376      * @param diagram
377      *            the diagram
378      * @return the Xcos diagram menu bar
379      */
380     // CSOFF: JavaNCSS
381     private MenuBar createMenuBar(final XcosDiagram diagram) {
382
383         menuBar = ScilabMenuBar.createMenuBar();
384
385         /** FILE MENU */
386         fileMenu = ScilabMenu.createMenu();
387         fileMenu.setText(XcosMessages.FILE);
388         fileMenu.setMnemonic('F');
389
390         fileMenu.add(NewDiagramAction.createMenu(diagram));
391         fileMenu.add(OpenAction.createMenu(diagram));
392         fileMenu.add(OpenInSciAction.createMenu(diagram));
393         recentsMenu = createRecentMenu();
394         fileMenu.add(recentsMenu);
395         fileMenu.addSeparator();
396
397         fileMenu.add(CloseAction.createMenu(diagram));
398         fileMenu.add(SaveAction.createMenu(diagram));
399         fileMenu.add(SaveAsAction.createMenu(diagram));
400         fileMenu.addSeparator();
401
402         fileMenu.add(ExportAction.createMenu(diagram));
403         fileMenu.add(ExportAllAction.createMenu(diagram));
404         fileMenu.addSeparator();
405
406         fileMenu.add(PrintAction.createMenu(diagram));
407         fileMenu.addSeparator();
408         fileMenu.add(QuitAction.createMenu(diagram));
409
410         menuBar.add(fileMenu);
411
412         /** Edit menu */
413         edit = ScilabMenu.createMenu();
414         edit.setText(XcosMessages.EDIT);
415         edit.setMnemonic('E');
416         menuBar.add(edit);
417
418         edit.add(UndoAction.undoMenu(diagram));
419         edit.add(RedoAction.redoMenu(diagram));
420         edit.addSeparator();
421         edit.add(CutAction.cutMenu(diagram));
422         edit.add(CopyAction.copyMenu(diagram));
423         edit.add(PasteAction.pasteMenu(diagram));
424         edit.add(DeleteAction.createMenu(diagram));
425         edit.addSeparator();
426         edit.add(SelectAllAction.createMenu(diagram));
427         edit.add(InvertSelectionAction.createMenu(diagram));
428         edit.addSeparator();
429         edit.add(BlockParametersAction.createMenu(diagram));
430         edit.addSeparator();
431         edit.add(RegionToSuperblockAction.createMenu(diagram));
432
433         /** View menu */
434         view = ScilabMenu.createMenu();
435         view.setText(XcosMessages.VIEW);
436         view.setMnemonic('V');
437         menuBar.add(view);
438
439         view.add(ZoomInAction.zoominMenu(diagram));
440         view.add(ZoomOutAction.zoomoutMenu(diagram));
441         view.add(FitDiagramToViewAction.createMenu(diagram));
442         view.add(NormalViewAction.createMenu(diagram));
443         view.addSeparator();
444         view.add(ViewPaletteBrowserAction.createCheckBoxMenu(diagram));
445         view.add(ViewDiagramTreeShowAction.createMenu(diagram));
446         view.add(ViewDiagramBrowserAction.createMenu(diagram));
447         final CheckBoxMenuItem menuItem = ViewViewportAction.createCheckBoxMenu(diagram);
448         viewport = (JCheckBoxMenuItem) menuItem.getAsSimpleCheckBoxMenuItem();
449         view.add(menuItem);
450         view.add(ViewDetailsAction.createMenu(diagram));
451
452         /** Simulation menu */
453         simulate = ScilabMenu.createMenu();
454         simulate.setText(XcosMessages.SIMULATION);
455         simulate.setMnemonic('S');
456         menuBar.add(simulate);
457
458         final MenuItem startMenu = StartAction.createMenu(diagram);
459         final MenuItem stopMenu = StopAction.createMenu(diagram);
460
461         simulate.add(SetupAction.createMenu(diagram));
462         simulate.add(DebugLevelAction.createMenu(diagram));
463         simulate.add(SetContextAction.createMenu(diagram));
464         simulate.add(CompileAction.createMenu(diagram));
465         simulate.add(InitModelicaAction.createMenu(diagram));
466         simulate.add(startMenu);
467         simulate.add(stopMenu);
468
469         /** Format menu */
470         format = ScilabMenu.createMenu();
471         format.setText(XcosMessages.FORMAT);
472         format.setMnemonic('O');
473         menuBar.add(format);
474
475         format.add(RotateAction.createMenu(diagram));
476         format.add(FlipAction.createMenu(diagram));
477         format.add(MirrorAction.createMenu(diagram));
478         format.add(ShowHideShadowAction.createMenu(diagram));
479
480         format.addSeparator();
481         alignMenu = ScilabMenu.createMenu();
482         alignMenu.setText(XcosMessages.ALIGN_BLOCKS);
483         alignMenu.add(AlignBlockActionLeft.createMenu(diagram));
484         alignMenu.add(AlignBlockActionCenter.createMenu(diagram));
485         alignMenu.add(AlignBlockActionRight.createMenu(diagram));
486         alignMenu.addSeparator();
487         alignMenu.add(AlignBlockActionTop.createMenu(diagram));
488         alignMenu.add(AlignBlockActionMiddle.createMenu(diagram));
489         alignMenu.add(AlignBlockActionBottom.createMenu(diagram));
490         format.add(alignMenu);
491         format.addSeparator();
492
493         format.add(EditFormatAction.createMenu(diagram));
494         format.add(BorderColorAction.createMenu(diagram));
495         format.add(FilledColorAction.createMenu(diagram));
496         format.addSeparator();
497
498         blockPosition = ScilabMenu.createMenu();
499         blockPosition.setText(XcosMessages.BLOCK_AUTO_POSITION);
500         blockPosition.add(AutoPositionSplitBlockAction.createMenu(diagram));
501         format.add(blockPosition);
502         format.addSeparator();
503
504         linkStyle = ScilabMenu.createMenu();
505         linkStyle.setText(XcosMessages.LINK_STYLE);
506         linkStyle.add(StyleHorizontalAction.createMenu(diagram));
507         linkStyle.add(StyleStraightAction.createMenu(diagram));
508         linkStyle.add(StyleVerticalAction.createMenu(diagram));
509         linkStyle.add(StyleOptimalAction.createMenu(diagram));
510         format.add(linkStyle);
511         format.addSeparator();
512
513         format.add(DiagramBackgroundAction.createMenu(diagram));
514         final CheckBoxMenuItem gridMenu = ViewGridAction.createCheckBoxMenu(diagram);
515         format.add(gridMenu);
516
517         /** Tools menu */
518         tools = ScilabMenu.createMenu();
519         tools.setText(XcosMessages.TOOLS);
520         tools.setMnemonic('T');
521         menuBar.add(tools);
522
523         tools.add(CodeGenerationAction.createMenu(diagram));
524
525         // add external action to the tools menu
526         final List<ExternalAction> externalActions = Xcos.getInstance().getExternalActions();
527         for (ExternalAction action : externalActions) {
528             final MenuItem item = ScilabMenuItem.createMenuItem();
529
530             final SwingScilabMenuItem swingItem = (SwingScilabMenuItem) item.getAsSimpleMenuItem();
531             swingItem.setAction(new ExternalAction(action, diagram));
532
533             tools.add(item);
534         }
535
536         /** Help menu */
537         help = ScilabMenu.createMenu();
538         help.setText(XcosMessages.HELP);
539         help.setMnemonic('?');
540         menuBar.add(help);
541
542         help.add(XcosDocumentationAction.createMenu(diagram));
543         help.add(BlockDocumentationAction.createMenu(diagram));
544         help.addSeparator();
545         help.add(XcosDemonstrationsAction.createMenu(diagram));
546         help.addSeparator();
547         help.add(AboutXcosAction.createMenu(diagram));
548
549         return menuBar;
550     }
551
552     // CSON: JavaNCSS
553
554     /**
555      * Populate recent files menu according to xcos preferences
556      *
557      * @param recent
558      *                  recent files menu
559      */
560     private void populateRecentMenu(final Menu recent) {
561         final ConfigurationManager manager = ConfigurationManager.getInstance();
562         final List<DocumentType> recentFiles = manager.getSettings().getRecent();
563         final int numberOfRecentlyOpen = XcosOptions.getPreferences().getNumberOfRecentlyOpen();
564         final int sizeOfMenu = Math.min(recentFiles.size(), numberOfRecentlyOpen);
565         for (int i = 0; i < sizeOfMenu; i++) {
566             URL url;
567             try {
568                 url = new URL(recentFiles.get(i).getUrl());
569             } catch (final MalformedURLException e) {
570                 Logger.getLogger(XcosTab.class.getName()).severe(e.toString());
571                 break;
572             }
573             recent.add(RecentFileAction.createMenu(url));
574         }
575     }
576
577     /**
578      * Create the recent menu from the previously opened files
579      *
580      * @return the recent menu
581      */
582     private Menu createRecentMenu() {
583         final Menu recent;
584
585         recent = ScilabMenu.createMenu();
586         recent.setText(XcosMessages.RECENT_FILES);
587
588         populateRecentMenu(recent);
589
590         ConfigurationManager.getInstance().addPropertyChangeListener(ConfigurationConstants.RECENT_FILES_CHANGED, new PropertyChangeListener() {
591             @Override
592             public void propertyChange(final PropertyChangeEvent evt) {
593                 assert evt.getPropertyName().equals(ConfigurationConstants.RECENT_FILES_CHANGED);
594
595                 /*
596                  * Remove all items of the recent files menu
597                  */
598                 ((SwingScilabMenu) recent.getAsSimpleMenu()).removeAll();
599
600                 /*
601                  * Populate recent files menu according to Xcos preferences
602                  */
603                 populateRecentMenu(recent);
604             }
605         });
606
607         return recent;
608     }
609
610     /**
611      * Create the Tab toolbar
612      *
613      * @param diagram
614      *            the associated diagram
615      * @return tool bar
616      */
617     private ToolBar createToolBar(final XcosDiagram diagram) {
618         final ToolBar toolBar = ScilabToolBar.createToolBar();
619         SwingScilabToolBar stb = (SwingScilabToolBar) toolBar.getAsSimpleToolBar();
620
621         newDiagramAction = NewDiagramAction.createButton(diagram);
622         stb.add(newDiagramAction);
623
624         openAction = OpenAction.createButton(diagram);
625         stb.add(openAction);
626
627         stb.add(OpenInSciAction.createButton(diagram));
628
629         stb.addSeparator();
630
631         saveAction = SaveAction.createButton(diagram);
632         stb.add(saveAction);
633         saveAsAction = SaveAsAction.createButton(diagram);
634         stb.add(saveAsAction);
635
636         stb.addSeparator();
637
638         printAction = PrintAction.createButton(diagram);
639         stb.add(printAction);
640
641         stb.addSeparator();
642
643         deleteAction = DeleteAction.createButton(diagram);
644         stb.add(deleteAction);
645
646         stb.addSeparator();
647
648         // UNDO / REDO
649         undoAction = UndoAction.undoButton(diagram);
650         redoAction = RedoAction.redoButton(diagram);
651         stb.add(undoAction);
652         stb.add(redoAction);
653
654         stb.addSeparator();
655
656         fitDiagramToViewAction = FitDiagramToViewAction.createButton(diagram);
657         stb.add(fitDiagramToViewAction);
658
659         stb.addSeparator();
660
661         // START / STOP
662         startAction = StartAction.createButton(diagram);
663         stopAction = StopAction.createButton(diagram);
664
665         stb.add(startAction);
666         stb.add(stopAction);
667
668         stb.addSeparator();
669
670         // ZOOMIN / ZOOMOUT
671         zoomInAction = ZoomInAction.zoominButton(diagram);
672         stb.add(zoomInAction);
673         zoomOutAction = ZoomOutAction.zoomoutButton(diagram);
674         stb.add(zoomOutAction);
675
676         stb.addSeparator();
677
678         xcosDemonstrationAction = XcosDemonstrationsAction.createButton(diagram);
679         stb.add(xcosDemonstrationAction);
680         xcosDocumentationAction = XcosDocumentationAction.createButton(diagram);
681         stb.add(xcosDocumentationAction);
682
683         return toolBar;
684     }
685
686     /**
687      * Check/uncheck the viewport check box menu item
688      *
689      * @param status
690      *            the checked status
691      */
692     public void setViewportChecked(boolean status) {
693         viewport.setSelected(status);
694     }
695
696     /**
697      * Get the check/uncheck status of the check box menu item
698      *
699      * @param status
700      *            the checked status
701      */
702     public boolean isViewportChecked() {
703         return viewport.isSelected();
704     }
705
706     private SwingScilabWindow createDefaultWindow() {
707         final SwingScilabWindow win;
708
709         final SwingScilabWindow configuration = WindowsConfigurationManager.createWindow(DEFAULT_WIN_UUID, false);
710         if (configuration != null) {
711             win = configuration;
712         } else {
713             win = SwingScilabWindow.createWindow(true);
714         }
715
716         win.addTab(this);
717         return win;
718     }
719 }
720
721 // CSON: ClassDataAbstractionCoupling
722 // CSON: ClassFanOutComplexity