source: other-projects/rsyntax-textarea/devel-packages/jflex-1.4.3/src/JFlex/gui/GeneratorThread.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 3.2 KB
Line 
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * JFlex 1.4.3 *
3 * Copyright (C) 1998-2009 Gerwin Klein <[email protected]> *
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
21package JFlex.gui;
22
23import JFlex.*;
24
25import java.io.File;
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.3, $Revision: 433 $, $Date: 2009-01-31 19:52:34 +1100 (Sat, 31 Jan 2009) $
34 */
35public class GeneratorThread extends Thread {
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 inputFile;
42
43 /** output directory */
44 String 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 inputFile,
58 String 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(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}
Note: See TracBrowser for help on using the repository browser.