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         * @og.rev 5.9.17.1 (2017/02/10) Pie3D,Ringにも色指定反映
064         *
065         * @param       create  ChartCreateオブジェクト
066         *
067         * @return      Plotオブジェクト
068         */
069        public Plot getPlot( final ChartCreate create ) {
070
071                List<ChartDataset> datasetList = create.getDatasetList();
072                ChartDataset chDataset = datasetList.get(0);
073
074                Dataset dtset = chDataset.getDataset();
075
076                // クリッカブル・マップ
077                HybsURLGenerator urlGen = create.getURLGenerator();
078                boolean useToolTip = create.isUseToolTip();             // 4.9.9.9 (2009/08/07) メソッド名変更
079
080                Plot plot = null;
081                String type = chDataset.getChartType();
082                if( "MultiplePie".equalsIgnoreCase( type ) ) {
083                        plot = new MultiplePiePlot();
084                        ((MultiplePiePlot)plot).setDataset( (CategoryDataset)dtset );
085                }
086                else if( "Pie".equalsIgnoreCase( type ) ) {
087                        plot = new PiePlot();
088                        ((PiePlot)plot).setDataset( (PieDataset)dtset );
089                        if( urlGen != null ) {
090                                ((PiePlot)plot).setURLGenerator( urlGen );
091                        }
092                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
093                                ((PiePlot)plot).setToolTipGenerator( new StandardPieToolTipGenerator() );
094                        }
095                        
096                        // 5.9.10.4 (2016/07/19) 色指定の反映
097                        java.awt.Color[] clrs = chDataset.getSeriesColors();
098                        if( clrs != null && clrs.length>0){
099                                for( int i=0;i<clrs.length; i++){
100                                        ((PiePlot)plot).setSectionPaint(i,clrs[i]); // 非推奨だがとりあえず暫定的にindexを使っておく
101                                }
102                        }
103                        
104                }
105                else if( "Pie3D".equalsIgnoreCase( type ) ) {
106                        plot = new PiePlot3D();
107                        ((PiePlot3D)plot).setDataset( (PieDataset)dtset );
108                        if( urlGen != null ) {
109                                ((PiePlot)plot).setURLGenerator( urlGen );
110                        }
111                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
112                                ((PiePlot)plot).setToolTipGenerator( new StandardPieToolTipGenerator() );
113                        }
114                        
115                        // 5.9.17.1 (2017/02/10)
116                        java.awt.Color[] clrs = chDataset.getSeriesColors();
117                        if( clrs != null && clrs.length>0){
118                                for( int i=0;i<clrs.length; i++){
119                                        ((PiePlot3D)plot).setSectionPaint(i,clrs[i]); // 非推奨だがとりあえず暫定的にindexを使っておく
120                                }
121                        }
122                }
123                else if( "Ring".equalsIgnoreCase( type ) ) {
124                        plot = new RingPlot();
125                        ((RingPlot)plot).setDataset( (PieDataset)dtset );
126                        if( urlGen != null ) {
127                                ((PiePlot)plot).setURLGenerator( urlGen );
128                        }
129                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
130                                ((RingPlot)plot).setToolTipGenerator( new StandardPieToolTipGenerator() );
131                        }
132                        
133                        // 5.9.17.1 (2017/02/10)
134                        java.awt.Color[] clrs = chDataset.getSeriesColors();
135                        if( clrs != null && clrs.length>0){
136                                for( int i=0;i<clrs.length; i++){
137                                        ((RingPlot)plot).setSectionPaint(i,clrs[i]); // 非推奨だがとりあえず暫定的にindexを使っておく
138                                }
139                        }
140                }
141                else if( "SpiderWeb".equalsIgnoreCase( type ) ) {
142                        plot = new SpiderWebPlot();
143                        ((SpiderWebPlot)plot).setDataset( (CategoryDataset)dtset );
144                        if( urlGen != null ) {
145                                ((SpiderWebPlot)plot).setURLGenerator( urlGen );
146                        }
147                        if( useToolTip ){       // 4.3.1.0 (2008/08/09) ツールチップスの利用
148                                ((SpiderWebPlot)plot).setToolTipGenerator( new StandardCategoryToolTipGenerator() );
149                        }
150                }
151                // 5.3.0.0 (2010/12/01) 特殊プロットの追加
152                else if( "Polar".equalsIgnoreCase( type ) ) {
153                        plot = new PolarPlot();
154                        ((PolarPlot)plot).setDataset( (XYDataset)dtset );
155                }
156                else if( "Meter".equalsIgnoreCase( type ) ) {
157                        // 5.7.8.0 (2014/07/04) 機能追加
158                        plot = chDataset.makeMeterPlot();
159//                      plot = new MeterPlot();
160//                      ((MeterPlot)plot).setDataset( (ValueDataset)dtset );
161                }
162                else if( "Thermometer".equalsIgnoreCase( type ) ) {
163                        // 5.7.8.0 (2014/07/04) 機能追加
164                        plot = chDataset.makeThermometerPlot();
165//                      plot = new ThermometerPlot();
166//                      ((ThermometerPlot)plot).setDataset( (ValueDataset)dtset );
167                }
168                else if( "Compass".equalsIgnoreCase( type ) ) {
169                        // 5.7.8.0 (2014/07/04) 機能追加
170                        plot = chDataset.makeCompassPlot();
171//                      plot = new CompassPlot();
172//                      ((CompassPlot)plot).addDataset( (ValueDataset)dtset );
173                }
174
175                return plot;
176        }
177}