1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.firemox.chart.datasets;
21
22 import java.util.Collection;
23
24 import org.jfree.data.statistics.HistogramType;
25
26 import net.sf.firemox.chart.ChartFilter;
27 import net.sf.firemox.chart.IChartKey;
28 import net.sf.firemox.chart.IDataProvider;
29 import net.sf.firemox.clickable.target.card.CardModel;
30
31 /***
32 *
33 */
34 public class HistogramDataset extends
35 org.jfree.data.statistics.HistogramDataset implements Dataset {
36
37 private int[] values = new int[0];
38
39 /***
40 * Create a new instance of this class.
41 *
42 * @param provider
43 * the key provider.
44 * @param filter
45 * the filter attached to this data set.
46 */
47 public HistogramDataset(IDataProvider provider, ChartFilter filter) {
48 super();
49 this.provider = provider;
50 this.filter = filter;
51 this.setType(HistogramType.FREQUENCY);
52 }
53
54 /***
55 * Add cards to all data sets.
56 *
57 * @param cardModel
58 * the card to add.
59 * @param amount
60 * the amount of card to add.
61 */
62 public void addCard(final CardModel cardModel, final int amount) {
63 Collection<IChartKey> keys = provider.getKeys(cardModel, filter);
64 for (IChartKey key : keys) {
65 if (key.getIntegerKey() + 1 > values.length) {
66 int[] tmp = new int[key.getIntegerKey() + 1];
67 System.arraycopy(values, 0, tmp, 0, values.length);
68 values = tmp;
69 }
70 values[key.getIntegerKey()] += amount;
71 }
72 list.clear();
73 int max = 0;
74 for (int value : values) {
75 if (value > max)
76 max = value;
77 }
78 double[] amounts = new double[max + 1];
79 for (int index = max + 1; index-- > 0;) {
80 amounts[values[index]] = index;
81 }
82 try {
83 addSeries("data1", amounts, amounts.length, 0, amounts.length);
84 } catch (Exception e) {
85 e.printStackTrace();
86 }
87 fireDatasetChanged();
88 }
89
90 /***
91 * Remove cards to all data sets.
92 *
93 * @param cardModel
94 * the card to remove.
95 * @param amount
96 * the amount of card to remove.
97 */
98 public void removeCard(final CardModel cardModel, final int amount) {
99 Collection<IChartKey> keys = provider.getKeys(cardModel, filter);
100 for (IChartKey key : keys) {
101 values[key.getIntegerKey()] -= amount;
102 double max = 0;
103 for (double value : values)
104 if (value > max)
105 max = value;
106 list.clear();
107 try {
108
109 } catch (Exception e) {
110 e.printStackTrace();
111 }
112 }
113 fireDatasetChanged();
114 }
115
116 public void setValue(IChartKey key, Integer value) {
117
118 }
119
120 public void removeAll() {
121
122 }
123
124 private final IDataProvider provider;
125
126 private final ChartFilter filter;
127
128 }