001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.hayabusa.io;
017
018import java.util.List;
019
020import org.jfree.data.general.Dataset;
021import org.jfree.data.general.PieDataset;
022// import org.jfree.data.general.ValueDataset;                  // 5.7.8.0 (2014/07/04)
023import org.jfree.data.category.CategoryDataset;
024import org.jfree.data.xy.XYDataset;
025import org.jfree.chart.plot.Plot;
026import org.jfree.chart.plot.MultiplePiePlot;
027import org.jfree.chart.plot.PiePlot;
028import org.jfree.chart.plot.PiePlot3D;
029import org.jfree.chart.plot.RingPlot;
030import org.jfree.chart.plot.SpiderWebPlot;
031import org.jfree.chart.plot.PolarPlot;
032// import org.jfree.chart.plot.MeterPlot;                               // 5.7.8.0 (2014/07/04)
033// import org.jfree.chart.plot.ThermometerPlot;                 // 5.7.8.0 (2014/07/04)
034// import org.jfree.chart.plot.CompassPlot;                             // 5.7.8.0 (2014/07/04)
035import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
036import org.jfree.chart.labels.StandardPieToolTipGenerator;
037
038/**
039 * ChartPlot_Pie は、ChartPlot インターフェースを継承した実体クラスです。
040 * JFreeChart では、各種オブジェクトの組み合わせで、色々なグラフを作成できます。
041 * チャートタイプが、複数種類存在するため、ここでは、特殊な方法として、各タイプ毎に
042 * オブジェクトを構築しています。(ファクトリメソッド的な処理)
043 *
044 * @version  0.9.0      2007/06/21
045 * @author       Kazuhiko Hasegawa
046 * @since        JDK1.1,
047 */
048public class ChartPlot_Pie implements ChartPlot {
049
050        /**
051         * Plot オブジェクトを取得します。
052         *
053         * Plot オブジェクト には、その種類の応じた、データセットやレンデラーを
054         * 設定する必要があります。
055         * また、複数のデータセットや、それに関係する属性情報も、設定する必要が
056         * あります。
057         * Plot は、JFreeChart オブジェクトにつき、一つ用意しなければなりません。
058         * チャート合成時でも、Plot は一つです。
059         *
060         * @og.rev 5.3.0.0 (2010/12/01) 特殊プロットの追加
061         * @og.rev 5.7.8.0 (2014/07/04) MeterPlot 、Compass 、Thermometer の機能追加
062         * @og.rev 5.9.10.4 (2016/07/19) Pieに色指定の反映
063         *
064         * @param       create  ChartCreateオブジェクト
065         *
066         * @return      Plotオブジェクト
067         */
068        public Plot getPlot( final ChartCreate create ) {
069
070                List<ChartDataset> datasetList = create.getDatasetList();
071                ChartDataset chDataset = datasetList.get(0);
072
073                Dataset dtset = chDataset.getDataset();
074
075                // クリッカブル・マップ
076                HybsURLGenerator urlGen = create.getURLGenerator();
077                boolean useToolTip = create.isUseToolTip();             // 4.9.9.9 (2009/08/07) メソッド名変更
078
079                Plot plot = null;
080                String type = chDataset.getChartType();
081                if( "MultiplePie".equalsIgnoreCase( type ) ) {
082                        plot = new MultiplePiePlot();
083                        ((MultiplePiePlot)plot).setDataset( (CategoryDataset)dtset );
084                }
085                else if( "Pie".equalsIgnoreCase( type ) ) {
086                        plot = new PiePlot();
087                        ((PiePlot)plot).setDataset( (PieDataset)dtset );
088                        if( urlGen != null ) {
089                                ((PiePlot)plot).setURLGenerator( urlGen );
090                        }
091                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
092                                ((PiePlot)plot).setToolTipGenerator( new StandardPieToolTipGenerator() );
093                        }
094                        
095                        // 5.9.10.4 (2016/07/19) 色指定の反映
096                        java.awt.Color[] clrs = chDataset.getSeriesColors();
097                        if( clrs != null && clrs.length>0){
098                                for( int i=0;i<clrs.length; i++){
099                                        ((PiePlot)plot).setSectionPaint(i,clrs[i]); // 非推奨だがとりあえず暫定的にindexを使っておく
100                                }
101                        }
102                        
103                }
104                else if( "Pie3D".equalsIgnoreCase( type ) ) {
105                        plot = new PiePlot3D();
106                        ((PiePlot3D)plot).setDataset( (PieDataset)dtset );
107                        if( urlGen != null ) {
108                                ((PiePlot)plot).setURLGenerator( urlGen );
109                        }
110                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
111                                ((PiePlot)plot).setToolTipGenerator( new StandardPieToolTipGenerator() );
112                        }
113                }
114                else if( "Ring".equalsIgnoreCase( type ) ) {
115                        plot = new RingPlot();
116                        ((RingPlot)plot).setDataset( (PieDataset)dtset );
117                        if( urlGen != null ) {
118                                ((PiePlot)plot).setURLGenerator( urlGen );
119                        }
120                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
121                                ((RingPlot)plot).setToolTipGenerator( new StandardPieToolTipGenerator() );
122                        }
123                }
124                else if( "SpiderWeb".equalsIgnoreCase( type ) ) {
125                        plot = new SpiderWebPlot();
126                        ((SpiderWebPlot)plot).setDataset( (CategoryDataset)dtset );
127                        if( urlGen != null ) {
128                                ((SpiderWebPlot)plot).setURLGenerator( urlGen );
129                        }
130                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
131                                ((SpiderWebPlot)plot).setToolTipGenerator( new StandardCategoryToolTipGenerator() );
132                        }
133                }
134                // 5.3.0.0 (2010/12/01) 特殊プロットの追加
135                else if( "Polar".equalsIgnoreCase( type ) ) {
136                        plot = new PolarPlot();
137                        ((PolarPlot)plot).setDataset( (XYDataset)dtset );
138                }
139                else if( "Meter".equalsIgnoreCase( type ) ) {
140                        // 5.7.8.0 (2014/07/04) 機能追加
141                        plot = chDataset.makeMeterPlot();
142//                      plot = new MeterPlot();
143//                      ((MeterPlot)plot).setDataset( (ValueDataset)dtset );
144                }
145                else if( "Thermometer".equalsIgnoreCase( type ) ) {
146                        // 5.7.8.0 (2014/07/04) 機能追加
147                        plot = chDataset.makeThermometerPlot();
148//                      plot = new ThermometerPlot();
149//                      ((ThermometerPlot)plot).setDataset( (ValueDataset)dtset );
150                }
151                else if( "Compass".equalsIgnoreCase( type ) ) {
152                        // 5.7.8.0 (2014/07/04) 機能追加
153                        plot = chDataset.makeCompassPlot();
154//                      plot = new CompassPlot();
155//                      ((CompassPlot)plot).addDataset( (ValueDataset)dtset );
156                }
157
158                return plot;
159        }
160}