1 package org.sat4j.sat.visu;
2
3 import java.awt.BorderLayout;
4 import java.awt.Color;
5 import java.awt.Container;
6 import java.awt.GridLayout;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9
10 import javax.swing.BoxLayout;
11 import javax.swing.JButton;
12 import javax.swing.JCheckBox;
13 import javax.swing.JColorChooser;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 import javax.swing.JScrollPane;
18 import javax.swing.JTextField;
19 import javax.swing.border.CompoundBorder;
20 import javax.swing.border.EmptyBorder;
21 import javax.swing.border.TitledBorder;
22
23
24
25
26
27
28 public class VisuPreferencesFrame extends JFrame {
29
30 private static final long serialVersionUID = 1L;
31
32 private VisuPreferences preferences;
33 private JPanel mainPanel;
34 private JPanel generalOptionsPanel;
35 private JPanel gnuplotOptionsPanel;
36 private JPanel graphPanel;
37
38 private JLabel backgroundColorLabel;
39 private final static String BACKGROUND_COLOR = "Background color: ";
40 private JButton bgButton;
41 private JLabel borderColorLabel;
42 private final static String BORDER_COLOR = "Border color: ";
43 private JButton borderButton;
44
45 private JLabel nbLinesReadLabel;
46 private final static String NB_LINE = "Number of lines that should be displayed: ";
47 private JTextField nbLinesTextField;
48
49 private JLabel refreshTimeLabel;
50 private final static String REFRESH_TIME = "Refresh Time (in ms): ";
51 private JTextField refreshTimeField;
52
53 private JLabel timeBeforeLaunchLabel;
54 private final static String TIME_BEFORE_LAUNCHING = "Time before launching gnuplot (in ms): ";
55 private JTextField timeBeforeLaunchField;
56
57 private JCheckBox displayRestartsCheckBox;
58 private final static String DISPLAY_RESTARTS = "Display restarts";
59
60 private JLabel restartColorLabel;
61 private final static String RESTART_COLOR = "Restart color";
62 private JButton restartButton;
63
64 private JCheckBox slidingWindows;
65 private final static String SLIDING_WINDOWS = "Use sliding windows";
66
67 private JCheckBox displayDecisionIndexesCB;
68 private final static String DECISION_INDEX = "Show index of decision variables";
69 private JCheckBox displaySpeedCB;
70 private final static String SPEED = "Show number of propagations per second";
71 private JCheckBox displayConflictsTrailCB;
72 private final static String CONFLICTS_TRAIL = "Show trail level when a conflict occurs";
73 private JCheckBox displayConflictsDecisionCB;
74 private final static String CONFLICTS_DECISION = "Show decision level when a conflict occurs";
75 private JCheckBox displayVariablesEvaluationCB;
76 private final static String VARIABLE_EVALUATION = "Show variables evaluation";
77 private JCheckBox displayClausesEvaluationCB;
78 private final static String CLAUSES_EVALUATION = "Show clauses evauluation";
79 private JCheckBox displayClausesSizeCB;
80 private final static String CLAUSES_SIZE = "Show size of learned clauses";
81
82 private JButton okButton;
83 private final static String OK = "OK";
84
85 public VisuPreferencesFrame() {
86 this(new VisuPreferences());
87 }
88
89 public VisuPreferencesFrame(VisuPreferences pref) {
90 super("Visualisation preferences");
91 this.preferences = pref;
92 createAndShowGUI();
93 }
94
95 public void createAndShowGUI() {
96 Container c = this.getContentPane();
97 c.setLayout(new BorderLayout());
98
99 createMainPanel();
100
101 JScrollPane scrollPane = new JScrollPane(this.mainPanel);
102 this.add(scrollPane);
103
104 this.pack();
105 this.setVisible(false);
106 }
107
108 public void createMainPanel() {
109 this.mainPanel = new JPanel();
110 this.mainPanel.setLayout(new BorderLayout());
111
112 this.generalOptionsPanel = new JPanel();
113
114 this.generalOptionsPanel.setName("General options");
115 this.generalOptionsPanel.setBorder(new CompoundBorder(new TitledBorder(
116 null, this.generalOptionsPanel.getName(), TitledBorder.LEFT,
117 TitledBorder.TOP), new EmptyBorder(5, 5, 5, 5)));
118
119 this.generalOptionsPanel.setLayout(new GridLayout(0, 2, 5, 5));
120
121 this.backgroundColorLabel = new JLabel(BACKGROUND_COLOR);
122 this.bgButton = new JButton("");
123 this.bgButton.setOpaque(true);
124 this.bgButton.setBorderPainted(false);
125 this.bgButton.setBackground(this.preferences.getBackgroundColor());
126
127 this.bgButton.addActionListener(new ActionListener() {
128 public void actionPerformed(ActionEvent e) {
129 Color color = JColorChooser.showDialog(getFrame(),
130 "Background Color",
131 VisuPreferencesFrame.this.bgButton.getBackground());
132 VisuPreferencesFrame.this.preferences.setBackgroundColor(color);
133 VisuPreferencesFrame.this.bgButton.setBackground(color);
134 }
135 });
136
137 this.generalOptionsPanel.add(this.backgroundColorLabel);
138 this.generalOptionsPanel.add(this.bgButton);
139
140 this.borderColorLabel = new JLabel(BORDER_COLOR);
141 this.borderButton = new JButton("");
142 this.borderButton.setOpaque(true);
143 this.borderButton.setBorderPainted(false);
144 this.borderButton.setBackground(this.preferences.getBorderColor());
145
146 this.borderButton.addActionListener(new ActionListener() {
147 public void actionPerformed(ActionEvent e) {
148 Color color = JColorChooser.showDialog(getFrame(),
149 "Border Color",
150 VisuPreferencesFrame.this.borderButton.getBackground());
151 VisuPreferencesFrame.this.preferences.setBorderColor(color);
152 VisuPreferencesFrame.this.borderButton.setBackground(color);
153 }
154 });
155
156 this.generalOptionsPanel.add(this.borderColorLabel);
157 this.generalOptionsPanel.add(this.borderButton);
158
159 this.restartColorLabel = new JLabel(RESTART_COLOR);
160 this.restartButton = new JButton("");
161 this.restartButton.setOpaque(true);
162 this.restartButton.setBorderPainted(false);
163 this.restartButton.setBackground(this.preferences.getRestartColor());
164
165
166
167
168 this.restartButton.addActionListener(new ActionListener() {
169 public void actionPerformed(ActionEvent e) {
170 Color color = JColorChooser
171 .showDialog(getFrame(), "Restart Color",
172 VisuPreferencesFrame.this.restartButton
173 .getBackground());
174 VisuPreferencesFrame.this.preferences.setRestartColor(color);
175 VisuPreferencesFrame.this.restartButton.setBackground(color);
176 }
177 });
178
179 this.generalOptionsPanel.add(this.restartColorLabel);
180 this.generalOptionsPanel.add(this.restartButton);
181
182 this.gnuplotOptionsPanel = new JPanel();
183
184 this.gnuplotOptionsPanel.setName("Gnuplot options");
185 this.gnuplotOptionsPanel.setBorder(new CompoundBorder(new TitledBorder(
186 null, this.gnuplotOptionsPanel.getName(), TitledBorder.LEFT,
187 TitledBorder.TOP), new EmptyBorder(5, 5, 5, 5)));
188
189 this.gnuplotOptionsPanel.setLayout(new GridLayout(0, 2, 5, 5));
190
191 this.slidingWindows = new JCheckBox(SLIDING_WINDOWS);
192 this.slidingWindows.setSelected(this.preferences.isSlidingWindows());
193
194 this.slidingWindows.addActionListener(new ActionListener() {
195 public void actionPerformed(ActionEvent e) {
196 VisuPreferencesFrame.this.nbLinesReadLabel
197 .setEnabled(VisuPreferencesFrame.this.slidingWindows
198 .isSelected());
199 VisuPreferencesFrame.this.nbLinesTextField
200 .setEnabled(VisuPreferencesFrame.this.slidingWindows
201 .isSelected());
202 VisuPreferencesFrame.this.preferences
203 .setSlidingWindows(VisuPreferencesFrame.this.slidingWindows
204 .isSelected());
205 }
206 });
207
208 this.gnuplotOptionsPanel.add(this.slidingWindows);
209 this.gnuplotOptionsPanel.add(new JLabel());
210
211 this.nbLinesReadLabel = new JLabel(NB_LINE);
212 this.nbLinesTextField = new JTextField(
213 this.preferences.getNbLinesRead() + "");
214
215 this.nbLinesReadLabel.setEnabled(this.slidingWindows.isSelected());
216 this.nbLinesTextField.setEnabled(this.slidingWindows.isSelected());
217
218 this.gnuplotOptionsPanel.add(this.nbLinesReadLabel);
219 this.gnuplotOptionsPanel.add(this.nbLinesTextField);
220
221 this.refreshTimeLabel = new JLabel(REFRESH_TIME);
222 this.refreshTimeField = new JTextField(
223 this.preferences.getRefreshTime() + "");
224
225 this.gnuplotOptionsPanel.add(this.refreshTimeLabel);
226 this.gnuplotOptionsPanel.add(this.refreshTimeField);
227
228 this.timeBeforeLaunchLabel = new JLabel(TIME_BEFORE_LAUNCHING);
229 this.timeBeforeLaunchField = new JTextField(
230 this.preferences.getTimeBeforeLaunching() + "");
231
232 this.gnuplotOptionsPanel.add(this.timeBeforeLaunchLabel);
233 this.gnuplotOptionsPanel.add(this.timeBeforeLaunchField);
234
235 this.displayRestartsCheckBox = new JCheckBox(DISPLAY_RESTARTS);
236 this.displayRestartsCheckBox.setSelected(this.preferences
237 .isDisplayRestarts());
238
239 this.displayRestartsCheckBox.addActionListener(new ActionListener() {
240 public void actionPerformed(ActionEvent e) {
241 VisuPreferencesFrame.this.restartColorLabel
242 .setEnabled(VisuPreferencesFrame.this.displayRestartsCheckBox
243 .isSelected());
244 VisuPreferencesFrame.this.restartButton
245 .setEnabled(VisuPreferencesFrame.this.displayRestartsCheckBox
246 .isSelected());
247 VisuPreferencesFrame.this.preferences
248 .setDisplayRestarts(VisuPreferencesFrame.this.displayRestartsCheckBox
249 .isSelected());
250 }
251 });
252
253 this.gnuplotOptionsPanel.add(this.displayRestartsCheckBox);
254 this.gnuplotOptionsPanel.add(new JLabel());
255
256 this.okButton = new JButton(OK);
257 this.okButton.addActionListener(new ActionListener() {
258 public void actionPerformed(ActionEvent e) {
259 getFrame().setVisible(false);
260 }
261 });
262
263
264 this.graphPanel = new JPanel();
265 this.graphPanel.setLayout(new BoxLayout(this.graphPanel,
266 BoxLayout.Y_AXIS));
267
268 this.graphPanel.setName("Possible Graphs");
269 this.graphPanel.setBorder(new CompoundBorder(
270 new TitledBorder(null, this.graphPanel.getName(),
271 TitledBorder.LEFT, TitledBorder.TOP), new EmptyBorder(
272 5, 5, 5, 5)));
273
274 this.displayClausesEvaluationCB = new JCheckBox(CLAUSES_EVALUATION);
275 this.graphPanel.add(this.displayClausesEvaluationCB);
276 this.displayClausesEvaluationCB.setSelected(this.preferences
277 .isDisplayClausesEvaluation());
278 this.displayClausesEvaluationCB.addActionListener(new ActionListener() {
279 public void actionPerformed(ActionEvent e) {
280 VisuPreferencesFrame.this.preferences
281 .setDisplayClausesEvaluation(VisuPreferencesFrame.this.displayClausesEvaluationCB
282 .isSelected());
283 }
284 });
285
286 this.displayClausesSizeCB = new JCheckBox(CLAUSES_SIZE);
287 this.graphPanel.add(this.displayClausesSizeCB);
288 this.displayClausesSizeCB.setSelected(this.preferences
289 .isDisplayClausesSize());
290 this.displayClausesSizeCB.addActionListener(new ActionListener() {
291 public void actionPerformed(ActionEvent e) {
292 VisuPreferencesFrame.this.preferences
293 .setDisplayClausesSize(VisuPreferencesFrame.this.displayClausesSizeCB
294 .isSelected());
295 }
296 });
297
298 this.displayConflictsDecisionCB = new JCheckBox(CONFLICTS_DECISION);
299 this.graphPanel.add(this.displayConflictsDecisionCB);
300 this.displayConflictsDecisionCB.setSelected(this.preferences
301 .isDisplayConflictsDecision());
302 this.displayConflictsDecisionCB.addActionListener(new ActionListener() {
303 public void actionPerformed(ActionEvent e) {
304 VisuPreferencesFrame.this.preferences
305 .setDisplayConflictsDecision(VisuPreferencesFrame.this.displayConflictsDecisionCB
306 .isSelected());
307 }
308 });
309
310 this.displayConflictsTrailCB = new JCheckBox(CONFLICTS_TRAIL);
311 this.graphPanel.add(this.displayConflictsTrailCB);
312 this.displayConflictsTrailCB.setSelected(this.preferences
313 .isDisplayConflictsTrail());
314 this.displayConflictsTrailCB.addActionListener(new ActionListener() {
315 public void actionPerformed(ActionEvent e) {
316 VisuPreferencesFrame.this.preferences
317 .setDisplayConflictsTrail(VisuPreferencesFrame.this.displayConflictsTrailCB
318 .isSelected());
319 }
320 });
321
322 this.displayDecisionIndexesCB = new JCheckBox(DECISION_INDEX);
323 this.graphPanel.add(this.displayDecisionIndexesCB);
324 this.displayDecisionIndexesCB.setSelected(this.preferences
325 .isDisplayDecisionIndexes());
326 this.displayDecisionIndexesCB.addActionListener(new ActionListener() {
327 public void actionPerformed(ActionEvent e) {
328 VisuPreferencesFrame.this.preferences
329 .setDisplayDecisionIndexes(VisuPreferencesFrame.this.displayDecisionIndexesCB
330 .isSelected());
331 }
332 });
333
334 this.displaySpeedCB = new JCheckBox(SPEED);
335 this.graphPanel.add(this.displaySpeedCB);
336 this.displaySpeedCB.setSelected(this.preferences.isDisplaySpeed());
337 this.displaySpeedCB.addActionListener(new ActionListener() {
338 public void actionPerformed(ActionEvent e) {
339 VisuPreferencesFrame.this.preferences
340 .setDisplaySpeed(VisuPreferencesFrame.this.displaySpeedCB
341 .isSelected());
342 }
343 });
344
345 this.displayVariablesEvaluationCB = new JCheckBox(VARIABLE_EVALUATION);
346 this.graphPanel.add(this.displayVariablesEvaluationCB);
347 this.displayVariablesEvaluationCB.setSelected(this.preferences
348 .isDisplayVariablesEvaluation());
349 this.displayVariablesEvaluationCB
350 .addActionListener(new ActionListener() {
351 public void actionPerformed(ActionEvent e) {
352 VisuPreferencesFrame.this.preferences
353 .setDisplayVariablesEvaluation(VisuPreferencesFrame.this.displayVariablesEvaluationCB
354 .isSelected());
355 }
356 });
357
358 JPanel topPanel = new JPanel();
359 topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
360
361 topPanel.add(this.generalOptionsPanel);
362 topPanel.add(this.gnuplotOptionsPanel);
363
364 this.mainPanel.add(topPanel, BorderLayout.NORTH);
365 this.mainPanel.add(this.graphPanel, BorderLayout.CENTER);
366 this.mainPanel.add(this.okButton, BorderLayout.SOUTH);
367 }
368
369 public JFrame getFrame() {
370 return this;
371 }
372
373 }