1 33 34 package com.icesoft.icefaces.samples.showcase.components.charts; 35 36 import com.icesoft.faces.component.outputchart.OutputChart; 37 import com.icesoft.faces.context.effects.Effect; 38 import com.icesoft.faces.context.effects.Highlight; 39 40 import java.awt.*; 41 import java.util.ArrayList ; 42 import java.util.Iterator ; 43 import java.util.List ; 44 import java.util.Map ; 45 46 52 public class PieChartBean extends Chart { 53 54 protected static List labels = new ArrayList (); 56 57 protected static List data = new ArrayList (); 59 60 private List paints; 62 63 private static List allSales = new ArrayList (); 65 66 private static final List sales = buildSales(); 68 69 private static Map salesMap; 71 72 private static String clickedAreaValue = ChartMediator.DEFAULT_STRING; 74 75 private String label; 77 78 private float value; 79 80 public static boolean is3D = false; 82 83 private boolean pieNeedsRendering = false; 85 86 private Color selectedColor; 88 89 private static Effect effectOutputText = new Highlight("#ffff99"); 91 92 int deletInex = 0; 94 95 private List deleteList = new ArrayList (); 97 98 99 100 101 public PieChartBean() { 102 super(); 103 paints = new ArrayList (); 104 paints.add(new Color(26, 86, 138)); paints.add(new Color(76, 126, 167)); paints.add(new Color(148, 179, 203)); paints.add(new Color(193, 211, 223)); } 109 110 111 112 113 119 public static List buildSales() { 120 ArrayList salesTemp = new ArrayList (); 121 122 salesMap = Sales.getSales(); 123 124 Iterator it = salesMap.values().iterator(); 125 double price; 126 String label; 127 while (it.hasNext()) { 128 129 Sales[] yearSale = (Sales[]) it.next(); 130 price = 0; 131 label = ""; 132 for (int i = 0; i < yearSale.length; i++) { 133 price += (yearSale[i]).getPrice(); 134 label = (yearSale[i]).getYear(); 135 salesTemp.add(yearSale[i]); 136 allSales.add(yearSale[i]); 137 138 } 139 labels.add(label); 140 data.add(new Double (price)); 141 142 } 143 return salesTemp; 144 } 145 146 147 155 public boolean renderOnSubmit(OutputChart component) { 156 if (pieNeedsRendering) { 157 pieNeedsRendering = false; 158 return true; 159 } else { 160 return false; 161 } 162 } 163 164 public static void setIs3D(boolean i3D) { 165 is3D = i3D; 166 } 167 168 173 public static boolean is3D() { 174 return is3D; 175 } 176 177 178 public String getLabel() { 179 return label; 180 } 181 182 public void setLabel(String label) { 183 if (null == label || label.length() < 1) { 184 label = " "; 185 } 186 this.label = label; 187 } 188 189 public float getValue() { 190 return value; 191 } 192 193 public void setValue(float value) { 194 this.value = value; 195 } 196 197 198 public String getClickedAreaValue() { 199 return clickedAreaValue; 200 } 201 202 public void setClickedAreaValue(String clickedAreaValue) { 203 PieChartBean.clickedAreaValue = clickedAreaValue; 204 } 205 206 207 public Effect getEffectOutputText() { 208 return effectOutputText; 209 } 210 211 public void setEffectOutputText(Effect effectOutputText) { 212 PieChartBean.effectOutputText = effectOutputText; 213 } 214 215 216 222 public static void setSalesForYear(String year) { 223 sales.clear(); 224 Sales[] yearSales = (Sales[]) salesMap.get(year); 225 for (int i = 0; i < yearSales.length; i++) { 226 sales.add(yearSales[i]); 227 } 228 } 229 230 public List getSales() { 231 return type.equalsIgnoreCase("pie3d") ? allSales : sales; 232 } 233 234 235 public List getData() { 236 return data; 237 } 238 239 public List getLabels() { 240 return labels; 241 } 242 243 public List getPaints() { 244 return paints; 245 } 246 247 public void setPaints(List paints) { 248 this.paints = paints; 249 } 250 } 251 | Popular Tags |