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; 019import java.awt.Color; 020import org.opengion.hayabusa.common.HybsSystemException; // 6.9.8.0 (2018/05/28) 021 022import org.jfree.data.general.Dataset; 023import org.jfree.data.general.PieDataset; 024import org.jfree.data.category.CategoryDataset; 025import org.jfree.data.xy.XYDataset; 026import org.jfree.chart.plot.Plot; 027import org.jfree.chart.plot.MultiplePiePlot; 028import org.jfree.chart.plot.PiePlot; 029import org.jfree.chart.plot.PiePlot3D; 030import org.jfree.chart.plot.RingPlot; 031import org.jfree.chart.plot.SpiderWebPlot; 032import org.jfree.chart.plot.PolarPlot; 033import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 034import org.jfree.chart.labels.StandardPieToolTipGenerator; 035 036/** 037 * ChartPlot_Pie は、ChartPlot インターフェースを継承した実体クラスです。 038 * JFreeChart では、各種オブジェクトの組み合わせで、色々なグラフを作成できます。 039 * チャートタイプが、複数種類存在するため、ここでは、特殊な方法として、各タイプ毎に 040 * オブジェクトを構築しています。(ファクトリメソッド的な処理) 041 * 042 * @version 0.9.0 2007/06/21 043 * @author Kazuhiko Hasegawa 044 * @since JDK1.1, 045 */ 046public class ChartPlot_Pie implements ChartPlot { 047 048 /** 049 * デフォルトコンストラクター 050 * 051 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 052 */ 053 public ChartPlot_Pie() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 054 055 /** 056 * Plot オブジェクトを取得します。 057 * 058 * Plot オブジェクト には、その種類の応じた、データセットやレンデラーを 059 * 設定する必要があります。 060 * また、複数のデータセットや、それに関係する属性情報も、設定する必要が 061 * あります。 062 * Plot は、JFreeChart オブジェクトにつき、一つ用意しなければなりません。 063 * チャート合成時でも、Plot は一つです。 064 * 065 * @og.rev 5.3.0.0 (2010/12/01) 特殊プロットの追加 066 * @og.rev 5.7.8.0 (2014/07/04) MeterPlot 、Compass 、Thermometer の機能追加 067 * @og.rev 6.4.9.0 (2016/07/23) Pie,Pie3D,Ring に、色指定を追加。これらは、同じ設定が使えるので、マージします。 068 * 069 * @param create ChartCreateオブジェクト 070 * 071 * @return Plotオブジェクト 072 */ 073 public Plot getPlot( final ChartCreate create ) { 074 075 final List<ChartDataset> datasetList = create.getDatasetList(); 076 final ChartDataset chDataset = datasetList.get(0); 077 078 final Dataset dtset = chDataset.getDataset(); 079 080 // クリッカブル・マップ 081 final HybsURLGenerator urlGen = create.getURLGenerator(); 082 final boolean useToolTip = create.isUseToolTip(); // 4.9.9.9 (2009/08/07) メソッド名変更 083 084 Plot plot = null; 085 final String type = chDataset.getChartType(); 086 // 6.4.9.0 (2016/07/23) Pie,Pie3D,Ring は、同じ設定が使えるので、マージします。 087 if( "Pie".equalsIgnoreCase( type ) || "Pie3D".equalsIgnoreCase( type ) || "Ring".equalsIgnoreCase( type ) ) { 088 final PiePlot pplot ; 089 switch( type ) { 090 case "Pie" : pplot = new PiePlot(); break; 091 case "Pie3D" : pplot = new PiePlot3D(); break; 092 case "Ring" : pplot = new RingPlot(); break; 093 // 6.9.8.0 (2018/05/28) FindBugs:switch 文の2つの case のために同じコードを使用しているメソッド 094// default : pplot = new PiePlot(); break; 095 default : 096 // 先に、type を判定しているため、default には、分岐されない。 097 final String errMsg = "何らかの要因で、ありえないエラーが発生しました。"; 098 throw new HybsSystemException( errMsg ); 099 } 100 101 pplot.setDataset( (PieDataset)dtset ); 102 if( urlGen != null ) { 103 pplot.setURLGenerator( urlGen ); 104 } 105 if( useToolTip ){ // 4.3.1.0 (2008/08/09) ツールチップスの利用 106 pplot.setToolTipGenerator( new StandardPieToolTipGenerator() ); 107 } 108 109 // 6.4.9.0 (2016/07/23) 色指定の反映。indexが非推奨なので、キー指定に変更。 110 final Color[] clrs = chDataset.getSeriesColors(); 111 if( clrs != null && clrs.length>0 ) { 112 final int len = ((PieDataset)dtset).getItemCount(); 113 for( int i=0;i<clrs.length && i<len; i++ ) { 114 final Comparable<?> key = ((PieDataset)dtset).getKey(i); 115 pplot.setSectionPaint( key,clrs[i] ); 116 } 117 } 118 plot = pplot; 119 } 120 else if( "MultiplePie".equalsIgnoreCase( type ) ) { 121 plot = new MultiplePiePlot(); 122 ((MultiplePiePlot)plot).setDataset( (CategoryDataset)dtset ); 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 // 6.4.9.0 (2016/07/23) 色指定の反映。 135 final Color[] clrs = chDataset.getSeriesColors(); 136 if( clrs != null && clrs.length>0 ) { 137 for( int i=0;i<clrs.length; i++ ) { 138 ((SpiderWebPlot)plot).setSeriesPaint( i,clrs[i] ); 139 } 140 } 141 } 142 // 5.3.0.0 (2010/12/01) 特殊プロットの追加 143 else if( "Polar".equalsIgnoreCase( type ) ) { 144 plot = new PolarPlot(); 145 ((PolarPlot)plot).setDataset( (XYDataset)dtset ); 146 } 147 else if( "Meter".equalsIgnoreCase( type ) ) { 148 // 5.7.8.0 (2014/07/04) 機能追加 149 plot = chDataset.makeMeterPlot(); 150 } 151 else if( "Thermometer".equalsIgnoreCase( type ) ) { 152 // 5.7.8.0 (2014/07/04) 機能追加 153 plot = chDataset.makeThermometerPlot(); 154 } 155 else if( "Compass".equalsIgnoreCase( type ) ) { 156 // 5.7.8.0 (2014/07/04) 機能追加 157 plot = chDataset.makeCompassPlot(); 158 } 159 160 return plot; 161 } 162}