1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.sat4j.sat;
31
32 import java.awt.BorderLayout;
33 import java.awt.Container;
34 import java.awt.Dimension;
35 import java.awt.Toolkit;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.WindowAdapter;
39 import java.awt.event.WindowEvent;
40 import java.io.BufferedReader;
41 import java.io.IOException;
42 import java.io.InputStreamReader;
43 import java.net.URL;
44
45 import javax.swing.Box;
46 import javax.swing.ButtonGroup;
47 import javax.swing.JFrame;
48 import javax.swing.JLabel;
49 import javax.swing.JMenu;
50 import javax.swing.JMenuBar;
51 import javax.swing.JMenuItem;
52 import javax.swing.JOptionPane;
53 import javax.swing.JRadioButtonMenuItem;
54 import javax.swing.JScrollPane;
55
56 import org.sat4j.minisat.core.ICDCLLogger;
57 import org.sat4j.minisat.orders.RandomWalkDecorator;
58 import org.sat4j.sat.visu.VisuPreferencesFrame;
59
60
61
62
63
64
65
66
67 public class RemoteControlFrame extends JFrame implements ICDCLLogger {
68
69
70
71
72 private static final long serialVersionUID = 1L;
73
74 private String lookAndFeel;
75
76 public static final Dimension dim = Toolkit.getDefaultToolkit()
77 .getScreenSize();
78
79 private JMenuBar barreMenu;
80 private JMenu menu;
81 private JMenuItem activateTracing;
82
83 private DetailedCommandPanel commandePanel;
84 private String filename;
85
86 private String ramdisk;
87
88 private RemoteControlStrategy telecomStrategy;
89 private RandomWalkDecorator randomWalk;
90
91 private String[] args;
92 private VisuPreferencesFrame visuFrame;
93
94 private final static String ACTIVATE = "Activate Tracing";
95 private final static String DEACTIVATE = "Deactivate Tracing";
96
97 private JRadioButtonMenuItem gnuplotBasedRadio;
98 private JRadioButtonMenuItem jChartBasedRadio;
99
100 public RemoteControlFrame(String filename, String ramdisk, String[] args) {
101 super("Remote Control");
102
103 this.filename = filename;
104 this.ramdisk = ramdisk;
105
106 this.args = args;
107 initLookAndFeel();
108
109 createAndShowGUI();
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123 public RemoteControlFrame(String filename, String ramdisk) {
124 this(filename, ramdisk, new String[] {});
125 }
126
127 public RemoteControlFrame(String filename) {
128 this(filename, "", new String[] {});
129 }
130
131
132
133
134
135 public RemoteControlFrame(String filename, String[] args) {
136 this(filename, "", args);
137 }
138
139 public void reinitialiser() {
140 }
141
142 public void setActivateGnuplot(boolean b) {
143 this.activateTracing.setSelected(b);
144 activateTracing(b);
145 }
146
147 public void initLookAndFeel() {
148 JFrame.setDefaultLookAndFeelDecorated(true);
149 }
150
151 public void createAndShowGUI() {
152 Container c = this.getContentPane();
153 c.setLayout(new BorderLayout());
154
155 createMenuBar();
156
157 this.commandePanel = new DetailedCommandPanel(this.filename,
158 this.ramdisk, this.args, this);
159
160 this.commandePanel.setChartBased(true);
161 this.commandePanel.activateGnuplotTracing(true);
162
163 this.visuFrame = new VisuPreferencesFrame(
164 this.commandePanel.getGnuplotPreferences());
165
166 JScrollPane scrollPane = new JScrollPane(this.commandePanel);
167
168 this.add(scrollPane);
169
170
171 this.addWindowListener(new WindowAdapter() {
172
173 @Override
174 public void windowClosing(WindowEvent e) {
175 RemoteControlFrame.this.commandePanel.stopVisu();
176 System.exit(NORMAL);
177 }
178
179 });
180
181 this.pack();
182 this.setVisible(true);
183 }
184
185 public void clickOnAboutSolver() {
186 if (this.commandePanel.getSolver() != null) {
187 JOptionPane.showMessageDialog(this, this.commandePanel.getSolver()
188 .toString());
189 } else {
190 JOptionPane.showMessageDialog(this,
191 "No solver is running at the moment. Please start solver.");
192 }
193 }
194
195 public void setActivateTracingEditableUnderCondition(boolean b) {
196 if (this.activateTracing.getText().equals(ACTIVATE)) {
197 this.activateTracing.setEnabled(b);
198 }
199 }
200
201 public void setActivateTracingEditable(boolean b) {
202 this.activateTracing.setEnabled(b);
203 }
204
205 public void createMenuBar() {
206 this.barreMenu = new JMenuBar();
207 this.menu = new JMenu("File");
208 this.barreMenu.add(this.menu);
209
210
211
212
213
214
215
216
217
218
219 this.activateTracing = new JMenuItem(DEACTIVATE);
220 this.menu.add(this.activateTracing);
221
222 this.activateTracing.addActionListener(new ActionListener() {
223 public void actionPerformed(ActionEvent e) {
224 activateTracing(RemoteControlFrame.this.activateTracing
225 .getText().equals(ACTIVATE));
226 }
227 });
228
229 this.menu.addSeparator();
230
231 this.gnuplotBasedRadio = new JRadioButtonMenuItem("Trace with Gnuplot");
232 this.jChartBasedRadio = new JRadioButtonMenuItem("Trace with Java");
233
234 ButtonGroup visuGroup = new ButtonGroup();
235 visuGroup.add(this.gnuplotBasedRadio);
236 visuGroup.add(this.jChartBasedRadio);
237
238 this.menu.add(this.gnuplotBasedRadio);
239
240 this.gnuplotBasedRadio.addActionListener(new ActionListener() {
241 public void actionPerformed(ActionEvent e) {
242 RemoteControlFrame.this.commandePanel.setGnuplotBased(true);
243 RemoteControlFrame.this.commandePanel.setChartBased(false);
244 RemoteControlFrame.this.commandePanel
245 .activateGnuplotTracing(RemoteControlFrame.this.activateTracing
246 .getText().equals(DEACTIVATE));
247
248 log("Use gnuplot tracing");
249 }
250 });
251 this.jChartBasedRadio.setSelected(true);
252
253 this.menu.add(this.jChartBasedRadio);
254
255 this.jChartBasedRadio.addActionListener(new ActionListener() {
256 public void actionPerformed(ActionEvent e) {
257 RemoteControlFrame.this.commandePanel.setGnuplotBased(false);
258 RemoteControlFrame.this.commandePanel.setChartBased(true);
259 RemoteControlFrame.this.commandePanel
260 .activateGnuplotTracing(RemoteControlFrame.this.activateTracing
261 .getText().equals(DEACTIVATE));
262 log("Use java tracing");
263 }
264 });
265
266
267
268
269
270
271
272
273
274
275 this.menu.addSeparator();
276
277 JMenuItem quit = new JMenuItem("Exit");
278 this.menu.add(quit);
279
280 quit.addActionListener(new ActionListener() {
281 public void actionPerformed(ActionEvent e) {
282
283
284
285
286
287
288
289
290 RemoteControlFrame.this.commandePanel.stopVisu();
291 System.exit(NORMAL);
292 }
293 });
294
295 JMenu preferences = new JMenu("Preferences");
296 JMenuItem gnuplotPreferencesItem = new JMenuItem(
297 "Visualisation preferences");
298
299 gnuplotPreferencesItem.addActionListener(new ActionListener() {
300 public void actionPerformed(ActionEvent e) {
301 RemoteControlFrame.this.visuFrame.setVisible(true);
302 }
303 });
304
305 preferences.add(gnuplotPreferencesItem);
306
307 this.barreMenu.add(preferences);
308
309 this.barreMenu.add(Box.createHorizontalGlue());
310
311
312 JLabel version = new JLabel(getVersion());
313 this.barreMenu.add(version);
314
315 this.setJMenuBar(this.barreMenu);
316
317 }
318
319 public void log(String message) {
320 this.commandePanel.log(message);
321 }
322
323 private String getVersion() {
324 URL url = RemoteControlFrame.class.getResource("/sat4j.version");
325 String s = "";
326 if (url == null) {
327 s = "no version file found!!!";
328 } else {
329 BufferedReader in = null;
330 try {
331 in = new BufferedReader(new InputStreamReader(url.openStream()));
332 s = "version " + in.readLine();
333 } catch (IOException e) {
334 s = "c ERROR: " + e.getMessage();
335 } finally {
336 if (in != null) {
337 try {
338 in.close();
339 } catch (IOException e) {
340 s = "c ERROR: " + e.getMessage();
341 }
342 }
343 }
344 }
345 return s;
346 }
347
348 public void activateTracing(boolean b) {
349 if (b) {
350 log("Activated tracing");
351 this.activateTracing.setText(DEACTIVATE);
352
353 this.commandePanel.setPlotActivated(true);
354 } else {
355 log("Deactivated tracing.");
356 this.activateTracing.setText(ACTIVATE);
357 this.commandePanel.stopVisu();
358 this.commandePanel.setPlotActivated(false);
359
360 }
361 if (this.commandePanel.getStartStopText().equals("Stop")
362 && this.activateTracing.getText().equals(ACTIVATE)) {
363 this.activateTracing.setEnabled(false);
364 } else {
365 this.activateTracing.setEnabled(true);
366 }
367 }
368
369 public void setOptimisationMode(boolean optimizationMode) {
370 this.commandePanel.setOptimisationMode(optimizationMode);
371 }
372
373 }