View Javadoc

1   package org.sat4j.sat;
2   
3   import java.awt.BorderLayout;
4   import java.awt.FlowLayout;
5   import java.awt.event.ActionEvent;
6   import java.awt.event.ActionListener;
7   
8   import javax.swing.JButton;
9   import javax.swing.JLabel;
10  import javax.swing.JPanel;
11  import javax.swing.JTextField;
12  import javax.swing.border.CompoundBorder;
13  import javax.swing.border.TitledBorder;
14  
15  public class RandomWalkCommandComponent extends CommandComponent {
16  
17      /**
18       * 
19       */
20      private static final long serialVersionUID = 1L;
21  
22      private SolverController controller;
23  
24      private JLabel probaRWLabel;
25      private JTextField probaRWField;
26  
27      private JButton applyRWButton;
28  
29      private final static String RW_LABEL = "Probabilty : ";
30      private final static String RW_APPLY = "Apply";
31  
32      public RandomWalkCommandComponent(String name, SolverController controller) {
33          this.controller = controller;
34          this.setName(name);
35          createPanel();
36      }
37  
38      @Override
39      public void createPanel() {
40          createRWPanel();
41      }
42  
43      public void createRWPanel() {
44  
45          this.setBorder(new CompoundBorder(new TitledBorder(null,
46                  this.getName(), TitledBorder.LEFT, TitledBorder.TOP),
47                  DetailedCommandPanel.border5));
48  
49          this.setLayout(new BorderLayout());
50  
51          this.probaRWLabel = new JLabel(RW_LABEL);
52          this.probaRWField = new JTextField("0", 10);
53  
54          this.probaRWLabel.setLabelFor(this.probaRWField);
55  
56          JPanel tmpPanel1 = new JPanel();
57          tmpPanel1.setLayout(new FlowLayout());
58  
59          tmpPanel1.add(this.probaRWLabel);
60          tmpPanel1.add(this.probaRWField);
61  
62          JPanel tmpPanel2 = new JPanel();
63          this.applyRWButton = new JButton(RW_APPLY);
64  
65          this.applyRWButton.addActionListener(new ActionListener() {
66              public void actionPerformed(ActionEvent e) {
67                  hasClickedOnApplyRW();
68              }
69          });
70  
71          tmpPanel2.add(this.applyRWButton);
72  
73          this.add(tmpPanel1, BorderLayout.CENTER);
74          this.add(tmpPanel2, BorderLayout.SOUTH);
75  
76      }
77  
78      public void hasClickedOnApplyRW() {
79          double proba = 0;
80          if (this.probaRWField != null) {
81              proba = Double.parseDouble(this.probaRWField.getText());
82          }
83  
84          this.controller.setRandomWalkProba(proba);
85      }
86  
87      public void setRWPanelEnabled(boolean enabled) {
88          this.probaRWLabel.setEnabled(enabled);
89          this.probaRWField.setEnabled(enabled);
90          this.applyRWButton.setEnabled(enabled);
91          this.repaint();
92      }
93  
94      public void setProba(double proba) {
95          this.probaRWField.setText(proba + "");
96          this.repaint();
97      }
98  
99  }