View Javadoc

1   // %1654063142:hoplugins.teamAnalyzer.ui%
2   /*
3    * Created on Sep 20, 2004
4    *
5    * To change the template for this generated file go to
6    * Window>Preferences>Java>Code Generation>Code and Comments
7    */
8   package hoplugins.teamAnalyzer.ui;
9   
10  import hoplugins.Commons;
11  
12  import hoplugins.commons.ui.BaseTableModel;
13  
14  import hoplugins.teamAnalyzer.report.TacticReport;
15  
16  import java.awt.BorderLayout;
17  
18  import java.text.DecimalFormat;
19  import java.text.NumberFormat;
20  
21  import java.util.Arrays;
22  import java.util.Iterator;
23  import java.util.List;
24  import java.util.Vector;
25  
26  import javax.swing.BorderFactory;
27  import javax.swing.JPanel;
28  import javax.swing.JTable;
29  import javax.swing.border.EtchedBorder;
30  import javax.swing.table.DefaultTableModel;
31  
32  
33  /***
34   * DOCUMENT ME!
35   *
36   * @author mamato To change the template for this generated type comment go to
37   *         Window>Preferences>Java>Code Generation>Code and Comments
38   */
39  public class TacticPanel extends JPanel {
40      //~ Instance fields ----------------------------------------------------------------------------
41  
42      private DefaultTableModel tableModel;
43      private JTable table;
44      private NumberFormat f = new DecimalFormat("#.#");
45  
46      //~ Constructors -------------------------------------------------------------------------------
47  
48      /***
49       * Creates a new TacticPanel object.
50       */
51      public TacticPanel() {
52          jbInit();
53      }
54  
55      //~ Methods ------------------------------------------------------------------------------------
56  
57      /***
58       * TODO Missing Method Documentation
59       *
60       * @param number TODO Missing Method Parameter Documentation
61       *
62       * @return TODO Missing Return Method Documentation
63       */
64      public String format(double number) {
65          return f.format(number);
66      }
67  
68      /***
69       * TODO Missing Method Documentation
70       *
71       * @param list TODO Missing Method Parameter Documentation
72       */
73      public void reload(List list) {
74          tableModel = new BaseTableModel(new Vector(),
75                                          new Vector(Arrays.asList(new Object[]{
76                                                                       "COL_A", "COL_B", "COL_C"
77                                                                   })));
78          table.setModel(tableModel);
79  
80          Vector rowData;
81          int row = 0;
82  
83          for (Iterator iter = list.iterator(); iter.hasNext();) {
84              TacticReport report = (TacticReport) iter.next();
85  
86              rowData = new Vector();
87              rowData.add(getTacticalRoleDesc(report.getTacticCode()));
88              rowData.add("" + report.getAppearance());
89              rowData.add(format(report.getRating()));
90              tableModel.addRow(rowData);
91              row++;
92  
93              if (row == 3) {
94                  break;
95              }
96          }
97  
98          if (row > 0) {
99              this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
100 
101             for (; row < 3; row++) {
102                 tableModel.addRow(emptyLine());
103             }
104         } else {
105             this.setBorder(null);
106         }
107 
108         table.getTableHeader().getColumnModel().getColumn(1).setMaxWidth(30);
109         table.getTableHeader().getColumnModel().getColumn(2).setMaxWidth(30);
110     }
111 
112     /***
113      * TODO Missing Method Documentation
114      *
115      * @param position TODO Missing Method Parameter Documentation
116      *
117      * @return TODO Missing Return Method Documentation
118      */
119     private String getTacticalRoleDesc(int position) {
120         return Commons.getModel().getHelper().getNameForPosition((byte) position);
121     }
122 
123     /***
124      *
125      */
126     private Vector emptyLine() {
127         Vector v = new Vector();
128 
129         return v;
130     }
131 
132     /***
133      * TODO Missing Method Documentation
134      */
135     private void jbInit() {
136         Vector data = new Vector();
137 
138         tableModel = new BaseTableModel(data,
139                                         new Vector(Arrays.asList(new Object[]{
140                                                                      "COL_A", "COL_B", "COL_C"
141                                                                  })));
142         table = new JTable(tableModel);
143         table.setRowSelectionAllowed(false);
144         table.setColumnSelectionAllowed(false);
145         this.setLayout(new BorderLayout());
146         this.add(table, BorderLayout.CENTER);
147         table.getTableHeader().getColumnModel().getColumn(1).setMaxWidth(30);
148         table.getTableHeader().getColumnModel().getColumn(2).setMaxWidth(30);
149     }
150 }