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