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 * drawItem と同等の機能を持った、メソッドです。 114 * 115 * @og.rev 4.1.1.0 (2008/02/04) 新規追加 116 * @og.rev 4.1.2.0 (2008/03/12) ラベルのアンダーライン時にItemLavelを表示しない 117 * @og.rev 6.0.2.2 (2014/10/03) このクラスでは高速化せず、親クラスの drawItem で処理しています。 118 * 119 * @param g2 Graphics2Dオブジェクト 120 * @param state CategoryItemRendererStateオブジェクト 121 * @param dataArea Rectangle2Dオブジェクト 122 * @param plot CategoryPlotオブジェクト 123 * @param domainAxis CategoryAxisオブジェクト 124 * @param rangeAxis ValueAxisオブジェクト 125 * @param dataset CategoryDatasetオブジェクト 126 * @param serNo シリアル番号 127 */ 128 @Override 129 public void drawItem2( final Graphics2D g2, final CategoryItemRendererState state, 130 final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, 131 final ValueAxis rangeAxis, final CategoryDataset dataset, final int serNo ) { 132 133 final int clmCount = dataset.getColumnCount(); 134 final int rowCount = dataset.getRowCount(); 135 final int passCount = getPassCount(); 136 137 for( int pass=0; pass<passCount; pass++ ) { 138 for( int column=0; column<clmCount; column++ ) { 139 for( int row=0; row<rowCount; row++ ) { 140 if( row == serNo ) { continue; } // Mis Add 2007/07/23 141 drawItem(g2, state, dataArea, plot, 142 domainAxis, rangeAxis, dataset, 143 row, column, pass); 144 } 145 // 指定のシリーズと一致する場合は、最後に描画する。 Mis Add 2007/07/23 146 if( serNo >= 0 ) { 147 drawItem(g2, state, dataArea, plot, 148 domainAxis, rangeAxis, dataset, 149 serNo, column, pass); 150 } 151 } 152 } 153 } 154 155 /** 156 * この文字列と指定されたオブジェクトを比較します。 157 * 158 * 親クラスで、equals メソッドが実装されているため、警告がでます。 159 * 160 * @og.rev 5.1.8.0 (2010/07/01) findbug対応 161 * @og.rev 5.1.9.0 (2010/08/01) findbug対応 162 * 163 * @param object 比較するオブジェクト 164 * 165 * @return Objectが等しい場合は true、そうでない場合は false 166 */ 167 @Override 168 public boolean equals( final Object object ) { 169 // 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 170 return super.equals( object ) && hsCode == ((HybsBarRenderer3D)object).hsCode; 171 } 172 173 /** 174 * このオブジェクトのハッシュコードを取得します。 175 * 176 * @og.rev 5.1.8.0 (2010/07/01) findbug対応 177 * @og.rev 5.1.9.0 (2010/08/01) findbug対応 178 * 179 * @return ハッシュコード 180 */ 181 @Override 182 public int hashCode() { return hsCode ; } 183}