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.hayabusa.common.HybsSystemException;
020    import org.opengion.hayabusa.resource.CodeData;
021    
022    /**
023     * ãƒ??タのコード情報を取り扱ã�?‚¯ラスですã?
024     *
025     * コードã?キーとラベルのæƒ??から、HTMLのメニューã‚?ƒªストを作æ?するための オプション
026     * タグを作æ?したりã?与えられたキーをもとに、チェãƒ?‚¯済みのオプションタグを作æ?したã‚?
027     * しますã?
028     *
029     * @og.group 選択データ制御
030     *
031     * @version  4.0
032     * @author   Kazuhiko Hasegawa
033     * @since    JDK5.0,
034     */
035    public class Selection_RADIO implements Selection {
036            private final CodeData codeData ;
037    
038            /**
039             * コンストラクター
040             *
041             * @param       cdData  コードデータオブジェクãƒ?
042             *
043             */
044            public Selection_RADIO( final CodeData cdData ) {
045                    if( cdData == null ) {
046                            String errMsg = "コードリソースが定義されてã�?�¾せんã€? + HybsSystem.CR ;
047                            throw new HybsSystemException( errMsg );
048                    }
049    
050                    codeData = cdData ;
051            }
052    
053            /**
054             * 初期値が選択済みの 選択肢(オプション)を返しますã?
055             * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
056             * ※ こã?クラスでは実è£?�•れてã�?�¾せんã€?
057             *
058             * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機è?を指定すã‚?seqFlag を導å?
059             *
060             * @param       selectValue     選択されてã�?‚‹値
061             * @param       seqFlag         シーケンスアクセス機è?のæŒ?®?
062             *
063             * @return  オプションタグ
064             */
065            public String getOption( final String selectValue,final boolean seqFlag ) {
066                    String errMsg = "こã?クラスでは実è£?�•れてã�?�¾せんã€?;
067                    throw new UnsupportedOperationException( errMsg );
068            }
069    
070            /**
071             * 初期値が選択済みの 選択肢(オプション)を返しますã?
072             * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
073             * ※ こã?クラスでは実è£?�•れてã�?�¾せんã€?
074             *
075             * @og.rev 5.1.3.0 (2010/02/01) 追åŠ?
076             *
077             * @param       selectValue     選択されてã�?‚‹値
078             * @param       seqFlag シーケンスアクセス機è?のæŒ?®?
079             * @param       useShortLabel   短ラベルのæŒ?®?
080             *
081             * @return  オプションタグ
082             */
083            public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) {
084                    String errMsg = "こã?クラスでは実è£?�•れてã�?�¾せんã€?;
085                    throw new UnsupportedOperationException( errMsg );
086            }
087    
088            /**
089             * 初期値が選択済みの 選択肢(オプション)を返しますã?
090             * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
091             *
092             * @og.rev 2.1.0.1 (2002/10/17) 選択リストを、正方向にしか選べなã�?‚ˆã�?�«する sequenceFlag を導å?する
093             * @og.rev 3.5.6.3 (2004/07/12) キャãƒ?‚·ュを利用せず毎回タグを作æ?しますã?
094             * @og.rev 3.8.6.0 (2006/09/29) useLabel 属æ? 追åŠ?
095             *
096             * @param   name         ラジオの name
097             * @param   selectValue  選択されてã�?‚‹値
098             * @param   useLabel     ラベル表示の有無 [true:æœ?false:無]
099             *
100             * @return  オプションタグ
101             */
102            public String getRadio( final String name,final String selectValue,final boolean useLabel ) {
103                    String inputTag = "<input type=\"radio\" name=\"" + name + "\" value=\"" ;
104                    StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_LARGE );
105                    int size = codeData.getSize();
106                    for( int i=0; i<size; i++ ) {
107                            String value = codeData.getCodeKey(i);
108                            if( useLabel ) { buf.append( "<label>" ); }
109                            buf.append( inputTag ).append( value ).append( "\"" );
110                            if( value.equals( selectValue ) ) {
111                                    buf.append( " checked=\"checked\"" );
112                            }
113                            buf.append( "/>" );
114                            if( useLabel ) { buf.append( codeData.getShortLabel(i) ).append( "</label>" ); }
115                    }
116                    return buf.toString();
117            }
118    
119            /**
120             * 選択肢(value)に対するラベルを返しますã?
121             * 選択肢(value)がã?存在しなかったå?合ã?ã€?�¸択肢そã?もã?を返しますã?
122             * getValueLabel( XX ) は、getValueLabel( XX,false ) と同じですã?
123             *
124             * @param   selectValue 選択肢の値
125             *
126             * @return  選択肢のラベル
127             * @see     #getValueLabel( String,boolean )
128             */
129            public String getValueLabel( final String selectValue ) {
130                    return getValueLabel( selectValue,false );
131            }
132    
133            /**
134             * 選択肢(value)に対するラベルを返しますã?
135             * 選択肢(value)がã?存在しなかったå?合ã?ã€?�¸択肢そã?もã?を返しますã?
136             * こã?メソãƒ?ƒ‰では、短縮ラベルを返すかどã�?�‹を指定するフラグを指定しますã?
137             * getValueLabel( XX,false ) は、getValueLabel( XX ) と同じですã?
138             *
139             * @og.rev 4.0.0.0 (2005/11/30) を追åŠ?
140             *
141             * @param       selectValue     選択肢の値
142             * @param       flag    短縮ラベルを使用する [true:使用する/false:しない]
143             *
144             * @return  選択肢のラベル
145             * @see     #getValueLabel( String )
146             */
147            public String getValueLabel( final String selectValue,final boolean flag ) {
148                    // マッチするアドレスを探すã?
149                    int selected = codeData.getAddress( selectValue );
150    
151                    if( selected < 0 ) {
152                            // マッチしなければã€?�¸択肢そã?もã?を返すã€?
153                            return selectValue;
154                    }
155                    else {
156                            if( flag ) {
157                                    return codeData.getShortLabel(selected);
158                            }
159                            else {
160                                    return codeData.getLongLabel(selected);
161                            }
162                    }
163            }
164    
165            /**
166             * 選択肢(value)に対するラベルを返しますã?
167             * 選択肢(value)がã?存在しなかったå?合ã?ã€?�¸択肢そã?もã?を返しますã?
168             * getValueLabel( XX ) は、getValueLabel( XX,false ) と同じですã?
169             *
170             * @param   selectValue 選択肢の値
171             *
172             * @return  選択肢のラベル
173             * @see     #getValueLabel( String,boolean )
174             */
175            public String getRadioLabel( final String selectValue ) {
176    
177                    StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
178                    int size = codeData.getSize();
179                    for( int i=0; i<size; i++ ) {
180                            String value = codeData.getCodeKey(i);
181                            if( value.equals( selectValue ) ) {
182                                    rtn.append( "â—? );                      // (2003/10/08 修正åˆ?
183                            }
184                            else {
185                                    rtn.append( "ã€? );                      // (2003/10/08 修正åˆ?
186                            }
187                    }
188    
189                    return rtn.toString();
190            }
191    
192            /**
193             * マルチã?キーセレクトを使用するかどã�?�‹を返しますã?
194             * true?š使用する。false:使用しなã�?ですã?
195             * ただしã?実際に使用するかどã�?�‹は、HTML出力時に決めることがå?来ますã?
196             * ここでは、USE_MULTI_KEY_SELECT ã�?true で、USE_SIZE(=20)以上ã?場合に
197             * true を返しますã?
198             *
199             * @og.rev 3.5.5.7 (2004/05/10) 新規作æ?
200             *
201             * @return  選択リストで、ã?ルチã?キーセレクトを使用するかどã�?�‹(true:使用する)
202             */
203            public boolean useMultiSelect() {
204                    return false;
205            }
206    
207            /**
208             * オブジェクトã?キャãƒ?‚·ュが時間å?れかどã�?�‹を返しますã?
209             * キャãƒ?‚·ュが時間å?ã‚?無効)であれば、true をã?有効であればã€?
210             * false を返しますã?
211             *
212             * @og.rev 4.0.0.0 (2005/01/31) 新規作æ?
213             *
214             * @return  キャãƒ?‚·ュが時間å?れなã‚?true
215             */
216            public boolean isTimeOver() {
217                    return false;
218            }
219    }