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