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    public class Selection_RADIO extends Selection_NULL {
037            private final CodeData codeData ;
038    
039            /**
040             * コンストラクター
041             *
042             * @param       cdData  コードデータオブジェク�
043             *
044             */
045            public Selection_RADIO( final CodeData cdData ) {
046                    if( cdData == null ) {
047                            String errMsg = "コードリソースãŒå®šç¾©ã•れã¦ã?¾ã›ã‚“ã€? + HybsSystem.CR ;
048                            throw new HybsSystemException( errMsg );
049                    }
050    
051                    codeData = cdData ;
052            }
053    
054            /**
055             * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã?
056             * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã?
057             * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?
058             *
059             * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機è?を指定ã™ã‚?seqFlag ã‚’å°Žå?
060             * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤
061             *
062             * @param       selectValue     é¸æŠžã•れã¦ã?‚‹å€¤
063             * @param       seqFlag         シーケンスアクセス機è?ã®æŒ?®?
064             *
065             * @return  オプションタグ
066             */
067    //      public String getOption( final String selectValue,final boolean seqFlag ) {
068    //              String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?;
069    //              throw new UnsupportedOperationException( errMsg );
070    //      }
071    
072            /**
073             * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã?
074             * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã?
075             * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?
076             *
077             * @og.rev 5.1.3.0 (2010/02/01) 追�
078             *
079             * @param       selectValue     é¸æŠžã•れã¦ã?‚‹å€¤
080             * @param       seqFlag シーケンスアクセス機è?ã®æŒ?®?
081             * @param       useShortLabel   çŸ­ãƒ©ãƒ™ãƒ«ã®æŒ?®?
082             *
083             * @return  オプションタグ
084             */
085            @Override
086            public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) {
087                    String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?;
088                    throw new UnsupportedOperationException( errMsg );
089            }
090    
091            /**
092             * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã?
093             * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã?
094             *
095             * @og.rev 2.1.0.1 (2002/10/17) é¸æŠžãƒªã‚¹ãƒˆã‚’ã€æ­£æ–¹å‘ã«ã—ã‹é¸ã¹ãªã?‚ˆã?«ã™ã‚‹ sequenceFlag ã‚’å°Žå?ã™ã‚‹
096             * @og.rev 3.5.6.3 (2004/07/12) キャãƒ?‚·ãƒ¥ã‚’利用ã›ãšæ¯Žå›žã‚¿ã‚°ã‚’ä½œæ?ã—ã¾ã™ã?
097             * @og.rev 3.8.6.0 (2006/09/29) useLabel 属æ? 追åŠ?
098             *
099             * @param   name         ラジオ㮠name
100             * @param   selectValue  é¸æŠžã•れã¦ã?‚‹å€¤
101             * @param   useLabel     ãƒ©ãƒ™ãƒ«è¡¨ç¤ºã®æœ‰ç„¡ [true:æœ?false:ç„¡]
102             *
103             * @return  オプションタグ
104             */
105            @Override
106            public String getRadio( final String name,final String selectValue,final boolean useLabel ) {
107                    String inputTag = "<input type=\"radio\" name=\"" + name + "\" value=\"" ;
108                    StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_LARGE );
109                    int size = codeData.getSize();
110                    for( int i=0; i<size; i++ ) {
111                            String value = codeData.getCodeKey(i);
112                            if( useLabel ) { buf.append( "<label>" ); }
113                            buf.append( inputTag ).append( value ).append( "\"" );
114                            if( value.equals( selectValue ) ) {
115                                    buf.append( " checked=\"checked\"" );
116                            }
117                            buf.append( "/>" );
118                            if( useLabel ) { buf.append( codeData.getShortLabel(i) ).append( "</label>" ); }
119                    }
120                    return buf.toString();
121            }
122    
123            /**
124             * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã?
125             * é¸æŠžè‚¢(value)ãŒã?存在ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã?
126             * getValueLabel( XX ) ã¯ã€getValueLabel( XX,false ) ã¨åŒã˜ã§ã™ã?
127             *
128             * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤
129             *
130             * @param   selectValue é¸æŠžè‚¢ã®å€¤
131             *
132             * @return  é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ«
133             * @see     #getValueLabel( String,boolean )
134             */
135    //      public String getValueLabel( final String selectValue ) {
136    //              return getValueLabel( selectValue,false );
137    //      }
138    
139            /**
140             * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã?
141             * é¸æŠžè‚¢(value)ãŒã?存在ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã?
142             * ã“ã?メソãƒ?ƒ‰ã§ã¯ã€çŸ­ç¸®ãƒ©ãƒ™ãƒ«ã‚’è¿”ã™ã‹ã©ã?‹ã‚’指定ã™ã‚‹ãƒ•ラグを指定ã—ã¾ã™ã?
143             * getValueLabel( XX,false ) ã¯ã€getValueLabel( XX ) ã¨åŒã˜ã§ã™ã?
144             *
145             * @og.rev 4.0.0.0 (2005/11/30) を追�
146             *
147             * @param       selectValue     é¸æŠžè‚¢ã®å€¤
148             * @param       flag    短縮ラベルを使用ã™ã‚‹ [true:使用ã™ã‚‹/false:ã—ãªã„]
149             *
150             * @return  é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ«
151             * @see     #getValueLabel( String )
152             */
153            @Override
154            public String getValueLabel( final String selectValue,final boolean flag ) {
155                    // マッãƒã™ã‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’探ã™ã?
156                    int selected = codeData.getAddress( selectValue );
157    
158                    if( selected < 0 ) {
159                            // マッãƒã—ãªã‘れã°ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã™ã€?
160                            return selectValue;
161                    }
162                    else {
163                            if( flag ) {
164                                    return codeData.getShortLabel(selected);
165                            }
166                            else {
167                                    return codeData.getLongLabel(selected);
168                            }
169                    }
170            }
171    
172            /**
173             * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã?
174             * é¸æŠžè‚¢(value)ãŒã?存在ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã?
175             * getValueLabel( XX ) ã¯ã€getValueLabel( XX,false ) ã¨åŒã˜ã§ã™ã?
176             *
177             * @param   selectValue é¸æŠžè‚¢ã®å€¤
178             *
179             * @return  é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ«
180             * @see     #getValueLabel( String,boolean )
181             */
182            @Override
183            public String getRadioLabel( final String selectValue ) {
184    
185                    StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
186                    int size = codeData.getSize();
187                    for( int i=0; i<size; i++ ) {
188                            String value = codeData.getCodeKey(i);
189                            if( value.equals( selectValue ) ) {
190                                    rtn.append( "� );                      // (2003/10/08 修正�
191                            }
192                            else {
193                                    rtn.append( "� );                      // (2003/10/08 修正�
194                            }
195                    }
196    
197                    return rtn.toString();
198            }
199    
200            /**
201             * マルãƒã?キーセレクトを使用ã™ã‚‹ã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã?
202             * true?šä½¿ç”¨ã™ã‚‹ã€‚false:使用ã—ãªã?ã§ã™ã?
203             * ãŸã ã—ã?実際ã«ä½¿ç”¨ã™ã‚‹ã‹ã©ã?‹ã¯ã€HTMLå‡ºåŠ›æ™‚ã«æ±ºã‚ã‚‹ã“ã¨ãŒå?æ¥ã¾ã™ã?
204             * ã“ã“ã§ã¯ã€USE_MULTI_KEY_SELECT ã?true ã§ã€USE_SIZE(=20)以上ã?å ´åˆã«
205             * true ã‚’è¿”ã—ã¾ã™ã?
206             *
207             * @og.rev 3.5.5.7 (2004/05/10) æ–°è¦ä½œæ?
208             * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤
209             *
210             * @return  é¸æŠžãƒªã‚¹ãƒˆã§ã€ã?ルãƒã?キーセレクトを使用ã™ã‚‹ã‹ã©ã?‹(true:使用ã™ã‚‹)
211             */
212    //      public boolean useMultiSelect() {
213    //              return false;
214    //      }
215    
216            /**
217             * オブジェクトã?キャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã?
218             * キャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?ã‚?無効)ã§ã‚れã°ã€true ã‚’ã?有効ã§ã‚れã°ã€?
219             * false ã‚’è¿”ã—ã¾ã™ã?
220             *
221             * @og.rev 4.0.0.0 (2005/01/31) æ–°è¦ä½œæ?
222             * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤
223             *
224             * @return  キャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れãªã‚?true
225             */
226    //      public boolean isTimeOver() {
227    //              return false;
228    //      }
229    }