1 33 34 43 44 package com.icesoft.icefaces.samples.showcase.components.charts; 45 46 47 import java.awt.Color ; 48 import java.util.ArrayList ; 49 import java.util.Arrays ; 50 import java.util.List ; 51 52 import com.icesoft.faces.component.outputchart.OutputChart; 53 import com.icesoft.faces.context.effects.Effect; 54 import com.icesoft.faces.context.effects.Highlight; 55 56 import javax.faces.event.ActionEvent; 57 import javax.faces.event.ValueChangeEvent; 58 import javax.faces.model.SelectItem; 59 60 67 public class ChartMediator { 68 69 private static final List areaPaints = 70 new ArrayList (Arrays.asList(new Color []{new Color (26, 86, 138), 71 new Color (76, 126, 167), 72 new Color (148, 179, 203)})); 73 74 private static SelectItem[] chartList = new SelectItem[]{ 76 new SelectItem(OutputChart.AREA_CHART_TYPE), 77 new SelectItem(OutputChart.AREA_STACKED_CHART_TYPE), 78 new SelectItem(OutputChart.BAR_CHART_TYPE), 79 new SelectItem(OutputChart.BAR_CLUSTERED_CHART_TYPE), 80 new SelectItem(OutputChart.BAR_STACKED_CHART_TYPE), 81 new SelectItem(OutputChart.LINE_CHART_TYPE), 82 new SelectItem(OutputChart.POINT_CHART_TYPE), 83 new SelectItem(OutputChart.PIE2D_CHART_TYPE), 84 new SelectItem(OutputChart.PIE3D_CHART_TYPE),}; 85 86 87 private boolean pie = false; 89 90 91 92 private boolean axis = true; 94 95 public boolean pie3D = false; 97 98 private boolean chartChangedFlag = true; 100 101 private String wasChanged; 103 104 public static final String DEFAULT_STRING = 105 "Click on the image map below to display a chart value: "; 106 107 private Highlight effectOutputText = new Highlight("#ffff99"); 109 110 private String chart = OutputChart.BAR_CHART_TYPE; 112 113 public Chart chartObject = new Chart(chart); 114 115 private String clickedValue = DEFAULT_STRING; 117 118 private boolean horizontal = false; 120 121 private boolean orientationChange = true; 123 124 private String titleX = "Years"; 126 127 private String titleY = "Problems"; 129 130 131 135 public SelectItem[] getChartList() { 136 return chartList; 137 } 138 139 143 public boolean isAxis() { 144 return axis; 145 } 146 147 151 public boolean isPie3D() { 152 return pie3D; 153 } 154 155 159 public void setPie3D(boolean pie3D) { 160 this.pie3D = pie3D; 161 } 162 163 167 public boolean isPie() { 168 return pie; 169 } 170 171 175 public void setAxis(boolean axis) { 176 this.axis = axis; 177 } 178 179 183 public void setPie(boolean pie) { 184 this.pie = pie; 185 } 186 187 188 192 public String getChart() { 193 194 return chart; 195 } 196 197 198 203 public void setChart(String chart) { 204 205 if (wasChanged != null) { 206 this.chart = wasChanged; 207 wasChanged = null; 208 } else { 209 this.chart = chart; 210 } 211 212 chartObject.setType(chart); 213 214 if (!chart.equals(OutputChart.PIE3D_CHART_TYPE)) { 215 pie3D = false; 216 217 } 218 if (chart.equals(OutputChart.PIE3D_CHART_TYPE) || 219 chart.equals(OutputChart.PIE2D_CHART_TYPE)) { 220 axis = false; 221 222 if (chart.equals(OutputChart.PIE3D_CHART_TYPE)) { 223 pie3D = true; 224 225 226 } 227 } else { 228 axis = true; 229 } 230 231 } 232 233 237 public boolean allCharts(OutputChart component) { 238 239 if (chartChangedFlag) { 240 chartChangedFlag = false; 241 return true; 242 } else { 243 return chartChangedFlag; 244 } 245 } 246 247 248 253 public void chartChanged(ValueChangeEvent event) { 254 chartChangedFlag = true; 255 wasChanged = (String ) event.getNewValue(); 256 257 if (event.getNewValue().equals(OutputChart.AREA_CHART_TYPE) || 258 event.getNewValue().equals(OutputChart.AREA_STACKED_CHART_TYPE)) { 259 setClickedValue( 260 "A client side image map is not supported for Area charts " + 261 "(clicking on the chart will not display any values)"); 262 } else { 263 setClickedValue(DEFAULT_STRING); 264 } 265 if(event.getNewValue().equals(OutputChart.BAR_CHART_TYPE) || 267 event.getNewValue().equals(OutputChart.BAR_CLUSTERED_CHART_TYPE)){ 268 orientationChange = true; 269 if(horizontal == true){ 270 titleX = "Problems"; 272 titleY = "Years"; 273 } 274 } 275 else { 276 orientationChange = false; 277 titleX = "Years"; 279 titleY = "Problems"; 280 } 281 282 } 283 284 285 289 public String getClickedValue() { 290 291 return clickedValue; 292 } 293 294 public Chart getChartObject(){ 295 return chartObject; 296 } 297 301 public Effect getEffectOutputText() { 302 return effectOutputText; 303 } 304 305 309 public void setEffectOutputText(Effect effectOutputText) { 310 this.effectOutputText = (Highlight) effectOutputText; 311 } 312 313 317 public void setClickedValue(String clickedValue) { 318 319 this.clickedValue = clickedValue; 320 } 321 322 326 public void imageClicked(ActionEvent event) { 327 328 if (event.getSource() instanceof OutputChart) { 329 OutputChart chart = (OutputChart) event.getSource(); 330 if (chart.getClickedImageMapArea().getXAxisLabel() != null) { 331 332 setClickedValue(DEFAULT_STRING + 333 chart.getClickedImageMapArea() 334 .getXAxisLabel() + 335 " : " + chart.getClickedImageMapArea() 336 .getValue()); 337 338 effectOutputText.setFired(false); 339 } 340 341 } 342 343 } 344 345 public void pieAction(ActionEvent event) { 346 347 if (event.getSource() instanceof OutputChart) { 348 OutputChart chart = (OutputChart) event.getSource(); 349 if (chart.getClickedImageMapArea().getLengendLabel() != null) { 350 setClickedValue(DEFAULT_STRING + chart 351 .getClickedImageMapArea().getLengendLabel() 352 + " : " + 353 chart.getClickedImageMapArea().getValue()); 354 PieChartBean.setSalesForYear( 355 chart.getClickedImageMapArea().getLengendLabel()); 356 effectOutputText.setFired(false); 357 358 359 } 360 } 361 362 } 363 370 public void setHorizontal(boolean horizontal){ 371 this.horizontal = horizontal; 372 } 373 374 379 public boolean getHorizontal(){ 380 return horizontal; 381 } 382 383 390 public boolean getOrientationChange() { 391 return orientationChange; 392 } 393 394 400 public void setOrientationChange(boolean orientationChange) { 401 this.orientationChange = orientationChange; 402 } 403 404 409 public void selectOrientation(ValueChangeEvent event){ 410 String temp = titleX; 411 if(event.getNewValue().equals("true")){ 412 horizontal = true; 414 titleX = titleY; 415 titleY = temp; 416 } 417 else{ 418 horizontal = false; 420 titleX = titleY; 421 titleY = temp; 422 } 423 chartChangedFlag = true; 425 } 426 427 432 public String getTitleX(){ 433 return titleX; 434 } 435 436 441 public void setTitleX(String titleX){ 442 this.titleX = titleX; 443 } 444 445 450 public String getTitleY(){ 451 return titleY; 452 } 453 454 459 public void setTitleY(String titleY){ 460 this.titleY = titleY; 461 } 462 463 public List getAreaPaints() { 464 return areaPaints; 465 } 466 } 467 | Popular Tags |