KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > chart > EnhancedChartComponent


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.chart;
21
22 import com.tonbeller.jpivot.chart.ChartComponent;
23 import com.tonbeller.jpivot.core.ModelChangeEvent;
24 import com.tonbeller.jpivot.core.ModelChangeListener;
25 import com.tonbeller.jpivot.olap.model.Cell;
26 import com.tonbeller.jpivot.olap.model.OlapException;
27 import com.tonbeller.jpivot.olap.model.OlapModel;
28 import com.tonbeller.jpivot.olap.model.Result;
29 import com.tonbeller.jpivot.olap.navi.DrillThrough;
30
31 import com.tonbeller.wcf.component.Component;
32 import com.tonbeller.wcf.controller.Dispatcher;
33 import com.tonbeller.wcf.controller.DispatcherSupport;
34 import com.tonbeller.wcf.controller.RequestContext;
35 import com.tonbeller.wcf.controller.RequestListener;
36 import com.tonbeller.wcf.table.ITableComponent;
37 import com.tonbeller.wcf.table.TableModel;
38 import com.tonbeller.wcf.utils.DomUtils;
39 import com.tonbeller.wcf.utils.XmlUtils;
40
41 import org.apache.log4j.Logger;
42
43 import org.jfree.chart.ChartRenderingInfo;
44 import org.jfree.chart.JFreeChart;
45 import org.jfree.chart.Legend;
46 import org.jfree.chart.StandardLegend;
47 import org.jfree.chart.axis.DateAxis;
48 import org.jfree.chart.entity.ChartEntity;
49 import org.jfree.chart.entity.EntityCollection;
50 import org.jfree.chart.entity.StandardEntityCollection;
51 import org.jfree.chart.plot.PlotOrientation;
52 import org.jfree.chart.plot.XYPlot;
53 import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
54 import org.jfree.chart.renderer.xy.XYItemRenderer;
55 import org.jfree.chart.servlet.ServletUtilities;
56 import org.jfree.chart.title.Title;
57 import org.jfree.chart.urls.CategoryURLGenerator;
58 import org.jfree.chart.urls.StandardCategoryURLGenerator;
59 import org.jfree.chart.urls.StandardPieURLGenerator;
60
61 import org.jfree.data.category.CategoryDataset;
62 import org.jfree.data.category.DefaultCategoryDataset;
63 import org.jfree.data.general.PieDataset;
64 import org.jfree.data.xy.XYDataset;
65
66 import org.jfree.ui.Spacer;
67
68 import org.jfree.util.TableOrder;
69
70 import org.openi.xmla.DatasetAdapter;
71
72 import org.w3c.dom.Document JavaDoc;
73 import org.w3c.dom.Element JavaDoc;
74
75 import java.awt.Color JavaDoc;
76 import java.awt.Font JavaDoc;
77 import java.awt.Paint JavaDoc;
78
79 import java.io.ByteArrayInputStream JavaDoc;
80 import java.io.InputStream JavaDoc;
81
82 import java.text.SimpleDateFormat JavaDoc;
83
84 import java.util.Iterator JavaDoc;
85 import java.util.List JavaDoc;
86 import java.util.Locale JavaDoc;
87
88 import javax.servlet.http.HttpSession JavaDoc;
89
90 import javax.xml.parsers.DocumentBuilder JavaDoc;
91
92
93 /**
94  * Started as an exact copy of com.tonbeller.jpivot.chart.ChartComponent. Needed
95  * to enhance the render functionality to handle different series colors and palettes.
96  * There was no way to overload, override that functionality without copying a significant amount
97  * of the class, so here is a complete copy. Will likely evolve into something quite different.
98  */

