View Javadoc

1   package org.inigma.waragent.view;
2   
3   import java.text.DateFormat;
4   import java.text.NumberFormat;
5   import java.util.Calendar;
6   
7   import org.eclipse.swt.SWT;
8   import org.eclipse.swt.layout.FillLayout;
9   import org.eclipse.swt.widgets.Composite;
10  import org.eclipse.swt.widgets.Table;
11  import org.eclipse.swt.widgets.TableColumn;
12  import org.eclipse.swt.widgets.TableItem;
13  import org.inigma.utopia.Army;
14  import org.inigma.utopia.Military;
15  import org.inigma.utopia.utils.CalendarUtils;
16  import org.inigma.utopia.utils.I18NUtil;
17  
18  /**
19   * @author <a href="mailto:sejal@inigma.org">Sejal Patel</a>
20   * @version $Revision: 1 $
21   */
22  class MilitaryComposite extends Composite {
23      private Table table;
24  
25      private Military military;
26  
27      public MilitaryComposite(Composite parent, Military military) {
28          super(parent, SWT.NONE);
29          setLayout(new FillLayout());
30  
31          table = new Table(this, SWT.SINGLE);
32          table.setHeaderVisible(true);
33          table.setLinesVisible(true);
34          TableColumn col = new TableColumn(table, SWT.NONE);
35          col.setText("ETA");
36          col.setWidth(125);
37          col = new TableColumn(table, SWT.NONE);
38          col.setText("Gens");
39          col.setWidth(75);
40          col = new TableColumn(table, SWT.NONE);
41          col.setText("Soldiers");
42          col.setWidth(75);
43          col = new TableColumn(table, SWT.NONE);
44          col.setText("Off Specs");
45          col.setWidth(75);
46          col = new TableColumn(table, SWT.NONE);
47          col.setText("Def Specs");
48          col.setWidth(75);
49          col = new TableColumn(table, SWT.NONE);
50          col.setText("Elites");
51          col.setWidth(75);
52          col = new TableColumn(table, SWT.NONE);
53          col.setText("Horses");
54          col.setWidth(75);
55          col = new TableColumn(table, SWT.NONE);
56          col.setText("Captured");
57          col.setWidth(75);
58  
59          setMilitary(military);
60      }
61  
62      public void setMilitary(Military military) {
63          this.military = military;
64          update();
65      }
66  
67      @Override
68      public void update() {
69          NumberFormat nf = I18NUtil.getGroupFormat();
70          DateFormat sdf = I18NUtil.getTimeFormat();
71          Calendar now = CalendarUtils.getCalendar();
72          table.removeAll();
73  
74          for (Army army : military.getArmies()) {
75              TableItem item = new TableItem(table, SWT.NONE);
76              if (now.after(army.getReturnTime())) {
77                  item.setText(0, "---");
78              } else {
79                  item.setText(0, sdf.format(army.getReturnTime().getTime()));
80              }
81              item.setText(1, nf.format(army.getGenerals()));
82              item.setText(2, nf.format(army.getSoldiers()));
83              item.setText(3, nf.format(army.getOffspecs()));
84              item.setText(4, nf.format(army.getDefspecs()));
85              item.setText(5, nf.format(army.getElites()));
86              item.setText(6, nf.format(army.getHorses()));
87              item.setText(7, nf.format(army.getSpoils()));
88          }
89  
90          table.update();
91          super.update();
92      }
93  }