001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.gui.se.control;
017
018 import java.util.ArrayList;
019
020 import javax.swing.Action;
021 import javax.swing.JFrame;
022 import javax.swing.JMenuItem;
023 import javax.swing.JOptionPane;
024
025 import org.qedeq.gui.se.tree.NothingSelectedException;
026 import org.qedeq.gui.se.tree.QedeqTreeCtrl;
027 import org.qedeq.gui.se.util.DataDictionary;
028 import org.qedeq.gui.se.util.GuiHelper;
029 import org.qedeq.gui.se.util.MenuHelper;
030 import org.qedeq.kernel.bo.KernelContext;
031 import org.qedeq.kernel.bo.common.QedeqBo;
032 import org.qedeq.kernel.se.common.ModuleService;
033
034
035 /**
036 * Controller for a the GUI application.
037 *
038 * A Controller, which represents the classes connecting the model and the view, and is used to
039 * communicate between classes in the model and view.
040 * Connects the models and the views. Handles program flow.
041 *
042 * LATER mime 20070605: encapsulate actions that need another thread
043 * for later java versions: use Executor framework
044 * mime 20130417: perhaps the kernel should use a thread pooling framework
045 *
046 * @author Michael Meyling
047 */
048 public class QedeqController {
049
050 /** Tree controller. */
051 private QedeqTreeCtrl treeCtrl;
052
053 /** About action. */
054 private final Action aboutAction;
055
056 /** Help action. */
057 private final Action helpAction;
058
059 /** Exit action. */
060 private final Action exitAction;
061
062 /** Add QEDEQ module from web. */
063 private final Action addAction;
064
065 /** Add QEDEQ module from local file. */
066 private final Action addFileAction;
067
068 /** Remove all QEDEQ modules from memory. */
069 private final Action removeAllAction;
070
071 /** Remove all QEDEQ modules from local buffer. */
072 private final Action removeLocalBufferAction;
073
074 /** Remove all selected QEDEQ modules from memory. */
075 private final Action removeModuleAction;
076
077 /** Add all modules from <a href="http://www.qedeq.org/">Hilbert II</a> webpage. */
078 private final Action addAllModulesFromQedeqAction;
079
080 /** Show all service processes. */
081 private final Action processViewAction;
082
083 /** Terminate all service processes. */
084 private final Action terminateAllAction;
085
086 /** Check if QEDEQ modules are well formed. */
087 private final Action checkWellFormedAction;
088
089 /** Check if QEDEQ modules are fully and correctly formally proved. */
090 private final Action checkFormallyProvedAction;
091
092 /** Remove all plugin results for QEDEQ module. */
093 private final Action removePluginResultsAction;
094
095 /** Show preferences window. */
096 private final Action preferencesAction;
097
098 /** Show plugin preferences window. */
099 private final Action pluginPreferencesAction;
100
101 /** Show parser window. */
102 private final Action latexParserAction;
103
104 /** Show parser window. */
105 private final Action textParserAction;
106
107 /** Show parser window. */
108 private final Action proofTextParserAction;
109
110 /** List of already wanted QEDEQ modules.*/
111 private final ArrayList moduleHistory;
112
113 /** Reference to main frame. */
114 private final JFrame main;
115
116 /** Maximum number of entries in history. */
117 static final int MAXIMUM_MODULE_HISTORY = 20; // LATER 20070606: put into properties
118
119 /**
120 * Constructor.
121 *
122 * @param main Reference to main frame.
123 */
124 public QedeqController(final JFrame main) {
125 this.main = main;
126 aboutAction = new AboutAction(this);
127 helpAction = new HelpAction(this);
128 preferencesAction = new PreferencesAction(this);
129 pluginPreferencesAction = new PluginPreferencesAction(this);
130 latexParserAction = new LatexParserAction(this);
131 textParserAction = new TextParserAction(this);
132 proofTextParserAction = new ProofTextParserAction(this);
133 exitAction = new ExitAction();
134 addAction = new AddAction(this);
135 addFileAction = new AddFileAction(this);
136 addAllModulesFromQedeqAction = new AddAllModulesFromQedeqAction();
137 removeAllAction = new RemoveAllAction();
138 removeModuleAction = new RemoveModuleAction(this);
139 removeLocalBufferAction = new RemoveLocalBufferAction();
140 checkWellFormedAction = new CheckWellFormedAction(this);
141 checkFormallyProvedAction = new CheckFormallyProvedAction(this);
142 removePluginResultsAction = new RemovePluginResultsAction(this);
143 processViewAction = new ProcessViewAction();
144 terminateAllAction = new TerminateAllAction();
145
146 final String[] list = KernelContext.getInstance().getConfig().getModuleHistory();
147 moduleHistory = new ArrayList();
148 for (int i = 0; i < list.length; i++) {
149 getModuleHistory().add(list[i]);
150 }
151
152 // LATER mime 20070606: dynamic evaluation from web page?
153 if (getModuleHistory().size() == 0) {
154 final String prefix = "http://wwww.qedeq.org/"
155 + KernelContext.getInstance().getKernelVersionDirectory() + "/doc/";
156 getModuleHistory().add(prefix + "math/qedeq_logic_v1.xml");
157 getModuleHistory().add(prefix + "math/qedeq_formal_logic_v1.xml");
158 getModuleHistory().add(prefix + "math/qedeq_set_theory_v1.xml");
159 getModuleHistory().add(prefix + "project/qedeq_basic_concept.xml");
160 getModuleHistory().add(prefix + "project/qedeq_logic_language.xml");
161 getModuleHistory().add(prefix + "sample/qedeq_sample1.xml");
162 getModuleHistory().add(prefix + "sample/qedeq_sample2.xml");
163 getModuleHistory().add(prefix + "sample/qedeq_sample3.xml");
164 getModuleHistory().add(prefix + "sample/qedeq_sample4.xml");
165 }
166 }
167
168 /**
169 * Set tree controller.
170 *
171 * @param treeCtrl Tree controller.
172 */
173 public void setTreeCtrl(final QedeqTreeCtrl treeCtrl) {
174 this.treeCtrl = treeCtrl;
175 }
176
177 /**
178 * Get selected module.
179 *
180 * @return Selected modules.
181 * @throws NothingSelectedException No modules were selected.
182 */
183 public QedeqBo[] getSelected() throws NothingSelectedException {
184 return treeCtrl.getSelected();
185 }
186
187 /**
188 * Get about action.
189 *
190 * @return Action.
191 */
192 public Action getAboutAction() {
193 return aboutAction;
194 }
195
196 /**
197 * Get help action.
198 *
199 * @return Action.
200 */
201 public Action getHelpAction() {
202 return helpAction;
203 }
204
205 /**
206 * Get preferences window startup action.
207 *
208 * @return Action.
209 */
210 public Action getPreferencesAction() {
211 return preferencesAction;
212 }
213
214 /**
215 * Get plugin preferences window startup action.
216 *
217 * @return Action.
218 */
219 public Action getPluginPreferencesAction() {
220 return pluginPreferencesAction;
221 }
222
223 /**
224 * Get parser window startup action.
225 *
226 * @return Action.
227 */
228 public Action getLatexParserAction() {
229 return latexParserAction;
230 }
231
232 /**
233 * Get parser window startup action.
234 *
235 * @return Action.
236 */
237 public Action getTextParserAction() {
238 return textParserAction;
239 }
240
241 /**
242 * Get parser window startup action.
243 *
244 * @return Action.
245 */
246 public Action getProofTextParserAction() {
247 return proofTextParserAction;
248 }
249
250 /**
251 * Get exit action.
252 *
253 * @return Action.
254 */
255 public Action getExitAction() {
256 return exitAction;
257 }
258
259 /**
260 * Get action for adding a new QEDEQ module out of the web.
261 *
262 * @return Action.
263 */
264 public Action getAddAction() {
265 return addAction;
266 }
267
268 /**
269 * Get action for adding a new QEDEQ module from a local file.
270 *
271 * @return Action.
272 */
273 public Action getAddFileAction() {
274 return addFileAction;
275 }
276
277 /**
278 * Get all plugin actions as menu entries.
279 *
280 * @return Menu entries for plugins.
281 */
282 public JMenuItem[] getPluginMenuEntries() {
283 final ModuleService[] plugins = KernelContext.getInstance().getPlugins();
284 final PluginAction[] pluginActions = new PluginAction[plugins.length];
285 for (int i = 0; i < plugins.length; i++) {
286 pluginActions[i] = new PluginAction(this, plugins[i]);
287 }
288 JMenuItem[] result = new JMenuItem[pluginActions.length];
289 for (int i = 0; i < pluginActions.length; i++) {
290 final JMenuItem item = MenuHelper.createMenuItem(pluginActions[i].getPlugin()
291 .getServiceAction());
292 item.addActionListener(pluginActions[i]);
293 item.setIcon(pluginActions[i].getIcon());
294 item.setToolTipText(GuiHelper.getToolTipText(pluginActions[i].getPlugin()
295 .getServiceDescription()));
296 result[i] = item;
297 }
298 return result;
299 }
300
301 /**
302 * Get action for checking if the selected QEDEQ modules are well formed.
303 *
304 * @return Action.
305 */
306 public Action getCheckWellFormedAction() {
307 return checkWellFormedAction;
308 }
309
310 /**
311 * Get action for checking if the selected QEDEQ modules are fully and formally correctly proved.
312 *
313 * @return Action.
314 */
315 public Action getCheckFormallyProvedAction() {
316 return checkFormallyProvedAction;
317 }
318
319 /**
320 * Get action for removing all plugin results for the selected QEDEQ modules.
321 *
322 * @return Action.
323 */
324 public Action getRemovePluginResultsAction() {
325 return removePluginResultsAction;
326 }
327
328 /**
329 * Get action for removing all QEDEQ modules from memory.
330 *
331 * @return Action.
332 */
333 public Action getRemoveAllAction() {
334 return removeAllAction;
335 }
336
337 /**
338 * Get action for removing all seelected QEDEQ modules from memory.
339 *
340 * @return Action.
341 */
342 public Action getRemoveModuleAction() {
343 return removeModuleAction;
344 }
345
346 /**
347 * Get action for removing all QEDEQ modules from memory and local buffer.
348 *
349 * @return Action.
350 */
351 public Action getRemoveLocalBufferAction() {
352 return removeLocalBufferAction;
353 }
354
355 /**
356 * Get action for loading all QEDEQ modules for the current release from the QEDEQ web site.
357 *
358 * @return Action.
359 */
360 public Action getAddAllModulesFromQedeqAction() {
361 return addAllModulesFromQedeqAction;
362 }
363
364 /**
365 * Get action for starting the service process viewer.
366 *
367 * @return Action.
368 */
369 public Action getProcessViewAction() {
370 return processViewAction;
371 }
372
373 /**
374 * Get action for stopping all currently running plugin actions.
375 *
376 * @return Action.
377 */
378 public Action getTerminateAllAction() {
379 return terminateAllAction;
380 }
381
382 /**
383 * This method returns a string from the resource bundle.
384 *
385 * @param key Name to look for.
386 * @return Value.
387 */
388 public String getString(final String key) {
389 return DataDictionary.getInstance().getString(key);
390 }
391
392 /**
393 * Returns a mnemonic from the resource bundle. Typically used as
394 * keyboard shortcuts in menu items.
395 *
396 * @param key Name to look for.
397 * @return Mnemonic.
398 */
399 public char getMnemonic(final String key) {
400 return DataDictionary.getInstance().getMnemonic(key);
401 }
402
403 void addToModuleHistory(final String url) {
404 getModuleHistory().add(0, url);
405 for (int i = 1; i < getModuleHistory().size(); i++) {
406 if (url.equals(getModuleHistory().get(i))) {
407 getModuleHistory().remove(i);
408 i--;
409 }
410 }
411 for (int i = getModuleHistory().size() - 1; i >= QedeqController.MAXIMUM_MODULE_HISTORY;
412 i--) {
413 getModuleHistory().remove(i);
414 }
415 KernelContext.getInstance().getConfig().saveModuleHistory(getModuleHistory());
416 }
417
418 ArrayList getModuleHistory() {
419 return moduleHistory;
420 }
421
422 JFrame getMainFrame() {
423 return main;
424 }
425
426 void selectionError() {
427 JOptionPane.showMessageDialog(
428 QedeqController.this.main,
429 "No QEDEQ module selected! In the tree at least one QEDEQ module must be selected",
430 "Error",
431 JOptionPane.ERROR_MESSAGE,
432 null);
433 }
434
435 }
|