1 33 34 43 44 package com.icesoft.icefaces.samples.showcase.components.charts; 45 46 47 import com.icesoft.faces.component.outputchart.OutputChart; 48 import com.icesoft.faces.context.effects.Effect; 49 import com.icesoft.faces.context.effects.Highlight; 50 51 import javax.faces.event.ActionEvent; 52 import javax.faces.event.ValueChangeEvent; 53 import javax.faces.model.SelectItem; 54 55 62 public class ChartFactory { 63 64 private static SelectItem[] chartList = new SelectItem[]{ 66 new SelectItem(OutputChart.AREA_CHART_TYPE), 67 new SelectItem(OutputChart.AREA_STACKED_CHART_TYPE), 68 new SelectItem(OutputChart.BAR_CHART_TYPE), 69 new SelectItem(OutputChart.BAR_CLUSTERED_CHART_TYPE), 70 new SelectItem(OutputChart.BAR_STACKED_CHART_TYPE), 71 new SelectItem(OutputChart.LINE_CHART_TYPE), 72 new SelectItem(OutputChart.POINT_CHART_TYPE), 73 new SelectItem(OutputChart.PIE2D_CHART_TYPE), 74 new SelectItem(OutputChart.PIE3D_CHART_TYPE),}; 75 76 77 private boolean pie = false; 79 80 81 82 private boolean axis = true; 84 85 public boolean pie3D = false; 87 88 private boolean chartChangedFlag = true; 90 91 private String wasChanged; 93 94 public static final String DEFAULT_STRING = 95 "Click on the image map below to display a chart value: "; 96 97 private Highlight effectOutputText = new Highlight("#ffff99"); 99 100 private static String chart = OutputChart.BAR_CHART_TYPE; 102 103 public static Chart chartObject = new Chart(chart); 104 105 private String clickedValue = DEFAULT_STRING; 107 108 112 public SelectItem[] getChartList() { 113 return chartList; 114 } 115 116 120 public boolean isAxis() { 121 return axis; 122 } 123 124 128 public boolean isPie3D() { 129 return pie3D; 130 } 131 132 136 public void setPie3D(boolean pie3D) { 137 this.pie3D = pie3D; 138 } 139 140 144 public boolean isPie() { 145 return pie; 146 } 147 148 152 public void setAxis(boolean axis) { 153 this.axis = axis; 154 } 155 156 160 public void setPie(boolean pie) { 161 this.pie = pie; 162 } 163 164 165 169 public String getChart() { 170 171 return chart; 172 } 173 174 175 176 181 public void setChart(String chart) { 182 183 if (wasChanged != null) { 184 this.chart = wasChanged; 185 wasChanged = null; 186 } else { 187 this.chart = chart; 188 } 189 190 chartObject.setType(chart); 191 192 193 194 if (!chart.equals(OutputChart.PIE3D_CHART_TYPE)) { 195 pie3D = false; 196 197 } 198 if (chart.equals(OutputChart.PIE3D_CHART_TYPE) || 199 chart.equals(OutputChart.PIE2D_CHART_TYPE)) { 200 axis = false; 201 202 if (chart.equals(OutputChart.PIE3D_CHART_TYPE)) { 203 pie3D = true; 204 205 206 } 207 } else { 208 axis = true; 209 } 210 211 } 212 213 217 public boolean allCharts(OutputChart component) { 218 219 if (chartChangedFlag) { 220 chartChangedFlag = false; 221 return true; 222 } else { 223 return chartChangedFlag; 224 } 225 } 226 227 228 233 public void chartChanged(ValueChangeEvent event) { 234 235 chartChangedFlag = true; 236 wasChanged = (String ) event.getNewValue(); 237 238 if (event.getNewValue().equals(OutputChart.AREA_CHART_TYPE) || 239 event.getNewValue().equals(OutputChart.AREA_STACKED_CHART_TYPE)) { 240 setClickedValue( 241 "A client side image map is not supported for Area charts " + 242 "(clicking on the chart will not display any values)"); 243 } else { 244 setClickedValue(DEFAULT_STRING); 245 } 246 } 247 248 249 253 public String getClickedValue() { 254 255 return clickedValue; 256 } 257 258 public Chart getChartObject(){ 259 return chartObject; 260 } 261 265 public Effect getEffectOutputText() { 266 return effectOutputText; 267 } 268 269 273 public void setEffectOutputText(Effect effectOutputText) { 274 this.effectOutputText = (Highlight) effectOutputText; 275 } 276 277 281 public void setClickedValue(String clickedValue) { 282 283 this.clickedValue = clickedValue; 284 } 285 286 290 public void imageClicked(ActionEvent event) { 291 292 if (event.getSource() instanceof OutputChart) { 293 OutputChart chart = (OutputChart) event.getSource(); 294 if (chart.getClickedImageMapArea().getXAxisLabel() != null) { 295 296 setClickedValue(DEFAULT_STRING + 297 chart.getClickedImageMapArea() 298 .getXAxisLabel() + 299 " : " + chart.getClickedImageMapArea() 300 .getValue()); 301 302 effectOutputText.setFired(false); 303 } 304 305 } 306 307 } 308 309 public void pieAction(ActionEvent event) 310 { 311 312 if (event.getSource() instanceof OutputChart) { 313 OutputChart chart = (OutputChart) event.getSource(); 314 if (chart.getClickedImageMapArea().getLengendLabel() != null) { 315 setClickedValue(DEFAULT_STRING + chart 316 .getClickedImageMapArea().getLengendLabel() 317 + " : " + 318 chart.getClickedImageMapArea().getValue()); 319 PieChartBean.setSalesForYear( 320 chart.getClickedImageMapArea().getLengendLabel()); 321 effectOutputText.setFired(false); 322 323 324 } 325 } 326 327 } 328 329 } 330 | Popular Tags |