1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3
* Copyright (C) 1998-2001 Gerwin Klein <lsf@jflex.de> *
4
* All rights reserved. *
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. *
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. *
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 *
19
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
import java.awt.event.*;
31
* JFlex main application frame (GUI mode only)
33
* @author Gerwin Klein
34
* @version JFlex 1.3.5, $Revision: 1.16 $, $Date: 2001/10/08 10:08:14 $
36
final public class MainFrame extends Frame implements Handles {
38
private boolean choosing;
40
private String fileName = "";
41
private String dirName = "";
44
private Button generate;
46
private Button specChoose;
47
private Button dirChoose;
49
private TextField spec;
50
private TextField dir;
52
private TextArea messages;
54
private GeneratorThread thread;
58
super("JFlex "+Main.version);
61
addWindowListener( new WindowAdapter() {
62
public void windowClosing(WindowEvent e) {
72
private void buildContent() {
73
setBackground(SystemColor.control);
75
generate = new Button("Generate");
76
quit = new Button("Quit");
77
stop = new Button("Stop");
78
dirChoose = new Button("Choose");
79
dir = new TextField(10);
80
specChoose = new Button("Choose");
81
spec = new TextField(10);
82
messages = new TextArea(10,80);
84
messages.setEditable(false);
85
Font font = messages.getFont();
87
messages.setFont(new Font("Monospaced", font.getStyle(), font.getSize()));
89
messages.setFont(new Font("Monospaced", Font.PLAIN, 12));
91
generate.addActionListener( new ActionListener() {
92
public void actionPerformed(ActionEvent e) {
97
quit.addActionListener( new ActionListener() {
98
public void actionPerformed(ActionEvent e) {
103
stop.addActionListener( new ActionListener() {
104
public void actionPerformed(ActionEvent e) {
109
specChoose.addActionListener( new ActionListener() {
110
public void actionPerformed(ActionEvent e) {
115
dirChoose.addActionListener( new ActionListener() {
116
public void actionPerformed(ActionEvent e) {
121
spec.addActionListener( new ActionListener() {
122
public void actionPerformed(ActionEvent e) {
123
fileName = spec.getText();
128
spec.addTextListener( new TextListener() {
129
public void textValueChanged(TextEvent e) {
130
fileName = spec.getText();
134
dir.addActionListener( new ActionListener() {
135
public void actionPerformed(ActionEvent e) {
136
dirName = dir.getText();
141
dir.addTextListener( new TextListener() {
142
public void textValueChanged(TextEvent e) {
143
dirName = dir.getText();
147
GridPanel north = new GridPanel(5,4,10,10);
148
north.setInsets( new Insets(10,5,5,10) );
150
north.add( 4,0, quit);
151
north.add( 4,1, generate);
152
north.add( 4,2, stop);
154
north.add( 0,0, BOTTOM, new Label("Lexical specification:"));
155
north.add( 0,1, 2,1, spec);
156
north.add( 2,1, specChoose);
158
north.add( 0,2, BOTTOM, new Label("Output directory:"));
159
north.add( 0,3, 2,1, dir);
160
north.add( 2,3, dirChoose);
162
Panel center = new Panel(new BorderLayout());
163
center.add("North", new Label("Messages:"));
164
center.add("Center", messages);
167
add("Center", center);
169
setEnabledAll(false);
172
public Dimension getPreferredSize() {
173
Dimension d = super.getPreferredSize();
174
d.width = messages.getPreferredSize().width;
178
private void setEnabledAll(boolean generating) {
179
stop.setEnabled( generating );
180
quit.setEnabled( !generating );
181
generate.setEnabled( !generating );
182
dirChoose.setEnabled( !generating );
183
dir.setEnabled( !generating );
184
specChoose.setEnabled( !generating );
185
spec.setEnabled( !generating );
188
private void generate() {
189
// workaround for a weird AWT bug
190
if (choosing) return;
194
thread = new GeneratorThread(this, fileName, messages, dirName);
198
public void generationFinished(boolean success) {
199
setEnabledAll(false);
202
messages.append(Out.NL+"Generation finished successfully."+Out.NL);
204
messages.append(Out.NL+"Generation aborted."+Out.NL);
207
private void stop() {
208
if (thread != null) {
211
generationFinished(false);
215
private void quit() {
220
private void dirChoose() {
223
FileDialog d = new FileDialog(this, "Choose directory", FileDialog.LOAD);
227
if (d.getDirectory() != null) {
228
dir.setText( (new File(d.getDirectory())).getAbsolutePath() );
234
private void specChoose() {
237
FileDialog d = new FileDialog(this, "Choose file", FileDialog.LOAD);
242
if (d.getFile() != null) {
243
fileName = d.getDirectory()+d.getFile();
244
dir.setText(d.getDirectory());
245
spec.setText(fileName);