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.db;
017
018 import org.opengion.hayabusa.common.HybsSystem;
019 import org.opengion.fukurou.util.LogWriter;
020 import org.opengion.hayabusa.resource.CodeData;
021
022 /**
023 * ãƒ??タのコード情報を取り扱ã�?‚¯ラスですã?
024 *
025 * 開始ã?終äº??スãƒ?ƒƒプã?æƒ??から、HTMLのメニューã‚?ƒªストを作æ?するための オプション
026 * タグを作æ?したりã?与えられたキーをもとに、チェãƒ?‚¯済みのオプションタグを作æ?したりしますã?
027 *
028 * ここでは、数字(é?番?‰ã?自動生成を行いますã?パラメータでã€?–‹始ã?終äº??スãƒ?ƒƒプをæŒ?®šしますã?
029 * パラメータの初期値はã€?–‹å§?1)、終äº?10)、スãƒ?ƒƒãƒ?1) ですã?
030 *
031 * 例ï¼?,10,1 â†?1,2,3,4,5,6,7,8,9,10 のプルãƒ?‚¦ン
032 * 例ï¼?0,100,10 â†?10,20,30,40,50,60,70,80,90,100 のプルãƒ?‚¦ン
033 * 例ï¼?5,5,1 â†?-5,-4,-3,-2,-1,0,1,2,3,4,5 のプルãƒ?‚¦ン
034 * 例ï¼?,-5,-2 â†?5,3,1,-1,-3,-5 のプルãƒ?‚¦ン
035 *
036 * @og.group 選択データ制御
037 * @og.rev 5.6.1.1 (2013/02/08) 新規追åŠ?
038 *
039 * @version 4.0
040 * @author Kazuhiko Hasegawa
041 * @since JDK5.0,
042 */
043 public class Selection_NUM implements Selection {
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 開始ã?終äº??[スãƒ?ƒƒプ]を表す引数(例ï¼?,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 = "スãƒ?ƒƒãƒ?に ??はæŒ?®šできません。無限ループしますã?";
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 * @param selectValue 選択されてã�?‚‹値
094 * @param seqFlag シーケンスアクセス機è? [true:ON/false:OFF]
095 *
096 * @return オプションタグ
097 * @see #getOption( String, boolean, boolean )
098 */
099 public String getOption( final String selectValue,final boolean seqFlag ) {
100 return getOption( selectValue, seqFlag, false );
101 }
102
103 /**
104 * 初期値が選択済みの 選択肢(オプション)を返しますã?
105 * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
106 * こã?メソãƒ?ƒ‰では、引数のuseShortLabelがtrueにæŒ?®šされた場合に、ラベル(短)をã?ースとした
107 * ãƒ??ルチップ表示を行いますã?
108 *
109 * @param selectValue 選択されてã�?‚‹値
110 * @param seqFlag シーケンスアクセス機è? [true:ON/false:OFF]
111 * @param useShortLabel ラベル(短)をã?ースとしたオプション表示を行うかどã�?�‹ã€?未使用)
112 *
113 * @return オプションタグ
114 * @see #getOption( String, boolean )
115 */
116 public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) {
117 // マッチするアドレスを探すã?
118 int selected = CACHE.indexOf( "\"" + selectValue + "\"" );
119
120 if( selected < 0 ) {
121 if( selectValue != null && selectValue.length() > 0 ) {
122 String errMsg = "数字ç¯?›²に存在しなã�??が指定されましたã€?
123 + " value=[" + selectValue + "]"
124 + HybsSystem.CR + ST_ED_STEP ;
125 LogWriter.log( errMsg );
126 }
127 return CACHE;
128 }
129 else {
130 // "値" æ–?—å?の位置がã?selected なので、å?のæ–?—数?‹2までがã?前半部åˆ?�«なるã?
131 int indx = selected + selectValue.length() + 2 ;
132
133 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
134 // 3.6.0.6 (2004/10/22) シーケンスアクセス機è?を指定すã‚?seqFlag を導å?
135 if( seqFlag ) {
136 buf.append( "<option value=\"" ).append( selectValue ).append( "\"" );
137 }
138 else {
139 buf.append( CACHE.substring( 0,indx ) );
140 }
141 buf.append( " selected=\"selected\"" );
142 buf.append( CACHE.substring( indx ) );
143 return buf.toString() ;
144 }
145 }
146
147 /**
148 * 初期値が選択済みの 選択肢(オプション)を返しますã?
149 * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
150 * ※ こã?クラスでは実è£?�•れてã�?�¾せんã€?
151 *
152 * @og.rev 2.1.0.1 (2002/10/17) 選択リストを、正方向にしか選べなã�?‚ˆã�?�«する sequenceFlag を導å?する
153 * @og.rev 3.8.6.0 (2006/09/29) useLabel 属æ? 追åŠ?
154 *
155 * @param name ラジオの name
156 * @param selectValue 選択されてã�?‚‹値
157 * @param useLabel ラベル表示の有無 [true:æœ?false:無]
158 *
159 * @return オプションタグ
160 */
161 public String getRadio( final String name,final String selectValue,final boolean useLabel ) {
162 String errMsg = "こã?クラスでは実è£?�•れてã�?�¾せんã€?;
163 throw new UnsupportedOperationException( errMsg );
164 }
165
166 /**
167 * 初期値が選択済みの 選択肢(オプション)を返しますã?
168 * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
169 * ※ こã?クラスでは実è£?�•れてã�?�¾せんã€?
170 *
171 * @param selectValue 選択されてã�?‚‹値
172 *
173 * @return オプションタグ
174 */
175 public String getRadioLabel( final String selectValue ) {
176 String errMsg = "こã?クラスでは実è£?�•れてã�?�¾せんã€?;
177 throw new UnsupportedOperationException( errMsg );
178 }
179
180 /**
181 * 選択肢(value)に対するラベルを返しますã?
182 * 選択肢(value)がã?存在しなかったå?合ã?ã€?�¸択肢そã?もã?を返しますã?
183 * getValueLabel( XX ) は、getValueLabel( XX,false ) と同じですã?
184 *
185 * @param selectValue 選択肢の値
186 *
187 * @return 選択肢のラベル
188 * @see #getValueLabel( String,boolean )
189 */
190 public String getValueLabel( final String selectValue ) {
191 return getValueLabel( selectValue,false );
192 }
193
194 /**
195 * 選択肢(value)に対するラベルを返しますã?
196 * 選択肢(value)がã?存在しなかったå?合ã?ã€?�¸択肢そã?もã?を返しますã?
197 * こã?メソãƒ?ƒ‰では、短縮ラベルを返すかどã�?�‹を指定するフラグを指定しますã?
198 * getValueLabel( XX,false ) は、getValueLabel( XX ) と同じですã?
199 *
200 * @og.rev 4.0.0.0 (2005/11/30) を追åŠ?
201 *
202 * @param selectValue 選択肢の値
203 * @param flag 短縮ラベルã‚?[true:使用する/false:しない] (未使用)
204 *
205 * @return 選択肢のラベル
206 * @see #getValueLabel( String )
207 */
208 public String getValueLabel( final String selectValue,final boolean flag ) {
209 // あろã�?�Œなかろã�?�Œã€?�¸択肢そã?もã?を返しますã?
210 return selectValue;
211 }
212
213 /**
214 * マルチã?キーセレクトを使用するかどã�?�‹を返しまã�?false固å®?ã€?
215 * true?š使用する。false:使用しなã�?ですã?
216 * ただしã?実際に使用するかどã�?�‹は、HTML出力時に決めることがå?来ますã?
217 * ここでは、USE_MULTI_KEY_SELECT ã�?true で、USE_SIZE(=20)以上ã?場合に
218 * true を返しますã?
219 *
220 * @og.rev 3.5.5.7 (2004/05/10) 新規作æ?
221 *
222 * @return 選択リストで、ã?ルチã?キーセレクトを使用するかどã�?�‹(true:使用する) (false固å®?
223 */
224 public boolean useMultiSelect() {
225 return true;
226 }
227
228 /**
229 * オブジェクトã?キャãƒ?‚·ュが時間å?れかどã�?�‹を返しますã?
230 * キャãƒ?‚·ュが時間å?ã‚?無効)であれば、true をã?有効であればã€?
231 * false を返しますã?
232 *
233 * @og.rev 4.0.0.0 (2005/01/31) 新規作æ?
234 *
235 * @return キャãƒ?‚·ュが時間å?れなã‚?true
236 */
237 public boolean isTimeOver() {
238 return false;
239 }
240 }