99 public class EnhancedChartComponent extends ChartComponent
100     implements ModelChangeListener {
101     private static Logger logger = Logger.getLogger(EnhancedChartComponent.class);
102     protected String JavaDoc ref;
103     protected Document JavaDoc document;
104     protected OlapModel olapModel;
105     protected boolean dirty = true;
106     protected Locale JavaDoc locale;
107
108     // protected Result result;
109
// protected Iterator cellIterator;
110
// protected int dimCount;
111
protected Element JavaDoc rootElement;
112     protected int colCount;
113
114     // servlet mapping - optionally can be set as a servlet context parameter
115
// with name "chartServlet"
116
// for example:
117
protected String JavaDoc CHART_SERVLET = "/DisplayChart";
118     final String JavaDoc CHART_SERVLET_KEY = "chartServlet";
119     protected String JavaDoc filename = null;
120
121     // chart properties
122
public static final int DEFAULT_CHART_WIDTH = 500;
123     public static final int DEFAULT_CHART_HEIGHT = 300;
124     final static double DEFAULT_LEGEND_WIDTH = 100.0;
125     protected String JavaDoc chartTitle = "";
126     protected java.awt.Font JavaDoc titleFont = JFreeChart.DEFAULT_TITLE_FONT;
127     protected String JavaDoc fontName = "SansSerif";
128     protected int fontStyle = java.awt.Font.BOLD;
129     protected int fontSize = 18;
130     protected String JavaDoc slicerFontName = "SansSerif";
131     protected int slicerFontStyle = java.awt.Font.PLAIN;
132     protected int slicerFontSize = 12;
133     protected String JavaDoc axisFontName = "SansSerif";
134     protected int axisFontStyle = java.awt.Font.PLAIN;
135     protected int axisFontSize = 12;
136     protected String JavaDoc axisTickFontName = "SansSerif";
137     protected int axisTickFontStyle = java.awt.Font.PLAIN;
138     protected int axisTickFontSize = 10;
139     protected String JavaDoc legendFontName = "SansSerif";
140     protected int legendFontStyle = java.awt.Font.PLAIN;
141     protected int legendFontSize = 10;
142     protected int legendPosition = Legend.EAST;
143     protected int slicerPosition = Title.BOTTOM;
144     protected int slicerAlignment = Title.CENTER;
145
146     //java.awt.Color bgColor = java.awt.Color.white;
147
protected int bgColorR = 255;
148     protected int bgColorG = 255;
149     protected int bgColorB = 255;
150     protected int chartType = 1;
151     protected int chartHeight = DEFAULT_CHART_HEIGHT;
152     protected int chartWidth = DEFAULT_CHART_WIDTH;
153     protected String JavaDoc horizAxisLabel = "";
154     protected String JavaDoc vertAxisLabel = "";
155     protected boolean showLegend = true;
156     protected boolean showSlicer = true;
157     protected boolean showTooltips = true;
158     protected boolean drillThroughEnabled = true;
159     protected int tickLabelRotate = 30; //default 30 degree rotation
160
protected ChartRenderingInfo info = null;
161     protected Dispatcher dispatcher = new DispatcherSupport();
162     protected List JavaDoc colorPalette;
163
164     /*As there is no float type formatter in com.tonbeller.wcf.format.BasicTypes class, making
165        foregroundAlpha as double type. But in library, this field of float type. So need to cast into
166        float type while setting foreground alpha for chart.
167      */

168     protected double foregroundAlpha = 1.0;
169     protected boolean showPareto = false;
170     protected boolean useChartSize = false; // chart size based on saved width and height.
171
private boolean rangeIsPercentage = true;
172     private boolean rangeIsCurrency = true;
173     private boolean rangeIsDefault = true;
174     private boolean writeImageMap = true;
175
176     /**
177      * Constructor
178      * @param id the id of this component
179      * @param ref a reference to an olap model
180      */

181     public EnhancedChartComponent(String JavaDoc id, Component parent, String JavaDoc ref,
182         RequestContext context) {
183         super(id, parent, ref, context);
184         this.ref = ref;
185         this.olapModel = (OlapModel) context.getModelReference(ref);
186         this.olapModel.addModelChangeListener(this);
187         this.locale = context.getLocale();
188
189         // extend the controller
190
getDispatcher().addRequestListener(null, null, dispatcher);
191
192         // optional servlet context parameter for chart servlet location
193
String JavaDoc chartServlet = context.getServletContext()
194                                      .getInitParameter(CHART_SERVLET_KEY);
195
196         if (chartServlet != null) {
197             this.CHART_SERVLET = chartServlet;
198         }
199     }
200
201     /**
202      * called once by the creating tag
203      */

204     public void initialize(RequestContext context) throws Exception JavaDoc {
205         super.initialize(context);
206     }
207
208     /**
209      * Entry point for producing charts, called by wcf render tag.
210      * Produces a jfreechart dataset from olap model, then creates a chart and
211      * writes it to the servlet container temp directory.
212      * Returns a DOM document for Renderer to transform into html.
213      * Requires that jfreechart servlet is installed in this application context.
214      */

215     public Document JavaDoc render(RequestContext context) throws Exception JavaDoc {
216         // check if we need to produce a new chart
217
if (dirty) {
218             // clear old listeners
219
dispatcher.clear();
220             // this.result = olapModel.getResult();
221
// this.cellIterator = result.getCells().iterator();
222
// this.dimCount = result.getAxes().length;
223
rangeIsPercentage = false;
224             rangeIsCurrency = false;
225             rangeIsDefault = false;
226
227             
228             // re-set dirty flag
229
dirty = false;
230
231             //set X/Y Axis Label
232
try {
233                 logger.debug("trying to build axis labels");
234
235                 AxisLabelGenerator axisLabeller = new AxisLabelGenerator();
236                 this.setHorizAxisLabel(axisLabeller.getHorizAxisLabel(
237                         this.getOlapModel()));
238                 this.setVertAxisLabel(axisLabeller.getVertAxisLabel(
239                         this.getOlapModel()));
240             } catch (Exception JavaDoc e) {
241                 logger.error("Error generating axis label:\n" + e);
242             }
243             // DefaultCategoryDataset dataset = new DatasetAdapter().buildCategoryDataset(this.getOlapModel());
244

245             JFreeChart chart = EnhancedChartFactory.createChart(olapModel,
246                     chartType, chartTitle,
247                 horizAxisLabel, vertAxisLabel,
248                 showLegend, showTooltips,
249                 drillThroughEnabled, titleFont,
250                 new Color JavaDoc(this.getBgColorR(), this.getBgColorG(), this.getBgColorB()),
251                 new Font JavaDoc(this.getSlicerFontName(), this.getSlicerFontStyle(), this.getSlicerFontSize()),
252                 new Font JavaDoc(this.getAxisFontName(), this.getAxisFontStyle(), this.getAxisFontSize()),
253                 new Font JavaDoc(this.getAxisTickFontName(), this.getAxisTickFontStyle(), this.getAxisTickFontSize()),
254                 new Font JavaDoc(this.getLegendFontName(), this.getLegendFontStyle(), this.getLegendFontSize()),
255                 legendPosition,
256                 tickLabelRotate,
257                 1.0f,
258                 showSlicer,
259                 slicerPosition,
260                 slicerAlignment,
261                 showPareto, this.getLocale());
262
263             try {
264                 /*
265                 ChartCustomizer customizer = new ChartCustomizer();
266                 customizer.customizeChart(this, dataset, chart);
267 */

268                 
269                 
270                 info = new ChartRenderingInfo(new StandardEntityCollection());
271
272                 // Write the chart image to the temporary directory
273
HttpSession JavaDoc session = context.getSession();
274                 filename = ServletUtilities.saveChartAsPNG(chart, chartWidth,
275                         chartHeight, info, session);
276             } catch (Exception JavaDoc e) {
277                 logger.error(e);
278                 filename = "public_error_500x300.png";
279                 dirty = true;
280             }
281         }
282
283         // new DOM document
284
DocumentBuilder JavaDoc parser = XmlUtils.getParser();
285
286         // get an image map for the chart, wrap it in xchart tags
287
// temporarily commenting out - with our < chars, breaks with a SAXException
288
String JavaDoc xchart = null;
289
290         // see org.jfree.chart.ChartUtilities.writeImageMap(..)
291
if (this.getWriteImageMap()) {
292             xchart = "<xchart>" + writeImageMap(filename, info, false) +
293                 "</xchart>";
294         } else {
295             xchart = "<xchart/>";
296         }
297
298         // create an InputStream from the DOM document
299
InputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(xchart.getBytes("UTF-8"));
300
301         document = parser.parse(stream);
302
303         Element JavaDoc root = document.getDocumentElement();
304
305         // create url for img tag
306
String JavaDoc graphURL = context.getRequest().getContextPath() +
307             CHART_SERVLET + "?filename=" + filename;
308         Element JavaDoc img = document.createElement("img");
309         img.setAttribute("src", graphURL);
310         img.setAttribute("width", new Integer JavaDoc(chartWidth).toString());
311         img.setAttribute("height", new Integer JavaDoc(chartHeight).toString());
312         img.setAttribute("style", "border:0;");
313         img.setAttribute("usemap", "#" + filename);
314         root.appendChild(img);
315
316         return document;
317     }
318
319     
320
321     
322
323     /**
324      * Writes an image map as a String
325      * This function has been requested to be added to jfreechart
326      * Also requires slight change to ChartEntity.getImageMapAreaTag()
327      * to produce valid xml tag and use &amp; entity in urls.
328      * Diffs sent to jfreechart project - so hopefully this will be in there soon
329      *
330      * @param name the map name.
331      * @param info the chart rendering info.
332      * @param useOverLibForToolTips whether to use OverLIB for tooltips
333      * (http://www.bosrup.com/web/overlib/).
334      */

335     public String JavaDoc writeImageMap(String JavaDoc name, ChartRenderingInfo info,
336         boolean useOverLibForToolTips) {
337         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
338         sb.append("<map name=\"" + name + "\">");
339
340         EntityCollection entities = info.getEntityCollection();
341         Iterator JavaDoc iterator = entities.iterator();
342
343         while (iterator.hasNext()) {
344             ChartEntity entity = (ChartEntity) iterator.next();
345
346             // the tag returned by getImageMapAreaTag is not valid xml
347
//String area = entity.getImageMapAreaTag(useOverLibForToolTips);
348
String JavaDoc area = "";
349
350             // logger.debug("useOverLibForToolTips=" + useOverLibForToolTips);
351
if (useOverLibForToolTips) {
352                 area = entity.getImageMapAreaTag(new org.jfree.chart.imagemap.OverLIBToolTipTagFragmentGenerator(),
353                         new org.jfree.chart.imagemap.StandardURLTagFragmentGenerator());
354             } else {
355                 area = entity.getImageMapAreaTag(new org.jfree.chart.imagemap.StandardToolTipTagFragmentGenerator(),
356                         new org.jfree.chart.imagemap.StandardURLTagFragmentGenerator());
357             }
358
359             // modify to valid xml tag
360
area = area.replaceAll("&", "&amp;");
361
362             //area = area.toLowerCase();
363
area = area.replaceAll(">$", "/>");
364
365             // can't do this one, b/c the image map will not work (just displays as html)
366
// area = area.replaceAll("<", "&lt;");
367
if (area.length() > 0) {
368                 sb.append(area);
369             }
370         }
371
372         sb.append("</map>");
373
374         return sb.toString();
375     }
376
377     /**
378      * @return
379      */

380     public int getColCount() {
381         return colCount;
382     }
383
384     /**
385      * true means that render() will create a new chart
386      */

387     public boolean isDirty() {
388         return dirty;
389     }
390
391     public void setDirty(boolean dirty) {
392         this.dirty = dirty;
393     }
394
395     public void modelChanged(ModelChangeEvent e) {
396         this.dirty = true;
397     }
398
399     public void structureChanged(ModelChangeEvent e) {
400         this.dirty = true;
401     }
402
403     /**
404      * @return
405      */

406     public int getChartHeight() {
407         return chartHeight;
408     }
409
410     /**
411      * @param chartHeight
412      */

413     public void setChartHeight(int chartHeight) {
414         this.chartHeight = chartHeight;
415         this.dirty = true;
416     }
417
418     /**
419      * @return
420      */

421     public String JavaDoc getChartTitle() {
422         return chartTitle;
423     }
424
425     /**
426      * @param chartTitle
427      */

428     public void setChartTitle(String JavaDoc chartTitle) {
429         this.chartTitle = chartTitle;
430         this.dirty = true;
431     }
432
433     /**
434      * @return
435      */

436     public int getChartType() {
437         return chartType;
438     }
439
440     /**
441      * @param chartType
442      */

443     public void setChartType(int chartType) {
444         this.chartType = chartType;
445         this.dirty = true;
446     }
447
448     /**
449      * @return
450      */

451     public int getChartWidth() {
452         return chartWidth;
453     }
454
455     /**
456      * @param chartWidth
457      */

458     public void setChartWidth(int chartWidth) {
459         this.chartWidth = chartWidth;
460         this.dirty = true;
461     }
462
463     /**
464      * @return
465      */

466     public String JavaDoc getHorizAxisLabel() {
467         return horizAxisLabel;
468     }
469
470     /**
471      * @param axisLabel
472      */

473     public void setHorizAxisLabel(String JavaDoc axisLabel) {
474         horizAxisLabel = axisLabel;
475         this.dirty = true;
476     }
477
478     /**
479      * @return
480      */

481     public boolean getShowLegend() {
482         return showLegend;
483     }
484
485     /**
486      * @param showLegend
487      */

488     public void setShowLegend(boolean showLegend) {
489         this.showLegend = showLegend;
490         this.dirty = true;
491     }
492
493     /**
494      * @return
495      */

496     public String JavaDoc getFontName() {
497         return fontName;
498     }
499
500     /**
501      * @param titleFont
502      */

503     public void setFontName(String JavaDoc fontname) {
504         this.fontName = fontname;
505         this.dirty = true;
506     }
507
508     /**
509      * @return
510      */

511     public String JavaDoc getVertAxisLabel() {
512         return vertAxisLabel;
513     }
514
515     /**
516      * @param axisLabel
517      */

518     public void setVertAxisLabel(String JavaDoc axisLabel) {
519         vertAxisLabel = axisLabel;
520         this.dirty = true;
521     }
522
523     /**
524      * @return
525      */

526     public int getFontSize() {
527         return fontSize;
528     }
529
530     /**
531      * @param fontSize
532      */

533     public void setFontSize(int fontSize) {
534         this.fontSize = fontSize;
535         this.dirty = true;
536     }
537
538     /**
539      * @return
540      */

541     public int getFontStyle() {
542         return fontStyle;
543     }
544
545     /**
546      * @param fontStyle
547      */

548     public void setFontStyle(int fontStyle) {
549         this.fontStyle = fontStyle;
550         this.dirty = true;
551     }
552
553     /**
554      * @return
555      */

556     public int getBgColorB() {
557         return bgColorB;
558     }
559
560     /**
561      * @param bgColorB
562      */

563     public void setBgColorB(int bgColorB) {
564         this.bgColorB = checkRGB(bgColorB);
565         this.dirty = true;
566     }
567
568     /**
569      * @return
570      */

571     public int getBgColorG() {
572         return bgColorG;
573     }
574
575     /**
576      * @param bgColorG
577      */

578     public void setBgColorG(int bgColorG) {
579         this.bgColorG = checkRGB(bgColorG);
580         this.dirty = true;
581     }
582
583     /**
584      * @return
585      */

586     public int getBgColorR() {
587         return bgColorR;
588     }
589
590     /**
591      * @param bgColorR
592      */

593     public void setBgColorR(int bgColorR) {
594         this.bgColorR = checkRGB(bgColorR);
595         this.dirty = true;
596     }
597
598     /**
599      * Enforce limits of 0 - 255 for RGB values.
600      */

601     private int checkRGB(int v) {
602         if (v > 255) {
603             v = 255;
604         } else if (v < 0) {
605             v = 0;
606         }
607
608         return v;
609     }
610
611     protected boolean canDrillThrough(Cell cell) {
612         return ((DrillThrough) olapModel.getExtension(DrillThrough.ID)).canDrillThrough((Cell) cell.getRootDecoree());
613     }
614
615     /**
616      * returns a DrillThroughTableModel for the drill through
617      * @param cell
618      * @return
619      */

620     protected TableModel drillThrough(Cell cell) {
621         return ((DrillThrough) olapModel.getExtension(DrillThrough.ID)).drillThrough((Cell) cell.getRootDecoree());
622     }
623
624     public boolean isDrillThroughEnabled() {
625         return drillThroughEnabled;
626     }
627
628     public void setDrillThroughEnabled(boolean drillThroughEnabled) {
629         this.drillThroughEnabled = drillThroughEnabled;
630     }
631
632     /**
633      * @return
634      */

635     public String JavaDoc getAxisFontName() {
636         return axisFontName;
637     }
638
639     /**
640      * @param axisFontName
641      */

642     public void setAxisFontName(String JavaDoc axisFontName) {
643         this.axisFontName = axisFontName;
644     }
645
646     /**
647      * @return
648      */

649     public int getAxisFontSize() {
650         return axisFontSize;
651     }
652
653     /**
654      * @param axisFontSize
655      */

656     public void setAxisFontSize(int axisFontSize) {
657         this.axisFontSize = axisFontSize;
658     }
659
660     /**
661      * @return
662      */

663     public int getAxisFontStyle() {
664         return axisFontStyle;
665     }
666
667     /**
668      * @param axisFontStyle
669      */

670     public void setAxisFontStyle(int axisFontStyle) {
671         this.axisFontStyle = axisFontStyle;
672     }
673
674     /**
675      * @return
676      */

677     public String JavaDoc getLegendFontName() {
678         return legendFontName;
679     }
680
681     /**
682      * @param legendFontName
683      */

684     public void setLegendFontName(String JavaDoc legendFontName) {
685         this.legendFontName = legendFontName;
686     }
687
688     /**
689      * @return
690      */

691     public int getLegendFontSize() {
692         return legendFontSize;
693     }
694
695     /**
696      * @param legendFontSize
697      */

698     public void setLegendFontSize(int legendFontSize) {
699         this.legendFontSize = legendFontSize;
700     }
701
702     /**
703      * @return
704      */

705     public int getLegendFontStyle() {
706         return legendFontStyle;
707     }
708
709     /**
710      * @param legendFontStyle
711      */

712     public void setLegendFontStyle(int legendFontStyle) {
713         this.legendFontStyle = legendFontStyle;
714     }
715
716     /**
717      * @return
718      */

719     public int getSlicerAlignment() {
720         return slicerAlignment;
721     }
722
723     /**
724      * @param slicerAlignment
725      */

726     public void setSlicerAlignment(int slicerAlignment) {
727         this.slicerAlignment = slicerAlignment;
728     }
729
730     /**
731      * @return
732      */

733     public String JavaDoc getSlicerFontName() {
734         return slicerFontName;
735     }
736
737     /**
738      * @param slicerFontName
739      */

740     public void setSlicerFontName(String JavaDoc slicerFontName) {
741         this.slicerFontName = slicerFontName;
742     }
743
744     /**
745      * @return
746      */

747     public int getSlicerFontSize() {
748         return slicerFontSize;
749     }
750
751     /**
752      * @param slicerFontSize
753      */

754     public void setSlicerFontSize(int slicerFontSize) {
755         this.slicerFontSize = slicerFontSize;
756     }
757
758     /**
759      * @return
760      */

761     public int getSlicerFontStyle() {
762         return slicerFontStyle;
763     }
764
765     /**
766      * @param slicerFontStyle
767      */

768     public void setSlicerFontStyle(int slicerFontStyle) {
769         this.slicerFontStyle = slicerFontStyle;
770     }
771
772     /**
773      * @return
774      */

775     public int getSlicerPosition() {
776         return slicerPosition;
777     }
778
779     /**
780      * @param slicerPosition
781      */

782     public void setSlicerPosition(int slicerPosition) {
783         this.slicerPosition = slicerPosition;
784     }
785
786     /**
787      * @return
788      */

789     public int getLegendPosition() {
790         return legendPosition;
791     }
792
793     /**
794      * @param legendPosition
795      */

796     public void setLegendPosition(int legendPosition) {
797         this.legendPosition = legendPosition;
798     }
799
800     /**
801      * @return
802      */

803     public String JavaDoc getAxisTickFontName() {
804         return axisTickFontName;
805     }
806
807     /**
808      * @param axisTickFontName
809      */

810     public void setAxisTickFontName(String JavaDoc axisTickFontName) {
811         this.axisTickFontName = axisTickFontName;
812     }
813
814     /**
815      * @return
816      */

817     public int getAxisTickFontSize() {
818         return axisTickFontSize;
819     }
820
821     /**
822      * @param axisTickFontSize
823      */

824     public void setAxisTickFontSize(int axisTickFontSize) {
825         this.axisTickFontSize = axisTickFontSize;
826     }
827
828     /**
829      * @return
830      */

831     public int getAxisTickFontStyle() {
832         return axisTickFontStyle;
833     }
834
835     /**
836      * @param axisTickFontStyle
837      */

838     public void setAxisTickFontStyle(int axisTickFontStyle) {
839         this.axisTickFontStyle = axisTickFontStyle;
840     }
841
842     /**
843      * @return Returns the tickLabelRotate.
844      */

845     public int getTickLabelRotate() {
846         return tickLabelRotate;
847     }
848
849     /**
850      * @param tickLabelRotate The tickLabelRotate to set.
851      */

852     public void setTickLabelRotate(int tickLabelRotate) {
853         this.tickLabelRotate = tickLabelRotate;
854     }
855
856     /**
857      * @return
858      */

859     public boolean isShowSlicer() {
860         return showSlicer;
861     }
862
863     /**
864      * @param showSlicer
865      */

866     public void setShowSlicer(boolean showSlicer) {
867         this.showSlicer = showSlicer;
868     }
869
870     /**
871      * @return
872      */

873     public String JavaDoc getFilename() {
874         return filename;
875     }
876
877     /**
878      * @return Returns the colorPalette.
879      */

880     public List JavaDoc getColorPalette() {
881         return colorPalette;
882     }
883
884     /**
885      * @param colorPalette The colorPalette to set.
886      */

887     public void setColorPalette(List JavaDoc seriesPalette) {
888         this.colorPalette = seriesPalette;
889     }
890
891     /**
892      * @return Returns the generatePareto.
893      */

894     public boolean getShowPareto() {
895         return showPareto;
896     }
897
898     public double getForegroundAlpha() {
899         return foregroundAlpha;
900     }
901
902     public boolean isUseChartSize() {
903         return useChartSize;
904     }
905
906     /**
907      * @param generatePareto The generatePareto to set.
908      */

909     public void setShowPareto(boolean showPareto) {
910         this.showPareto = showPareto;
911     }
912
913     public void setForegroundAlpha(double foregroundAlpha) {
914         this.foregroundAlpha = foregroundAlpha;
915     }
916
917     public void setUseChartSize(boolean useChartSize) {
918         this.useChartSize = useChartSize;
919     }
920
921     /**
922      * @return Returns the writeImageMap.
923      */

924     public boolean getWriteImageMap() {
925         return writeImageMap;
926     }
927
928     /**
929      * @param writeImageMap The writeImageMap to set.
930      */

931     public void setWriteImageMap(boolean writeImageMap) {
932         this.writeImageMap = writeImageMap;
933     }
934
935     public OlapModel getOlapModel() {
936         return olapModel;
937     }
938
939     public void setOlapModel(OlapModel olapModel) {
940         this.olapModel = olapModel;
941     }
942
943     /**
944      * A URLGenerator class to generate pie urls that work with jpivot
945      * @author ati
946      *
947      */

948     public class jpivotPieURLGenerator extends StandardPieURLGenerator {
949         /** Prefix to the URL */
950         private String JavaDoc prefix = "";
951         private List JavaDoc cells = null;
952         private int rowCount;
953         private TableOrder order; // COLUMN or ROW - used to calculate cell Position
954

955         jpivotPieURLGenerator(Result result) {
956             cells = result.getCells();
957         }
958
959         jpivotPieURLGenerator(String JavaDoc prefix) {
960             this.prefix = prefix;
961         }
962
963         /*
964          * Use this constructor to set dataExtraction type (PER_COLUMN/PER_ROW), and allow for
965          * rowcount of current dataset (could be changed to just take rowCount)
966          */

967         jpivotPieURLGenerator(TableOrder order, DefaultCategoryDataset dataset) {
968             this.order = order;
969             this.rowCount = dataset.getRowCount();
970         }
971
972         /**
973          * Implementation of generateURL that integrates with jpivot/wcf framework.
974          * A request handler is added for each cell/item.
975          * No test is done to see if a cell is drillable, since the url has to added (I think, like an all or nothing ?)
976          * Generates a URL for a particular item within a series.
977          *
978          * @param data the dataset.
979          * @param key the data item key.
980          * @param pieIndex the index of the pie containing key (zero-based).
981          *
982          * @return the generated URL
983          */

984         public String JavaDoc generateURL(PieDataset data, Comparable JavaDoc key, int pieIndex) {
985             String JavaDoc url = prefix;
986             int index = data.getIndex(key);
987
988             int cellpos;
989
990             // if cells is null, initialize cells
991
if (cells == null) {
992                 try {
993                     cells = olapModel.getResult().getCells();
994                 } catch (Exception JavaDoc e) {
995                     logger.error(e);
996                 }
997             }
998
999             if (order == TableOrder.BY_COLUMN) {
1000                cellpos = (pieIndex * rowCount) + index;
1001            } else {
1002                cellpos = pieIndex + (rowCount * index);
1003            }
1004
1005            if (canDrillThrough((Cell) cells.get(cellpos)) &&
1006                    (!((Cell) cells.get(cellpos)).isNull())) {
1007                String JavaDoc id = DomUtils.randomId();
1008                dispatcher.addRequestListener(id, null,
1009                    new DrillThroughHandler((Cell) cells.get(cellpos)));
1010
1011                boolean firstParameter = url.indexOf("?") == -1;
1012                url += (firstParameter ? "?" : "&");
1013                url += id;
1014
1015                return url;
1016            } else {
1017                return null;
1018            }
1019        }
1020    }
1021
1022    /**
1023     * A URLGenerator class to generate chart urls that work with jpivot
1024     * @author robin
1025     *
1026     */

1027    public class jpivotCategoryURLGenerator extends StandardCategoryURLGenerator {
1028        /** Prefix to the URL */
1029        private String JavaDoc prefix = "";
1030
1031        /** Series parameter name to go in each URL */
1032        private String JavaDoc seriesParameterName = "col";
1033
1034        /** Category parameter name to go in each URL */
1035        private String JavaDoc categoryParameterName = "row";
1036        private List JavaDoc cells = null;
1037
1038        jpivotCategoryURLGenerator(Result result) {
1039            cells = result.getCells();
1040        }
1041
1042        jpivotCategoryURLGenerator(Result result, String JavaDoc prefix) {
1043            this.prefix = prefix;
1044            cells = result.getCells();
1045        }
1046
1047        /**
1048         * Implementation of generateURL that integrates with jpivot/wcf framework.
1049         * A request handler is added for each cell/item.
1050         * No test is done to see if a cell is drillable, since the url has to added (I think, like an all or nothing ?)
1051         * Generates a URL for a particular item within a series.
1052         *
1053         * @param data the dataset.
1054         * @param series the series index (zero-based).
1055         * @param category the category index (zero-based).
1056         *
1057         * @return the generated URL
1058         */

1059        public String JavaDoc generateURL(CategoryDataset data, int series, int category) {
1060            String JavaDoc url = prefix;
1061
1062            // convert col, row into ordinal
1063
// series is col, category is row
1064
// (reverese terminology to jfreechart, that way series on measures which is more logical)
1065
int cellpos = (category * colCount) + series;
1066
1067            if (canDrillThrough((Cell) cells.get(cellpos)) &&
1068                    (!((Cell) cells.get(cellpos)).isNull())) {
1069                String JavaDoc id = DomUtils.randomId();
1070                dispatcher.addRequestListener(id, null,
1071                    new DrillThroughHandler((Cell) cells.get(cellpos)));
1072
1073                boolean firstParameter = url.indexOf("?") == -1;
1074                url += (firstParameter ? "?" : "&");
1075                url += id;
1076
1077                return url;
1078            } else {
1079                return null;
1080            }
1081        }
1082    }
1083
1084    /**
1085     * request handler for chart drill through
1086     * does nothing if cell can't be drilled through (e.g. calculated measure)
1087     * @author robin
1088     *
1089     */

1090
1091    // class DrillThroughHandler implements RequestListener {
1092
// Cell cell;
1093
// DrillThroughHandler(Cell cell) {
1094
// this.cell = cell;
1095
// }
1096
// public void request(RequestContext context) throws Exception {
1097
//
1098
// if ( canDrillThrough(cell) ) {
1099
//
1100
// HttpSession session = context.getSession();
1101
// final String drillTableRef = olapModel.getID() + ".drillthroughtable";
1102
// com.tonbeller.wcf.table.TableComponent tc =
1103
// (com.tonbeller.wcf.table.TableComponent)
1104
// session.getAttribute(drillTableRef);
1105
// // get a new drill through table model
1106
// TableModel tm = drillThrough(cell);
1107
//
1108
// // need to create a new table model for each drill through request
1109
// // because table model creates an array of columns
1110
// tc = new com.tonbeller.wcf.table.TableComponent(drillTableRef, tm);
1111
// tc.initialize(context);
1112
// ((DefaultSelectionModel) tc.getSelectionModel()).setMode(SelectionModel.NO_SELECTION);
1113
// session.setAttribute(drillTableRef, tc);
1114
// tc.setVisible(true);
1115
// }
1116
// }
1117
// }
1118
class DrillThroughHandler implements RequestListener {
1119        Cell cell;
1120
1121        DrillThroughHandler(Cell cell) {
1122            this.cell = cell;
1123        }
1124
1125        public void request(RequestContext context) throws Exception JavaDoc {
1126            if (canDrillThrough(cell)) {
1127                HttpSession JavaDoc session = context.getSession();
1128                final String JavaDoc drillTableRef = olapModel.getID() +
1129                    ".drillthroughtable";
1130                ITableComponent tc = (ITableComponent) session.getAttribute(drillTableRef);
1131
1132                // get a new drill through table model
1133
TableModel tm = drillThrough(cell);
1134                tc.setModel(tm);
1135                tc.setVisible(true);
1136            }
1137        }
1138    }
1139}
1140
Popular Tags