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