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.awt.Graphics2D;
019import java.awt.Paint;
020import java.awt.geom.Rectangle2D;
021import java.awt.Color;
022
023import org.jfree.chart.renderer.category.BarRenderer3D;
024import org.jfree.chart.renderer.category.CategoryItemRendererState;
025import org.jfree.chart.axis.CategoryAxis;
026import org.jfree.chart.axis.ValueAxis;
027import org.jfree.chart.plot.CategoryPlot;
028import org.jfree.data.category.CategoryDataset;
029
030/**
031 * HybsBarRenderer は、org.jfree.chart.renderer.category.BarRenderer を
032 * 拡張したカスタマイズクラスです。
033 * これは、描画に対して、予め制限を設けて、処理速度の向上を図っています。
034 *
035 * @og.rev 6.0.2.2 (2014/10/03) 新規作成
036 *
037 * @version  0.9.0      2001/05/05
038 * @author       Kazuhiko Hasegawa
039 * @since        JDK1.1,
040 */
041public class HybsBarRenderer3D extends BarRenderer3D implements HybsDrawItem {
042        private static final long serialVersionUID = 602220141003L ;
043
044        private Color[]         categoryColor                   ;               // 6.0.2.1 (2014/09/26) categoryカラー配列
045        private final int hsCode = Long.valueOf( System.nanoTime() ).hashCode() ;       // 5.1.9.0 (2010/08/01) equals,hashCode
046
047        /**
048         * デフォルトコンストラクター
049         *
050         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
051         */
052        public HybsBarRenderer3D() { super(); }         // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
053
054        /**
055         * itemLabelVisible 時に、最後の値のみ表示するかどうか[true:有効/false:無効]を指定します。
056         *
057         * これは、itemLabelVisible 属性に、"last" という設定値を指定した場合は、
058         * 最後のみラベル表示します。
059         * このメソッドでは、true が指定された場合は、"last" 属性が有効になったと
060         * 判断します。
061         * (独自メソッド。HybsDrawItem より継承)
062         *
063         * @og.rev 4.1.2.0 (2008/03/12) 新規追加
064         * @og.rev 6.0.2.2 (2014/10/03) このクラスでは使用していません。
065         *
066         * @param       flag    最後の値のみ表示するかどうか[true:有効/false:無効]
067         */
068        @Override
069        public void setItemLabelLastVisible( final boolean flag ) {
070                // 現時点では、何もしません。
071        }
072
073        /**
074         * categoryカラー配列を設定します。
075         *
076         * これは、HybsJDBCCategoryDataset クラスで、カテゴリカラーを指定した場合に、
077         * そこから取り出した値をセットすることで、Hybs***Renderer に設定して使います。
078         * Hybs***Renderer 側では、このカラー配列を使用して、getItemPaint(int,int) を
079         * オーバーライドして使います。
080         * (独自メソッド。HybsDrawItem より継承)
081         *
082         * @og.rev 6.0.2.1 (2014/09/26) 新規追加
083         *
084         * @param       cateColor       categoryカラー配列(可変長引数)
085         */
086        @Override
087        public void setCategoryColor( final Color... cateColor ) {
088                // 6.0.2.5 (2014/10/31) refactoring
089                if( cateColor != null ) { categoryColor = cateColor.clone(); }          // 6.1.1.0 (2015/01/17) 可変長引数でもnullは来る。
090        }
091
092        /**
093         * カテゴリ違いのColorオブジェクトを返します。
094         *
095         * Returns the paint used to color data items as they are drawn.
096         * <p>
097         * The default implementation passes control to the
098         * <code>lookupSeriesPaint()</code> method. You can override this method
099         * if you require different behaviour.
100         *
101         * @param row  the row (or series) index (zero-based).
102         * @param column  the column (or category) index (zero-based).
103         *
104         * @return カテゴリ違いのColorオブジェクト
105         */
106        @Override
107        public Paint getItemPaint( final int row, final int column ) {
108                // 6.4.1.1 (2016/01/16) PMD refactoring. A method should have only one exit point, and that should be the last statement in the method
109                return categoryColor == null ? super.getItemPaint( row,column ) : categoryColor[column];
110
111        }
112
113        /**
114         * drawItem と同等の機能を持った、メソッドです。
115         *
116         * @og.rev 4.1.1.0 (2008/02/04) 新規追加
117         * @og.rev 4.1.2.0 (2008/03/12) ラベルのアンダーライン時にItemLavelを表示しない
118         * @og.rev 6.0.2.2 (2014/10/03) このクラスでは高速化せず、親クラスの drawItem で処理しています。
119         *
120         * @param g2                    Graphics2Dオブジェクト
121         * @param state                 CategoryItemRendererStateオブジェクト
122         * @param dataArea              Rectangle2Dオブジェクト
123         * @param plot                  CategoryPlotオブジェクト
124         * @param domainAxis    CategoryAxisオブジェクト
125         * @param rangeAxis             ValueAxisオブジェクト
126         * @param dataset               CategoryDatasetオブジェクト
127         * @param serNo                 シリアル番号
128         */
129        @Override
130        public void drawItem2( final Graphics2D g2, final CategoryItemRendererState state,
131                        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
132                        final ValueAxis rangeAxis, final CategoryDataset dataset, final int serNo ) {
133
134                final int clmCount = dataset.getColumnCount();
135                final int rowCount = dataset.getRowCount();
136                final int passCount = getPassCount();
137
138                for( int pass=0; pass<passCount; pass++ ) {
139                        for( int column=0; column<clmCount; column++ ) {
140                                for( int row=0; row<rowCount; row++ ) {
141                                        if( row == serNo ) { continue; }        // Mis Add 2007/07/23
142                                                drawItem(g2, state, dataArea, plot,
143                                                        domainAxis, rangeAxis, dataset,
144                                                        row, column, pass);
145                                }
146                                // 指定のシリーズと一致する場合は、最後に描画する。 Mis Add 2007/07/23
147                                if( serNo >= 0 ) {
148                                                drawItem(g2, state, dataArea, plot,
149                                                        domainAxis, rangeAxis, dataset,
150                                                        serNo, column, pass);
151                                }
152                        }
153                }
154        }
155
156        /**
157         * この文字列と指定されたオブジェクトを比較します。
158         *
159         * 親クラスで、equals メソッドが実装されているため、警告がでます。
160         *
161         * @og.rev 5.1.8.0 (2010/07/01) findbug対応
162         * @og.rev 5.1.9.0 (2010/08/01) findbug対応
163         *
164         * @param       object  比較するオブジェクト
165         *
166         * @return      Objectが等しい場合は true、そうでない場合は false
167         */
168        @Override
169        public boolean equals( final Object object ) {
170                // 6.4.1.1 (2016/01/16) PMD refactoring. A method should have only one exit point, and that should be the last statement in the method
171                return super.equals( object ) && hsCode == ((HybsBarRenderer3D)object).hsCode;
172
173        }
174
175        /**
176         * このオブジェクトのハッシュコードを取得します。
177         *
178         * @og.rev 5.1.8.0 (2010/07/01) findbug対応
179         * @og.rev 5.1.9.0 (2010/08/01) findbug対応
180         *
181         * @return      ハッシュコード
182         */
183        @Override
184        public int hashCode() { return hsCode ; }
185}