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    }