MakeLatexAction.java
01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02  *
03  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
04  *
05  * "Hilbert II" is free software; you can redistribute
06  * it and/or modify it under the terms of the GNU General Public
07  * License as published by the Free Software Foundation; either
08  * version 2 of the License, or (at your option) any later version.
09  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  */
15 
16 package org.qedeq.gui.se.control;
17 
18 import java.awt.event.ActionEvent;
19 
20 import javax.swing.AbstractAction;
21 
22 import org.qedeq.base.trace.Trace;
23 import org.qedeq.gui.se.tree.NothingSelectedException;
24 import org.qedeq.kernel.bo.KernelContext;
25 import org.qedeq.kernel.bo.common.QedeqBo;
26 import org.qedeq.kernel.bo.service.latex.Qedeq2LatexPlugin;
27 
28 /**
29  * Create LaTeX file out of selected QEDEQ module files.
30  */
31 class MakeLatexAction extends AbstractAction {
32 
33     /** This class. */
34     private static final Class CLASS = MakeLatexAction.class;
35 
36     /** Controller reference. */
37     private final QedeqController controller;
38 
39     /**
40      * Constructor.
41      *
42      @param   controller  Reference to controller.
43      */
44     MakeLatexAction(final QedeqController controller) {
45         this.controller = controller;
46     }
47 
48     /* inherited
49      */
50     public void actionPerformed(final ActionEvent e) {
51         final String method = "actionPerformed";
52         Trace.begin(CLASS, this, method);
53         try {
54             final QedeqBo[] props;
55             try {
56                 props = controller.getSelected();
57             catch (NothingSelectedException ex) {
58                 controller.selectionError();
59                 return;
60             }
61 
62             final Thread thread = new Thread() {
63                 public void run() {
64                     for (int i = 0; i < props.length; i++) {
65                         KernelContext.getInstance().executePlugin(Qedeq2LatexPlugin.CLASS.getName(),
66                             props[i].getModuleAddress());
67                     }
68                 }
69             };
70             thread.setDaemon(true);
71             thread.start();
72         finally {
73             Trace.end(CLASS, this, method);
74         }
75     }
76 
77 }