View Javadoc

1   package org.inigma.waragent.view;
2   
3   import java.text.NumberFormat;
4   
5   import org.eclipse.swt.SWT;
6   import org.eclipse.swt.layout.FillLayout;
7   import org.eclipse.swt.widgets.Composite;
8   import org.eclipse.swt.widgets.Table;
9   import org.eclipse.swt.widgets.TableColumn;
10  import org.eclipse.swt.widgets.TableItem;
11  import org.inigma.utopia.Survey;
12  import org.inigma.utopia.utils.I18NUtil;
13  
14  /**
15   * @author <a href="mailto:sejal@inigma.org">Sejal Patel</a>
16   * @version $Revision: 1 $
17   */
18  class SurveyComposite extends Composite {
19      private Table table;
20  
21      private Survey survey;
22  
23      public SurveyComposite(Composite parent, Survey survey) {
24          super(parent, SWT.NONE);
25          setLayout(new FillLayout());
26  
27          table = new Table(this, SWT.SINGLE);
28          table.setHeaderVisible(true);
29          table.setLinesVisible(true);
30          addTableColumn("Acres", 75, false);
31          addTableColumn("Acres %", 75, false);
32          addTableColumn("Building", 200, true);
33  //        addTableColumn("Progress", 75, false);
34  //        addTableColumn("Required", 75, false);
35  //        addTableColumn("Target %", 50, false);
36  
37          setSurvey(survey);
38      }
39  
40      private void addTableColumn(String title, int width, boolean leftAlign) {
41          TableColumn column = new TableColumn(table, SWT.NONE);
42          column.setText(title);
43          column.setWidth(width);
44          column.setAlignment(leftAlign ? SWT.LEFT : SWT.RIGHT);
45      }
46  
47      public void setSurvey(Survey survey) {
48          this.survey = survey;
49          update();
50      }
51  
52      private void addTableItem(String title, int acres) {
53          NumberFormat pf = I18NUtil.getPercentageFormat();
54          NumberFormat nf = I18NUtil.getGroupFormat();
55  
56          TableItem item = new TableItem(table, SWT.NONE);
57          item.setText(0, nf.format(acres));
58          item.setText(1, pf.format((float) acres / (float) survey.getProvince().getAcres()));
59          item.setText(2, title);
60  //        item.setText(3, nf.format(0));
61  //        item.setText(4, nf.format(0));
62  //        item.setText(5, pf.format((float) acres / (float) survey.getTotalAcres()));
63      }
64  
65      @Override
66      public void update() {
67          table.removeAll();
68  
69          addTableItem("Unknown", survey.getProvince().getAcres() - survey.getTotalAcres());
70          addTableItem("Barren Lands", survey.getBarren());
71          addTableItem("Homes", survey.getHomes());
72          addTableItem("Farms", survey.getFarms());
73          addTableItem("Mills", survey.getMills());
74          addTableItem("Banks", survey.getBanks());
75          addTableItem("Training Grounds", survey.getTrainingGrounds());
76          addTableItem("Armouries", survey.getArmories());
77          addTableItem("Barracks", survey.getBarracks());
78          addTableItem("Forts", survey.getForts());
79          addTableItem("Guard Stations", survey.getGuardStations());
80          addTableItem("Hospitals", survey.getHospitals());
81          addTableItem("Guilds", survey.getGuilds());
82          addTableItem("Towers", survey.getTowers());
83          addTableItem("Thief Dens", survey.getThievesDens());
84          addTableItem("Watchtowers", survey.getWatchtowers());
85          addTableItem("Libraries", survey.getLibraries());
86          addTableItem("Schools", survey.getSchools());
87          addTableItem("Stables", survey.getStables());
88          addTableItem("Dungeons", survey.getDungeons());
89          
90          table.update();
91          super.update();
92      }
93  }