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.db; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.fukurou.util.LogWriter; 020 021/** 022 * データのコード情報を取り扱うクラスです。 023 * 024 * 開始、終了、ステップの情報から、HTMLのメニューやリストを作成するための オプション 025 * タグを作成したり、与えられたキーをもとに、チェック済みのオプションタグを作成したりします。 026 * 027 * ここでは、数字(連番)の自動生成を行います。パラメータで、開始、終了、ステップを指定します。 028 * パラメータの初期値は、開始(1)、終了(10)、ステップ(1) です。 029 * 030 * 例:1,10,1 → 1,2,3,4,5,6,7,8,9,10 のプルダウン 031 * 例:10,100,10 → 10,20,30,40,50,60,70,80,90,100 のプルダウン 032 * 例:-5,5,1 → -5,-4,-3,-2,-1,0,1,2,3,4,5 のプルダウン 033 * 例:5,-5,-2 → 5,3,1,-1,-3,-5 のプルダウン 034 * 035 * @og.group 選択データ制御 036 * @og.rev 5.6.1.1 (2013/02/08) 新規追加 037 * 038 * @version 4.0 039 * @author Kazuhiko Hasegawa 040 * @since JDK5.0, 041 */ 042// public class Selection_NUM implements Selection { 043public class Selection_NUM extends Selection_NULL { 044 private final String CACHE ; 045 private final String ST_ED_STEP ; 046 047 /** 048 * コンストラクター 049 * 050 * 引数は、開始、終了、ステップです。 051 * パラメータの初期値は、開始(1)、終了(10)、ステップ(1) です。 052 * 053 * @param editPrm 開始、終了、[ステップ]を表す引数(例:1,10,1) 054 */ 055 public Selection_NUM( final String editPrm ) { 056 // if( param.length < 2 ) { 057 // String errMsg = "引数は、開始、終了、[ステップ] です。最低でも2個必要です。"; 058 // throw new IllegalArgumentException( errMsg ); 059 // } 060 061 String[] param = (editPrm == null) ? new String[0] : editPrm.split( "," ) ; 062 063 int start = (param.length > 0) ? Integer.parseInt( param[0].trim() ) : 1; 064 int end = (param.length > 1) ? Integer.parseInt( param[1].trim() ) : 10 ; 065 int step = (param.length > 2) ? Integer.parseInt( param[2].trim() ) : 1; 066 067 if( step == 0 ) { 068 String errMsg = "ステップ に 0 は指定できません。無限ループします。"; 069 throw new IllegalArgumentException( errMsg ); 070 } 071 072 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 073 074 // ステップの正負による判定の違い。while( Math.signum( end-start ) * step >= 0.0 ) で、判る? 075 // 終了条件は、含む(val<=end) 076 int val = start; 077 int sign = ( step > 0 ) ? 1 : -1 ; // ステップの符号。 078 while( (end - val) * sign >= 0 ) { 079 buf.append( "<option value=\"" ).append( val ).append( "\"" ); 080 buf.append( ">" ).append( val ).append( "</option>" ); 081 val += step; 082 } 083 084 CACHE = buf.toString(); 085 ST_ED_STEP = "Start=" + start + " , End=" + end + " , Step=" + step ; 086 } 087 088 /** 089 * 初期値が選択済みの 選択肢(オプション)を返します。 090 * このオプションは、引数の値を初期値とするオプションタグを返します。 091 * このメソッドでは、ラベル(短)が設定されている場合でも、これを使用せずに必ずラベル(長)を使用します。 092 * 093 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL を 継承するため、削除 094 * 095 * @param selectValue 選択されている値 096 * @param seqFlag シーケンスアクセス機能 [true:ON/false:OFF] 097 * 098 * @return オプションタグ 099 * @see #getOption( String, boolean, boolean ) 100 */ 101// public String getOption( final String selectValue,final boolean seqFlag ) { 102// return getOption( selectValue, seqFlag, false ); 103// } 104 105 /** 106 * 初期値が選択済みの 選択肢(オプション)を返します。 107 * このオプションは、引数の値を初期値とするオプションタグを返します。 108 * このメソッドでは、引数のuseShortLabelがtrueに指定された場合に、ラベル(短)をベースとした 109 * ツールチップ表示を行います。 110 * 111 * @param selectValue 選択されている値 112 * @param seqFlag シーケンスアクセス機能 [true:ON/false:OFF] 113 * @param useShortLabel ラベル(短)をベースとしたオプション表示を行うかどうか。(未使用) 114 * 115 * @return オプションタグ 116 * @see #getOption( String, boolean ) 117 */ 118 @Override 119 public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) { 120 // マッチするアドレスを探す。 121 int selected = CACHE.indexOf( "\"" + selectValue + "\"" ); 122 123 if( selected < 0 ) { 124 if( selectValue != null && selectValue.length() > 0 ) { 125 String errMsg = "数字範囲に存在しない値が指定されました。" 126 + " value=[" + selectValue + "]" 127 + HybsSystem.CR + ST_ED_STEP ; 128 LogWriter.log( errMsg ); 129 } 130 return CACHE; 131 } 132 else { 133 // "値" 文字列の位置が、selected なので、値の文字数+2までが、前半部分になる。 134 int indx = selected + selectValue.length() + 2 ; 135 136 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 137 // 3.6.0.6 (2004/10/22) シーケンスアクセス機能を指定する seqFlag を導入 138 if( seqFlag ) { 139 buf.append( "<option value=\"" ).append( selectValue ).append( "\"" ); 140 } 141 else { 142 buf.append( CACHE.substring( 0,indx ) ); 143 } 144 buf.append( " selected=\"selected\"" ); 145 buf.append( CACHE.substring( indx ) ); 146 return buf.toString() ; 147 } 148 } 149 150 /** 151 * 初期値が選択済みの 選択肢(オプション)を返します。 152 * このオプションは、引数の値を初期値とするオプションタグを返します。 153 * ※ このクラスでは実装されていません。 154 * 155 * @og.rev 2.1.0.1 (2002/10/17) 選択リストを、正方向にしか選べないようにする sequenceFlag を導入する 156 * @og.rev 3.8.6.0 (2006/09/29) useLabel 属性 追加 157 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL を 継承するため、削除 158 * 159 * @param name ラジオの name 160 * @param selectValue 選択されている値 161 * @param useLabel ラベル表示の有無 [true:有/false:無] 162 * 163 * @return オプションタグ 164 */ 165// public String getRadio( final String name,final String selectValue,final boolean useLabel ) { 166// String errMsg = "このクラスでは実装されていません。"; 167// throw new UnsupportedOperationException( errMsg ); 168// } 169 170 /** 171 * 初期値が選択済みの 選択肢(オプション)を返します。 172 * このオプションは、引数の値を初期値とするオプションタグを返します。 173 * ※ このクラスでは実装されていません。 174 * 175 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL を 継承するため、削除 176 * 177 * @param selectValue 選択されている値 178 * 179 * @return オプションタグ 180 */ 181// public String getRadioLabel( final String selectValue ) { 182// String errMsg = "このクラスでは実装されていません。"; 183// throw new UnsupportedOperationException( errMsg ); 184// } 185 186 /** 187 * 選択肢(value)に対するラベルを返します。 188 * 選択肢(value)が、存在しなかった場合は、選択肢そのものを返します。 189 * getValueLabel( XX ) は、getValueLabel( XX,false ) と同じです。 190 * 191 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL を 継承するため、削除 192 * 193 * @param selectValue 選択肢の値 194 * 195 * @return 選択肢のラベル 196 * @see #getValueLabel( String,boolean ) 197 */ 198// public String getValueLabel( final String selectValue ) { 199// return getValueLabel( selectValue,false ); 200// } 201 202 /** 203 * 選択肢(value)に対するラベルを返します。 204 * 選択肢(value)が、存在しなかった場合は、選択肢そのものを返します。 205 * このメソッドでは、短縮ラベルを返すかどうかを指定するフラグを指定します。 206 * getValueLabel( XX,false ) は、getValueLabel( XX ) と同じです。 207 * 208 * @og.rev 4.0.0.0 (2005/11/30) を追加 209 * 210 * @param selectValue 選択肢の値 211 * @param flag 短縮ラベルを [true:使用する/false:しない] (未使用) 212 * 213 * @return 選択肢のラベル 214 * @see #getValueLabel( String ) 215 */ 216 @Override 217 public String getValueLabel( final String selectValue,final boolean flag ) { 218 // あろうがなかろうが、選択肢そのものを返します。 219 return selectValue; 220 } 221 222 /** 223 * マルチ・キーセレクトを使用するかどうかを返します(false固定)。 224 * true:使用する。false:使用しない です。 225 * ただし、実際に使用するかどうかは、HTML出力時に決めることが出来ます。 226 * ここでは、USE_MULTI_KEY_SELECT が true で、USE_SIZE(=20)以上の場合に 227 * true を返します。 228 * 229 * @og.rev 3.5.5.7 (2004/05/10) 新規作成 230 * 231 * @return 選択リストで、マルチ・キーセレクトを使用するかどうか(true:使用する) (false固定) 232 */ 233 @Override 234 public boolean useMultiSelect() { 235 return true; 236 } 237 238 /** 239 * オブジェクトのキャッシュが時間切れかどうかを返します。 240 * キャッシュが時間切れ(無効)であれば、true を、有効であれば、 241 * false を返します。 242 * 243 * @og.rev 4.0.0.0 (2005/01/31) 新規作成 244 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL を 継承するため、削除 245 * 246 * @return キャッシュが時間切れなら true 247 */ 248// public boolean isTimeOver() { 249// return false; 250// } 251}