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 */
016 package org.opengion.hayabusa.io;
017
018 import org.opengion.fukurou.util.StringUtil;
019
020 import org.jfree.chart.urls.CategoryURLGenerator;
021 import org.jfree.chart.urls.PieURLGenerator;
022 import org.jfree.chart.urls.XYURLGenerator;
023
024 import org.jfree.data.category.CategoryDataset;
025 import org.jfree.data.general.PieDataset;
026 import org.jfree.data.xy.XYDataset;
027
028 /**
029 * A URL generator that can be assigned to a
030 * {@link org.jfree.chart.renderer.category.CategoryItemRenderer}.
031 */
032 public class HybsURLGenerator implements CategoryURLGenerator, PieURLGenerator, XYURLGenerator {
033
034 /** The prefix. */
035 private final String prefix ;
036
037 /** The category parameter name. */
038 private String categoryName = "category";
039
040 /** The pie index parameter name. */
041 private String indexName = "pieIndex";
042
043 /** Series parameter name to go in each URL */
044 private String seriesName = "series" ;
045
046 /**
047 * クリ?ブル・マップ用URLを指定します?
048 *
049 * 画像に、クリ?ブル・マップを作?する場合?、URL を指定します?
050 * これは、画像上にエリア?でリンク引数を作?することが可能です?
051 * URL 自身は? 付きで固定?の引数を?結することが可能です?
052 * クリ?したエリアのカ?リ?ン?クスの値(引数)は、?動的に
053 * 設定されます?(?しな??合?チャートによって異なりま?
054 * ※ 本家 jFreeChart とは並び?キーが異なります?
055 * <pre>
056 * ・Pie ?category、pieIndex
057 * ・XY ?category、series
058 * ・Category ?category、series
059 * </pre>
060 * こ?引数の URL の名称を変更した??合?、URL に続けて、カン?,) で?
061 * 名称を記述してください?
062 * 例:link.jsp,BLOCK
063 *
064 * @param imageMapUrl クリ?ブル・マップ用URL
065 */
066 public HybsURLGenerator( final String imageMapUrl ) {
067 boolean first = imageMapUrl.indexOf( '?' ) < 0 ; // 含まなければ true
068
069 int adrs = imageMapUrl.indexOf( ',' );
070 if( adrs < 0 ) { // 引数???
071 prefix = imageMapUrl + ((first) ? "?" : "&");
072 }
073 else {
074 // ?目の引数設?
075 prefix = imageMapUrl.substring( 0,adrs ) + ((first) ? "?" : "&") ;
076 int adrs2 = imageMapUrl.indexOf( ',',adrs+1 );
077 if( adrs2 < 0 ) { // 引数?1個確?
078 categoryName = imageMapUrl.substring( adrs+1 );
079 }
080 else {
081 categoryName = imageMapUrl.substring( adrs+1,adrs2 );
082 seriesName = imageMapUrl.substring( adrs2+1 );
083 indexName = seriesName;
084 }
085 }
086 }
087
088 /**
089 * Generates a URL for a particular item within a series.
090 *
091 * @param dataset カ?リDataset
092 * @param series シリーズ番号
093 * @param category カ?リ番号
094 *
095 * @return 作?されたURL??
096 */
097 public String generateURL( final CategoryDataset dataset, final int series, final int category ) {
098 Comparable<?> seriesKey = dataset.getRowKey(series); // 4.3.3.6 (2008/11/15) Generics警告対?
099 Comparable<?> categoryKey = dataset.getColumnKey(category); // 4.3.3.6 (2008/11/15) Generics警告対?
100
101 String url = prefix
102 + categoryName + "="
103 + StringUtil.urlEncode(categoryKey.toString() )
104 + "&" + seriesName + "="
105 + StringUtil.urlEncode( seriesKey.toString() );
106 return url;
107 }
108
109 /**
110 * Generates a URL.
111 *
112 * @param dataset パイDataset
113 * @param key アイ?キー
114 * @param pieIndex イン?クス番号
115 *
116 * @return 作?されたURL??
117 */
118 @SuppressWarnings("rawtypes")
119 public String generateURL( final PieDataset dataset, final Comparable key, final int pieIndex ) {
120 String url = prefix
121 + categoryName + "="
122 + StringUtil.urlEncode(key.toString() )
123 + "&" + indexName + "="
124 + pieIndex;
125
126 return url;
127 }
128
129 /**
130 * Generates a URL for a particular item within a series.
131 *
132 * @param dataset エ?スワイDataset
133 * @param series シリーズ番号
134 * @param item アイ?番号
135 *
136 * @return 作?されたURL??
137 */
138 public String generateURL( final XYDataset dataset, final int series, final int item ) {
139 String url = prefix
140 + categoryName + "=" + item
141 + "&" + seriesName + "=" + series;
142 return url;
143 }
144 }