1 /* 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Copyright (C) 2015 - Scilab Enterprises 4 * 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises 6 * 7 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * This file was originally licensed under the terms of the CeCILL v2.1, 10 * and continues to be available under such terms. 11 * For more information, see the COPYING file which you should have received 12 * along with this program. 13 * 14 */ 15 16 package org.scilab.modules.ui_data.newsfeed; 17 18 import org.scilab.modules.ui_data.newsfeed.actions.CloseAction; 19 import org.scilab.modules.ui_data.newsfeed.actions.HelpAction; 20 import org.scilab.modules.ui_data.newsfeed.actions.UpdateAction; 21 22 import org.scilab.modules.gui.bridge.tab.SwingScilabDockablePanel; 23 import org.scilab.modules.gui.bridge.toolbar.SwingScilabToolBar; 24 import org.scilab.modules.gui.bridge.window.SwingScilabWindow; 25 import org.scilab.modules.gui.textbox.ScilabTextBox; 26 import org.scilab.modules.gui.textbox.TextBox; 27 import org.scilab.modules.gui.toolbar.ScilabToolBar; 28 import org.scilab.modules.gui.toolbar.ToolBar; 29 import org.scilab.modules.gui.menu.Menu; 30 import org.scilab.modules.gui.menu.ScilabMenu; 31 import org.scilab.modules.gui.menubar.MenuBar; 32 import org.scilab.modules.gui.menubar.ScilabMenuBar; 33 import org.scilab.modules.gui.tab.SimpleTab; 34 import org.scilab.modules.gui.utils.ClosingOperationsManager; 35 import org.scilab.modules.gui.utils.WindowsConfigurationManager; 36 import org.scilab.modules.gui.tabfactory.ScilabTabFactory; 37 38 import org.scilab.modules.ui_data.utils.UiDataMessages; 39 40 import java.util.List; 41 import java.util.ListIterator; 42 43 44 /** 45 * Main class to display a news feed in a tab Dockable panel (jflexdock) For 46 * now, manages one tab only 47 */ 48 public class NewsFeedTab extends SwingScilabDockablePanel implements SimpleTab { 49 50 public static final String NEWSFEED_UUID = "DC0957B3-81DA-4E39-B0B5-E93B35412162"; 51 public static final String NEWSFEED_HELP_ID = "newsfeed"; 52 53 private static NewsFeedTab instance = null; 54 55 private NewsFeedWidget newsFeedWidget; 56 private NewsFeedController newsFeedController; 57 58 static { 59 ScilabTabFactory.getInstance().addTabFactory(NewsFeedTabFactory.getInstance()); 60 } 61 getInstance()62 public static NewsFeedTab getInstance() { 63 if (instance == null) { 64 instance = new NewsFeedTab(); 65 } 66 return instance; 67 } 68 NewsFeedTab()69 private NewsFeedTab() { 70 super(NewsFeedUIMessages.NEWS_FEED, NEWSFEED_UUID); 71 72 newsFeedController = new NewsFeedController(); 73 newsFeedWidget = new NewsFeedWidget(newsFeedController); 74 newsFeedController.addNewsFeedEventListener(newsFeedWidget); 75 76 setContentPane(newsFeedWidget); 77 78 addMenuBar(createMenuBar()); 79 addToolBar(createToolBar()); 80 TextBox infobar = ScilabTextBox.createTextBox(); 81 addInfoBar(infobar); 82 83 registerClosingOperation(); 84 WindowsConfigurationManager.restorationFinished(this); 85 86 setAssociatedXMLIDForHelp(NEWSFEED_HELP_ID); 87 88 startNewsFeed(); 89 } 90 displayTab()91 public static void displayTab() { 92 WindowsConfigurationManager.restoreWindow(NEWSFEED_UUID); 93 } 94 startNewsFeed()95 public void startNewsFeed() { 96 newsFeedController.start(); 97 } 98 updateNewsFeed()99 public void updateNewsFeed() { 100 newsFeedController.updateNewsFeed(); 101 } 102 closeTab()103 public void closeTab() { 104 stopNewsFeed(); 105 instance = null; 106 } 107 addInfoBar(TextBox infoBar)108 public void addInfoBar(TextBox infoBar) { 109 setInfoBar(infoBar); 110 } 111 addToolBar(ToolBar toolBar)112 public void addToolBar(ToolBar toolBar) { 113 setToolBar(toolBar); 114 } 115 addMenuBar(MenuBar menuBar)116 public void addMenuBar(MenuBar menuBar) { 117 setMenuBar(menuBar); 118 } 119 getParentWindow()120 public SwingScilabWindow getParentWindow() { 121 return SwingScilabWindow.allScilabWindows.get(getParentWindowId()); 122 } 123 getAsSimpleTab()124 public SimpleTab getAsSimpleTab() { 125 return this; 126 } 127 createMenuBar()128 private MenuBar createMenuBar() { 129 MenuBar menuBar = ScilabMenuBar.createMenuBar(); 130 131 Menu fileMenu = ScilabMenu.createMenu(); 132 fileMenu.setText(UiDataMessages.FILE); 133 fileMenu.setMnemonic('F'); 134 fileMenu.add(CloseAction.createMenuItem()); 135 fileMenu.add(UpdateAction.createMenuItem()); 136 menuBar.add(fileMenu); 137 138 Menu helpMenu = ScilabMenu.createMenu(); 139 helpMenu.setText(NewsFeedUIMessages.NEWS_FEED_HELP_LABEL); 140 helpMenu.setMnemonic('?'); 141 helpMenu.add(HelpAction.createMenuItem()); 142 menuBar.add(helpMenu); 143 144 return menuBar; 145 } 146 createToolBar()147 private ToolBar createToolBar() { 148 ToolBar toolBar = ScilabToolBar.createToolBar(); 149 SwingScilabToolBar swingScilabToolBar = (SwingScilabToolBar) toolBar.getAsSimpleToolBar(); 150 swingScilabToolBar.add(UpdateAction.createPushButton()); 151 swingScilabToolBar.addSeparator(); 152 swingScilabToolBar.add(HelpAction.createPushButton()); 153 return toolBar; 154 } 155 registerClosingOperation()156 private void registerClosingOperation() { 157 ClosingOperationsManager.registerClosingOperation(this, new ClosingOperationsManager.ClosingOperation() { 158 159 @Override 160 public int canClose() { 161 return 1; 162 } 163 164 @Override 165 public void destroy() { 166 closeTab(); 167 } 168 169 @Override 170 public String askForClosing(final List<SwingScilabDockablePanel> list) { 171 return null; 172 } 173 174 @Override 175 public void updateDependencies(List<SwingScilabDockablePanel> list, 176 ListIterator<SwingScilabDockablePanel> it) { 177 } 178 }); 179 180 ClosingOperationsManager.addDependencyWithRoot(this); 181 } 182 stopNewsFeed()183 private void stopNewsFeed() { 184 newsFeedController.stop(); 185 } 186 } 187