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