KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JFlex > gui > GeneratorThread


1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * JFlex 1.4.1 *
3  * Copyright (C) 1998-2004 Gerwin Klein <lsf@jflex.de> *
4  * All rights reserved. *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License. See the file *
8  * COPYRIGHT for more information. *
9  * *
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  * You should have received a copy of the GNU General Public License along *
16  * with this program; if not, write to the Free Software Foundation, Inc., *
17  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
18  * *
19  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

20
21 package JFlex.gui;
22
23 import JFlex.*;
24
25 import java.io.File JavaDoc;
26
27
28 /**
29  * Low priority thread for code generation (low priority
30  * that gui has time for screen updates)
31  *
32  * @author Gerwin Klein
33  * @version JFlex 1.4.1, $Revision: 2.6 $, $Date: 2004/11/06 23:03:33 $
34  */

35 public class GeneratorThread extends Thread JavaDoc {
36
37   /** there must be at most one instance of this Thread running */
38     private static volatile boolean running = false;
39
40     /** input file setting from GUI */
41     String JavaDoc inputFile;
42
43   /** output directory */
44   String JavaDoc outputDir;
45   
46   /** main UI component, likes to be notified when generator finishes */
47   MainFrame parent;
48
49     /**
50      * Create a new GeneratorThread, but do not run it yet.
51      *
52      * @param parent the frame, main UI component
53      * @param inputFile input file from UI settings
54      * @param messages where generator messages should appear
55      * @param outputDir output directory from UI settings
56      */

57   public GeneratorThread(MainFrame parent, String JavaDoc inputFile,
58                          String JavaDoc outputDir) {
59     this.parent = parent;
60     this.inputFile = inputFile;
61     this.outputDir = outputDir;
62   }
63
64
65     /**
66      * Run the generator thread. Only one instance of it can run at any time.
67      */

68   public void run() {
69     if (running) {
70         Out.error(ErrorMessages.ALREADY_RUNNING);
71             parent.generationFinished(false);
72     }
73     else {
74         running = true;
75             setPriority(MIN_PRIORITY);
76             try {
77         if (!outputDir.equals("")) {
78           Options.setDir(outputDir);
79         }
80                 Main.generate(new File JavaDoc(inputFile));
81                 Out.statistics();
82                 parent.generationFinished(true);
83             }
84             catch (GeneratorException e) {
85                 Out.statistics();
86                 parent.generationFinished(false);
87             }
88       finally {
89         running = false;
90       }
91     }
92   }
93 }
94
Popular Tags