View Javadoc

1   // %1956788941:hoplugins.trainingExperience.ui.component%
2   package hoplugins.trainingExperience.ui.component;
3   
4   import hoplugins.Commons;
5   import hoplugins.TrainingExperience;
6   
7   import hoplugins.trainingExperience.constants.Trainings;
8   import hoplugins.trainingExperience.ui.model.FutureTrainingsTableModel;
9   
10  import plugins.IFutureTrainingWeek;
11  import plugins.IHOMiniModel;
12  
13  import java.awt.event.ActionEvent;
14  import java.awt.event.ActionListener;
15  
16  import java.util.Iterator;
17  import java.util.List;
18  
19  import javax.swing.JButton;
20  import javax.swing.JComboBox;
21  import javax.swing.JPanel;
22  
23  
24  /***
25   * Panel for Settings all the future training week
26   *
27   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
28   */
29  public class FutureSettingPanel extends JPanel {
30      //~ Instance fields ----------------------------------------------------------------------------
31  
32      private FutureTrainingsTableModel futureModel;
33      private JComboBox intensity;
34      private JComboBox training;
35  
36      //~ Constructors -------------------------------------------------------------------------------
37  
38      /***
39       * Creates a new FutureSettingPanel object.
40       *
41       * @param fm The futureTraining table model, used to update it when needed
42       */
43      public FutureSettingPanel(FutureTrainingsTableModel fm) {
44          super();
45          futureModel = fm;
46          jbInit();
47      }
48  
49      //~ Methods ------------------------------------------------------------------------------------
50  
51      /***
52       * Populate the Future training table with the future training
53       */
54      protected void resetFutureTraininhgs() {
55          IHOMiniModel p_IHMM_miniModel = Commons.getModel();
56          List futureTrainings = p_IHMM_miniModel.getFutureTrainingWeeks();
57  
58          for (Iterator iter = futureTrainings.iterator(); iter.hasNext();) {
59              IFutureTrainingWeek train = (IFutureTrainingWeek) iter.next();
60              train.setIntensitaet(intensity.getSelectedIndex());
61              train.setTyp(Trainings.getTrainingCode((String) training.getSelectedItem()));
62              p_IHMM_miniModel.saveFutureTraining(train);
63          }
64  
65          futureModel.populate();
66          TrainingExperience.getTrainPanel().updateUI();
67          TrainingExperience.refreshPlayerDetail();
68      }
69  
70      /***
71       * Initializes the state of this instance.
72       */
73      private void jbInit() {
74          training = new TrainingComboBox();
75          intensity = new IntensityComboBox();
76          intensity.setSelectedIndex(100);
77  
78          JButton button = new JButton(Commons.getModel().getResource().getProperty("Aendern")); //$NON-NLS-1$
79  
80          button.addActionListener(new ActionListener() {
81                  public void actionPerformed(ActionEvent arg0) {
82                      resetFutureTraininhgs();
83                  }
84              });
85          add(training);
86          add(intensity);
87          add(button);
88      }
89  }