View Javadoc

1   package org.sat4j.sat;
2   
3   import java.awt.BorderLayout;
4   import java.awt.event.ActionEvent;
5   import java.awt.event.ActionListener;
6   
7   import javax.swing.BoxLayout;
8   import javax.swing.ButtonGroup;
9   import javax.swing.JButton;
10  import javax.swing.JPanel;
11  import javax.swing.JRadioButton;
12  import javax.swing.border.CompoundBorder;
13  import javax.swing.border.TitledBorder;
14  
15  import org.sat4j.minisat.core.SimplificationType;
16  
17  public class SimplifierCommandComponent extends CommandComponent {
18  
19      /**
20       * 
21       */
22      private static final long serialVersionUID = 1L;
23  
24      private SolverController controller;
25  
26      private final static String SIMPLIFICATION_APPLY = "Apply";
27      public final static String SIMPLIFICATION_NO = "No reason simplification";
28      public final static String SIMPLIFICATION_SIMPLE = "Simple reason simplification";
29      public final static String SIMPLIFICATION_EXPENSIVE = "Expensive reason simplification";
30  
31      private JButton simplificationApplyButton;
32      private ButtonGroup simplificationGroup;
33      private JRadioButton simplificationNoRadio;
34      private JRadioButton simplificationSimpleRadio;
35      private JRadioButton simplificationExpensiveRadio;
36  
37      public SimplifierCommandComponent(String name, SolverController controller) {
38          this.setName(name);
39          this.controller = controller;
40          createPanel();
41      }
42  
43      @Override
44      public void createPanel() {
45          createSimplifierPanel();
46      }
47  
48      public void createSimplifierPanel() {
49  
50          this.setBorder(new CompoundBorder(new TitledBorder(null,
51                  this.getName(), TitledBorder.LEFT, TitledBorder.TOP),
52                  DetailedCommandPanel.border5));
53  
54          this.setLayout(new BorderLayout());
55  
56          // simplificationRadio = new Radio
57          this.simplificationGroup = new ButtonGroup();
58          this.simplificationExpensiveRadio = new JRadioButton(
59                  SIMPLIFICATION_EXPENSIVE);
60          this.simplificationNoRadio = new JRadioButton(SIMPLIFICATION_NO);
61          this.simplificationSimpleRadio = new JRadioButton(SIMPLIFICATION_SIMPLE);
62  
63          JPanel tmpPanel1 = new JPanel();
64          tmpPanel1.setLayout(new BoxLayout(tmpPanel1, BoxLayout.Y_AXIS));
65  
66          this.simplificationGroup.add(this.simplificationNoRadio);
67          this.simplificationGroup.add(this.simplificationSimpleRadio);
68          this.simplificationGroup.add(this.simplificationExpensiveRadio);
69  
70          tmpPanel1.add(this.simplificationNoRadio);
71          tmpPanel1.add(this.simplificationSimpleRadio);
72          tmpPanel1.add(this.simplificationExpensiveRadio);
73  
74          this.simplificationApplyButton = new JButton(SIMPLIFICATION_APPLY);
75  
76          this.simplificationApplyButton.addActionListener(new ActionListener() {
77              public void actionPerformed(ActionEvent e) {
78                  hasClickedOnApplySimplification();
79              }
80          });
81  
82          JPanel tmpPanel2 = new JPanel();
83          tmpPanel2.add(this.simplificationApplyButton);
84  
85          this.add(tmpPanel1, BorderLayout.NORTH);
86          this.add(tmpPanel2, BorderLayout.SOUTH);
87  
88      }
89  
90      public void setSelectedSimplification(String simplification) {
91          if (simplification.equals(SIMPLIFICATION_EXPENSIVE)) {
92              this.simplificationExpensiveRadio.setSelected(true);
93          } else if (simplification.equals(SIMPLIFICATION_SIMPLE)) {
94              this.simplificationSimpleRadio.setSelected(true);
95          } else {
96              this.simplificationNoRadio.setSelected(true);
97          }
98      }
99  
100     public void hasClickedOnApplySimplification() {
101         if (this.simplificationSimpleRadio.isSelected()) {
102             this.controller
103                     .setSimplifier(SimplificationType.SIMPLE_SIMPLIFICATION);
104         } else if (this.simplificationExpensiveRadio.isSelected()) {
105             this.controller
106                     .setSimplifier(SimplificationType.EXPENSIVE_SIMPLIFICATION);
107         } else {
108             this.controller.setSimplifier(SimplificationType.NO_SIMPLIFICATION);
109         }
110 
111     }
112 
113     public void setSimplifierPanelEnabled(boolean enabled) {
114         this.simplificationNoRadio.setEnabled(enabled);
115         this.simplificationExpensiveRadio.setEnabled(enabled);
116         this.simplificationSimpleRadio.setEnabled(enabled);
117         this.simplificationApplyButton.setEnabled(enabled);
118         this.repaint();
119     }
120 
121 }