View Javadoc

1   // %1126721451963:hoplugins.trainingExperience.ui%
2   package hoplugins.trainingExperience.ui;
3   
4   import hoplugins.Commons;
5   import hoplugins.TrainingExperience;
6   
7   import hoplugins.commons.utils.PluginProperty;
8   
9   import hoplugins.trainingExperience.dao.DividerDAO;
10  import hoplugins.trainingExperience.ui.component.DividerListener;
11  import hoplugins.trainingExperience.ui.component.FutureSettingPanel;
12  import hoplugins.trainingExperience.ui.model.FutureTrainingsTableModel;
13  import hoplugins.trainingExperience.ui.model.PastTrainingsTableModel;
14  
15  import plugins.IHOMiniModel;
16  
17  import java.awt.BorderLayout;
18  import java.awt.event.ActionEvent;
19  import java.awt.event.ActionListener;
20  
21  import java.util.List;
22  import java.util.Vector;
23  
24  import javax.swing.JButton;
25  import javax.swing.JLabel;
26  import javax.swing.JOptionPane;
27  import javax.swing.JPanel;
28  import javax.swing.JScrollPane;
29  import javax.swing.JSplitPane;
30  import javax.swing.JTable;
31  import javax.swing.table.TableCellEditor;
32  
33  
34  /***
35   * Panel where past and future training are shown
36   */
37  public class TrainingPanel extends JPanel {
38      //~ Instance fields ----------------------------------------------------------------------------
39  
40      /*** Future trainings table model */
41      private FutureTrainingsTableModel futureModel;
42      private JTable futureTable;
43  
44      /*** Past trainings table model */
45      private PastTrainingsTableModel oldTableModel;
46  
47      //~ Constructors -------------------------------------------------------------------------------
48  
49      /***
50       * Creates a new TrainingPanel object.
51       */
52      public TrainingPanel() {
53          super();
54          jbInit();
55      }
56  
57      //~ Methods ------------------------------------------------------------------------------------
58  
59      /***
60       * Returns the list of future trainings
61       *
62       * @return future trainings list
63       */
64      public List getFutureTrainings() {
65          return futureModel.getTrainingsData();
66      }
67  
68      /***
69       * Returns the list of past trainings
70       *
71       * @return past trainings list
72       */
73      public Vector getOldTrainings() {
74          return oldTableModel.getTrainingsData();
75      }
76  
77      /***
78       * Populate the table is called everytime a refresh command is issued
79       */
80      public void reload() {
81          oldTableModel.populate();
82          futureModel.populate();
83          updateUI();
84      }
85  
86      /***
87       * Initialize the object layout
88       */
89      private void jbInit() {
90          IHOMiniModel model = Commons.getModel();
91  
92          // create and populate the old training table
93          oldTableModel = new PastTrainingsTableModel(model);
94  
95          JTable oldTable = new TrainingTable(oldTableModel, model);
96  
97          oldTableModel.populate();
98  
99          JScrollPane scrollPane = new JScrollPane(oldTable);
100 
101         scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
102         scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
103 
104         //create and populate the future training table
105         futureModel = new FutureTrainingsTableModel(model);
106         futureTable = new TrainingTable(futureModel, model);
107         futureModel.populate();
108 
109         JScrollPane scrollPane2 = new JScrollPane(futureTable);
110 
111         scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
112         scrollPane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
113 
114         // Organize the panel layout
115         JPanel panel2 = model.getGUI().createImagePanel();
116 
117         panel2.setLayout(new BorderLayout());
118         panel2.setOpaque(false);
119 
120         JLabel l = new JLabel(PluginProperty.getString("FutureTrainings"), JLabel.CENTER); //$NON-NLS-1$
121 
122         l.setOpaque(false);
123 
124         JButton button = new JButton(PluginProperty.getString("SetAll")); //$NON-NLS-1$
125 
126         button.addActionListener(new ActionListener() {
127                 public void actionPerformed(ActionEvent arg0) {
128                     TableCellEditor editor = futureTable.getCellEditor();
129 
130                     if (editor != null) {
131                         editor.stopCellEditing();
132                     }
133 
134                     JOptionPane.showMessageDialog(TrainingExperience.getPluginPanel(),
135                                                   new FutureSettingPanel(futureModel),
136                                                   PluginProperty.getString("SetAll"), //$NON-NLS-1$
137                                                   JOptionPane.PLAIN_MESSAGE);
138                 }
139             });
140         panel2.add(button, BorderLayout.EAST);
141         panel2.add(l, BorderLayout.CENTER);
142 
143         JSplitPane pane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel2, scrollPane2);
144 
145         pane2.setDividerLocation(25);
146         pane2.setDividerSize(0);
147 
148         JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, pane2);
149 
150         pane.setDividerLocation(DividerDAO.getDividerPosition("TrainingDivider")); //$NON-NLS-1$
151         pane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
152                                        new DividerListener("TrainingDivider")); //$NON-NLS-1$
153         pane.setDividerSize(1);
154         setLayout(new BorderLayout());
155         setOpaque(false);
156         add(pane, BorderLayout.CENTER);
157     }
158 }