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 |
|
---|
21 | package JFlex.gui;
|
---|
22 |
|
---|
23 | import java.awt.*;
|
---|
24 | import java.awt.event.*;
|
---|
25 |
|
---|
26 | import java.io.File;
|
---|
27 |
|
---|
28 | import JFlex.GeneratorException;
|
---|
29 | import JFlex.Options;
|
---|
30 | import JFlex.Skeleton;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * A dialog for setting JFlex options
|
---|
34 | *
|
---|
35 | * @author Gerwin Klein
|
---|
36 | * @version $Revision: 433 $, $Date: 2009-01-31 19:52:34 +1100 (Sat, 31 Jan 2009) $
|
---|
37 | */
|
---|
38 | public class OptionsDialog extends Dialog {
|
---|
39 |
|
---|
40 | private Frame owner;
|
---|
41 |
|
---|
42 | private Button skelBrowse;
|
---|
43 | private TextField skelFile;
|
---|
44 |
|
---|
45 | private Button ok;
|
---|
46 | private Button defaults;
|
---|
47 |
|
---|
48 | private Checkbox dump;
|
---|
49 | private Checkbox verbose;
|
---|
50 | private Checkbox jlex;
|
---|
51 | private Checkbox no_minimize;
|
---|
52 | private Checkbox no_backup;
|
---|
53 | private Checkbox time;
|
---|
54 | private Checkbox dot;
|
---|
55 |
|
---|
56 | private Checkbox tableG;
|
---|
57 | private Checkbox switchG;
|
---|
58 | private Checkbox packG;
|
---|
59 |
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Create a new options dialog
|
---|
63 | *
|
---|
64 | * @param owner
|
---|
65 | */
|
---|
66 | public OptionsDialog(Frame owner) {
|
---|
67 | super(owner, "Options");
|
---|
68 |
|
---|
69 | this.owner = owner;
|
---|
70 |
|
---|
71 | setup();
|
---|
72 | pack();
|
---|
73 |
|
---|
74 | addWindowListener( new WindowAdapter() {
|
---|
75 | public void windowClosing(WindowEvent e) {
|
---|
76 | close();
|
---|
77 | }
|
---|
78 | });
|
---|
79 | }
|
---|
80 |
|
---|
81 | public void setup() {
|
---|
82 | // create components
|
---|
83 | ok = new Button("Ok");
|
---|
84 | defaults = new Button("Defaults");
|
---|
85 | skelBrowse = new Button(" Browse");
|
---|
86 | skelFile = new TextField();
|
---|
87 | skelFile.setEditable(false);
|
---|
88 | dump = new Checkbox(" dump");
|
---|
89 | verbose = new Checkbox(" verbose");
|
---|
90 |
|
---|
91 | jlex = new Checkbox(" JLex compatibility");
|
---|
92 | no_minimize = new Checkbox(" skip minimization");
|
---|
93 | no_backup = new Checkbox(" no backup file");
|
---|
94 | time = new Checkbox(" time statistics");
|
---|
95 | dot = new Checkbox(" dot graph files");
|
---|
96 |
|
---|
97 | CheckboxGroup codeG = new CheckboxGroup();
|
---|
98 | tableG = new Checkbox(" table",Options.gen_method == Options.TABLE, codeG);
|
---|
99 | switchG = new Checkbox(" switch",Options.gen_method == Options.SWITCH, codeG);
|
---|
100 | packG = new Checkbox(" pack",Options.gen_method == Options.PACK, codeG);
|
---|
101 |
|
---|
102 | // setup interaction
|
---|
103 | ok.addActionListener( new ActionListener() {
|
---|
104 | public void actionPerformed(ActionEvent e) {
|
---|
105 | close();
|
---|
106 | }
|
---|
107 | } );
|
---|
108 |
|
---|
109 | defaults.addActionListener( new ActionListener() {
|
---|
110 | public void actionPerformed(ActionEvent e) {
|
---|
111 | setDefaults();
|
---|
112 | }
|
---|
113 | } );
|
---|
114 |
|
---|
115 | skelBrowse.addActionListener( new ActionListener() {
|
---|
116 | public void actionPerformed(ActionEvent e) {
|
---|
117 | skelBrowse();
|
---|
118 | }
|
---|
119 | } );
|
---|
120 |
|
---|
121 | tableG.addItemListener( new ItemListener() {
|
---|
122 | public void itemStateChanged(ItemEvent e) {
|
---|
123 | setGenMethod();
|
---|
124 | }
|
---|
125 | } );
|
---|
126 |
|
---|
127 | verbose.addItemListener( new ItemListener() {
|
---|
128 | public void itemStateChanged(ItemEvent e) {
|
---|
129 | Options.verbose = verbose.getState();
|
---|
130 | }
|
---|
131 | } );
|
---|
132 |
|
---|
133 | dump.addItemListener( new ItemListener() {
|
---|
134 | public void itemStateChanged(ItemEvent e) {
|
---|
135 | Options.dump = dump.getState();
|
---|
136 | }
|
---|
137 | } );
|
---|
138 |
|
---|
139 | jlex.addItemListener( new ItemListener() {
|
---|
140 | public void itemStateChanged(ItemEvent e) {
|
---|
141 | Options.jlex = jlex.getState();
|
---|
142 | }
|
---|
143 | } );
|
---|
144 |
|
---|
145 | no_minimize.addItemListener( new ItemListener() {
|
---|
146 | public void itemStateChanged(ItemEvent e) {
|
---|
147 | Options.no_minimize = no_minimize.getState();
|
---|
148 | }
|
---|
149 | } );
|
---|
150 |
|
---|
151 | no_backup.addItemListener( new ItemListener() {
|
---|
152 | public void itemStateChanged(ItemEvent e) {
|
---|
153 | Options.no_backup = no_backup.getState();
|
---|
154 | }
|
---|
155 | } );
|
---|
156 |
|
---|
157 | dot.addItemListener( new ItemListener() {
|
---|
158 | public void itemStateChanged(ItemEvent e) {
|
---|
159 | Options.dot = dot.getState();
|
---|
160 | }
|
---|
161 | } );
|
---|
162 |
|
---|
163 | time.addItemListener( new ItemListener() {
|
---|
164 | public void itemStateChanged(ItemEvent e) {
|
---|
165 | Options.time = time.getState();
|
---|
166 | }
|
---|
167 | } );
|
---|
168 |
|
---|
169 | // setup layout
|
---|
170 | GridPanel panel = new GridPanel(4,7,10,10);
|
---|
171 | panel.setInsets( new Insets(10,5,5,10) );
|
---|
172 |
|
---|
173 | panel.add(3,0,ok);
|
---|
174 | panel.add(3,1,defaults);
|
---|
175 |
|
---|
176 | panel.add(0,0,2,1,Handles.BOTTOM,new Label("skeleton file:"));
|
---|
177 | panel.add(0,1,2,1,skelFile);
|
---|
178 | panel.add(2,1,1,1,Handles.TOP, skelBrowse);
|
---|
179 |
|
---|
180 | panel.add(0,2,1,1,Handles.BOTTOM,new Label("code:"));
|
---|
181 | panel.add(0,3,1,1,tableG);
|
---|
182 | panel.add(0,4,1,1,switchG);
|
---|
183 | panel.add(0,5,1,1,packG);
|
---|
184 |
|
---|
185 | panel.add(1,3,1,1,dump);
|
---|
186 | panel.add(1,4,1,1,verbose);
|
---|
187 | panel.add(1,5,1,1,time);
|
---|
188 |
|
---|
189 |
|
---|
190 | panel.add(2,3,1,1,no_minimize);
|
---|
191 | panel.add(2,4,1,1,no_backup);
|
---|
192 |
|
---|
193 | panel.add(3,3,1,1,jlex);
|
---|
194 | panel.add(3,4,1,1,dot);
|
---|
195 |
|
---|
196 | add("Center",panel);
|
---|
197 |
|
---|
198 | updateState();
|
---|
199 | }
|
---|
200 |
|
---|
201 | private void skelBrowse() {
|
---|
202 | FileDialog d = new FileDialog(owner , "Choose file", FileDialog.LOAD);
|
---|
203 | d.show();
|
---|
204 |
|
---|
205 | if (d.getFile() != null) {
|
---|
206 | File skel = new File(d.getDirectory()+d.getFile());
|
---|
207 | try {
|
---|
208 | Skeleton.readSkelFile(skel);
|
---|
209 | skelFile.setText(skel.toString());
|
---|
210 | }
|
---|
211 | catch (GeneratorException e) {
|
---|
212 | // do nothing
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | private void setGenMethod() {
|
---|
218 | if ( tableG.getState() ) {
|
---|
219 | Options.gen_method = Options.TABLE;
|
---|
220 | return;
|
---|
221 | }
|
---|
222 |
|
---|
223 | if ( switchG.getState() ) {
|
---|
224 | Options.gen_method = Options.SWITCH;
|
---|
225 | return;
|
---|
226 | }
|
---|
227 |
|
---|
228 | if ( packG.getState() ) {
|
---|
229 | Options.gen_method = Options.PACK;
|
---|
230 | return;
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | private void updateState() {
|
---|
235 | dump.setState(Options.dump);
|
---|
236 | verbose.setState(Options.verbose);
|
---|
237 | jlex.setState(Options.jlex);
|
---|
238 | no_minimize.setState(Options.no_minimize);
|
---|
239 | no_backup.setState(Options.no_backup);
|
---|
240 | time.setState(Options.time);
|
---|
241 | dot.setState(Options.dot);
|
---|
242 |
|
---|
243 | tableG.setState(Options.gen_method == Options.TABLE);
|
---|
244 | switchG.setState(Options.gen_method == Options.SWITCH);
|
---|
245 | packG.setState(Options.gen_method == Options.PACK);
|
---|
246 | }
|
---|
247 |
|
---|
248 | private void setDefaults() {
|
---|
249 | Options.setDefaults();
|
---|
250 | Skeleton.readDefault();
|
---|
251 | skelFile.setText("");
|
---|
252 | updateState();
|
---|
253 | }
|
---|
254 |
|
---|
255 | public void close() {
|
---|
256 | hide();
|
---|
257 | }
|
---|
258 |
|
---|
259 | }
|
---|