View Javadoc

1   // %1180046389:hoplugins.teamAnalyzer.ui%
2   package hoplugins.teamAnalyzer.ui;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.ui.sorter.AbstractTableSorter;
7   import hoplugins.commons.utils.RatingUtil;
8   
9   import hoplugins.teamAnalyzer.SystemManager;
10  
11  import java.text.DecimalFormat;
12  
13  import java.util.ArrayList;
14  import java.util.Comparator;
15  import java.util.List;
16  
17  import javax.swing.table.TableModel;
18  
19  
20  /***
21   * TODO Missing Class Documentation
22   *
23   * @author TODO Author Name
24   */
25  public class RecapTableSorter extends AbstractTableSorter {
26      //~ Instance fields ----------------------------------------------------------------------------
27  
28      private List skills;
29  
30      //~ Constructors -------------------------------------------------------------------------------
31  
32      /***
33       * Creates a new RecapTableSorter object.
34       *
35       * @param tableModel TODO Missing Constructuor Parameter Documentation
36       */
37      public RecapTableSorter(TableModel tableModel) {
38          super(tableModel);
39          skills = new ArrayList();
40  
41          for (int i = 1; i < 21; i++) {
42              skills.add(Commons.getModel().getHelper().getNameForBewertung(i, false, false));
43          }
44      }
45  
46      //~ Methods ------------------------------------------------------------------------------------
47  
48      /***
49       * TODO Missing Method Documentation
50       *
51       * @param column TODO Missing Method Parameter Documentation
52       *
53       * @return TODO Missing Return Method Documentation
54       */
55      public Comparator getCustomComparator(int column) {
56          if ((column > 4) && (column < 12)) {
57              return new Comparator() {
58                      public boolean equals(Object arg0) {
59                          return false;
60                      }
61  
62                      public int compare(Object arg0, Object arg1) {
63                          try {
64                              double d1 = RatingUtil.getRating(arg0 + "",
65                                                               SystemManager.getConfig()
66                                                                            .isNumericRating(),
67                                                               SystemManager.getConfig()
68                                                                            .isDescriptionRating(),
69                                                               skills);
70                              double d2 = RatingUtil.getRating(arg1 + "",
71                                                               SystemManager.getConfig()
72                                                                            .isNumericRating(),
73                                                               SystemManager.getConfig()
74                                                                            .isDescriptionRating(),
75                                                               skills);
76  
77                              if (d1 > d2) {
78                                  return 1;
79                              }
80  
81                              if (d1 < d2) {
82                                  return -1;
83                              }
84                          } catch (Exception e) {
85                          }
86  
87                          return 0;
88                      }
89                  };
90          }
91  
92          if ((column > 11) && (column < 16)) {
93              return new Comparator() {
94                      private DecimalFormat df = new DecimalFormat("###.#");
95  
96                      public boolean equals(Object arg0) {
97                          return false;
98                      }
99  
100                     public int compare(Object arg0, Object arg1) {
101                         try {
102                             double d1 = df.parse(arg0 + "").doubleValue();
103                             double d2 = df.parse(arg1 + "").doubleValue();
104 
105                             if (d1 > d2) {
106                                 return 1;
107                             }
108 
109                             if (d1 < d2) {
110                                 return -1;
111                             }
112                         } catch (Exception e) {
113                             e.printStackTrace();
114                         }
115 
116                         return 0;
117                     }
118                 };
119         }
120 
121         if (column == 16) {
122             return new Comparator() {
123                     private DecimalFormat df = new DecimalFormat("###.##");
124 
125                     public boolean equals(Object arg0) {
126                         return false;
127                     }
128 
129                     public int compare(Object arg0, Object arg1) {
130                         try {
131                             double d1 = df.parse(arg0 + "").doubleValue();
132                             double d2 = df.parse(arg1 + "").doubleValue();
133 
134                             if (d1 > d2) {
135                                 return 1;
136                             }
137 
138                             if (d1 < d2) {
139                                 return -1;
140                             }
141                         } catch (Exception e) {
142                             e.printStackTrace();
143                         }
144 
145                         return 0;
146                     }
147                 };
148         }
149 
150         if (column == 18) {
151             return new Comparator() {
152                     public boolean equals(Object arg0) {
153                         return false;
154                     }
155 
156                     public int compare(Object arg0, Object arg1) {
157                         try {
158                             double d1 = RatingUtil.getRating(arg0 + "", false, true, skills);
159                             double d2 = RatingUtil.getRating(arg1 + "", false, true, skills);
160 
161                             if (d1 > d2) {
162                                 return 1;
163                             }
164 
165                             if (d1 < d2) {
166                                 return -1;
167                             }
168                         } catch (Exception e) {
169                         }
170 
171                         return 0;
172                     }
173                 };
174         }
175 
176         return null;
177     }
178 
179     /***
180      * TODO Missing Method Documentation
181      *
182      * @return TODO Missing Return Method Documentation
183      */
184     public boolean hasHeaderLine() {
185         return true;
186     }
187 
188     /***
189      * TODO Missing Method Documentation
190      *
191      * @return TODO Missing Return Method Documentation
192      */
193     public int minSortableColumn() {
194         return 3;
195     }
196 }