01: /* SimplePieModel.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Aug 14 11:20:14 2006, Created by henrichen
10: }}IS_NOTE
11:
12: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul;
20:
21: import org.zkoss.lang.Objects;
22: import org.zkoss.zul.event.ChartDataEvent;
23: import org.zkoss.zul.event.ChartDataListener;
24:
25: import java.util.Map;
26: import java.util.List;
27: import java.util.HashMap;
28: import java.util.Iterator;
29: import java.util.ArrayList;
30: import java.util.Collection;
31:
32: /**
33: * A Pie chart data model implementation of {@link PieModel}.
34: * Piechart model is an one series of (Category, value) data objects.
35: *
36: * @author henrichen
37: * @see PieModel
38: * @see Chart
39: */
40: public class SimplePieModel extends AbstractChartModel implements
41: PieModel {
42: private List _categoryList = new ArrayList(13);
43: private Map _categoryMap = new HashMap(13);
44:
45: //-- PieModel --//
46: public Comparable getCategory(int index) {
47: return (Comparable) _categoryList.get(index);
48: }
49:
50: public Collection getCategories() {
51: return _categoryList;
52: }
53:
54: public Number getValue(Comparable category) {
55: return (Number) _categoryMap.get(category);
56: }
57:
58: public void setValue(Comparable category, Number value) {
59: if (!_categoryMap.containsKey(category)) {
60: _categoryList.add(category);
61: } else {
62: Number ovalue = (Number) _categoryMap.get(category);
63: if (Objects.equals(ovalue, value)) {
64: return;
65: }
66: }
67: _categoryMap.put(category, value);
68: fireEvent(ChartDataEvent.CHANGED, null, category);
69: }
70:
71: public void removeValue(Comparable category) {
72: _categoryMap.remove(category);
73: _categoryList.remove(category);
74: fireEvent(ChartDataEvent.REMOVED, null, category);
75: }
76:
77: public void clear() {
78: _categoryMap.clear();
79: _categoryList.clear();
80: fireEvent(ChartDataEvent.REMOVED, null, null);
81: }
82: }
|