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.plugin.column;
017
018 import org.opengion.hayabusa.db.AbstractEditor;
019 import org.opengion.hayabusa.db.CellEditor;
020 import org.opengion.hayabusa.db.DBColumn;
021 import org.opengion.fukurou.util.XHTMLTag;
022 import org.opengion.hayabusa.common.HybsSystem;
023 import org.opengion.fukurou.util.Attributes;
024 import org.opengion.fukurou.util.StringUtil;
025 import org.opengion.fukurou.util.TagBuffer;
026
027 import java.util.StringTokenizer ;
028
029 /**
030 * AUTOAREA エãƒ?‚£ã‚¿ãƒ¼ã¯ã€ã‚«ãƒ©ãƒ??ãƒ??タをテã‚ストエリアã§ç·¨é›?™ã‚‹å?åˆã«
031 * 使用ã™ã‚‹ã‚¯ãƒ©ã‚¹ã§ã™ã?
032 *
033 * エリアã®å¤§ãã•ã¯ã€è¡¨ç¤ºã™ã‚‹æ–?—å?ã«ã‚ˆã£ã¦ã€è?å‹•çš„ã«å¤‰æ›´ã•れã¾ã™ã?
034 * åˆæœŸå€¤ã‚??æ–?—æ•°ãŒå°ã•ã??åˆã?サイズã¯ã€ãƒ‡ãƒ•ォルトå?を使用ã™ã‚‹ã‹ã?
035 * ç·¨é›?ƒ‘ラメータã«ã€x,yå½¢å¼ã§æŒ?®šã•れãŸå€¤ã‚’使ã?¾ã™ã?
036 * 列方å‘ã§ã®æœ?¤§æ¡æ•°ã‚’ã?æŒ?®šã™ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã™ã?シスãƒ?ƒ パラメータã§
037 * HTML_AUTOAREA_MAX_COL_SIZE を指定ã™ã‚‹ã“ã¨ã§ã€æŠ˜ã‚Šè¿”ã—列数ã®èª¿æ•´ã‚?
038 * åŒæ™‚ã«è¡Œã‚れã¾ã™ã?0 ãŒæŒ‡å®šã•れãŸå ´åˆã?ã€ç„¡åˆ¶é™ã«ãªã‚Šã¾ã™ã?
039 * HTML_AUTOAREA_MAX_ROW_SIZE を指定ã™ã‚‹ã“ã¨ã§ã€è¡Œæ•°ã®æœ?¤§å€¤ã‚?
040 * æŒ?®šã™ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã™ã?0 ãŒæŒ‡å®šã•れãŸå ´åˆã?ã€ç„¡åˆ¶é™ã«ãªã‚Šã¾ã™ã?
041 * ç·¨é›?ƒ‘ラメータã¯ã€ã?è¡?列ã?æŒ?®šå¯èƒ½ã§ã™ã?例ãˆã°ã€?,10 ã¨ã™ã‚‹ã¨ã€?¼•行1ï¼å?ã®
042 * ãƒ?‚ストエリアを最å°ç¯?›²ã¨ã—ã¦è¨å®šã§ãã¾ã™ã?
043 * åˆæœŸå€¤ã¯ã€HTML_COLUMS_MAXSIZE ã§æŒ?®šã?列数ã¨ã€å®šç¾©ã•れã¦ã?‚‹ãƒ??タサイズ
044 * 割ã‚?HTML_COLUMS_MAXSIZE ã§ã€?¼•ã‚’è¶?ˆãªã??ã‚’ã?行数ã¨ã—ã¦ã?¾ã™ã?
045 * ç·¨é›?ƒ‘ラメータã®ã€ã?è¡?列ã?æŒ?®šã§ã€åŒæ™‚ã«ã€æœ€å¤§è¡Œå?æ•°ã®æŒ?®šã‚‚å¯èƒ½ã§ã™ã?
046 * 5-10,15-20 ã¨ã™ã‚‹ã¨ã€æœ€å°ï¼•è¡Œï¼æœ€å¤§?‘ï¼è¡Œã§ã€æœ€å°ï¼‘5å??最大?’ï¼å?ã®
047 * ãƒ?‚ストエリアを指定ã§ãã¾ã™ã?ç·¨é›?ƒ‘ラメータã§ã®æœ?¤§å€¤æŒ?®šã?ã€?
048 * シスãƒ?ƒ パラメータã§ã®æœ?¤§å€¤æŒ?®šã‚ˆã‚Šã?優先ã•れã¾ã™ã?
049 *
050 * ã“ã?エãƒ?‚£ã‚¿ãƒ¼ã§ã¯ã€ã‚«ãƒ©ãƒ??å†?®¹ã«å¿œã˜ã¦ã€æ›¸è¾¼ã¿ç¦æ¢å±žæ?を強制çš?«ä»˜ä¸Žã™ã‚?
051 * 事もå¯èƒ½ã§ã™ã?
052 * value (æ¤œç´¢çµæžœ)ã®å…ˆé??‘æ–‡å—ç›®ãŒã?アンãƒ??ãƒã?(_) ã®å ´åˆã?ã€?
053 * ç·¨é›?ƒ¢ãƒ¼ãƒ‰ã«ãªã‚Šã¾ã›ã‚“ã€?èªå–専用)
054 * ãƒ??タベã?ã‚¹ã«æ›¸ãè¾¼ã‚?¨ãã«ã¯ã€??常ã®ã‚¢ãƒ³ãƒ??ãƒã?ç„¡ã—ã?æ–?—å?ã«å¤‰æ›ã—ã¦ç™»éŒ²ã—ã¾ã™ã?
055 *
056 * カラãƒ??表示ã«å¿?¦ãªå±žæ?ã¯, DBColumn オブジェクãƒ?よりå–り出ã—ã¾ã™ã?
057 * ã“ã?クラスã¯ã€DBColumn オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã?
058 *
059 * @og.rev 3.8.0.2 (2005/06/30) æ–°è¦è¿½åŠ??
060 * @og.group �?タ編�
061 *
062 * @version 4.0
063 * @author Kazuhiko Hasegawa
064 * @since JDK5.0,
065 */
066 public class Editor_AUTOAREA extends AbstractEditor {
067 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */
068 private static final String VERSION = "5.1.7.0 (2010/06/01)" ;
069
070 private static final int COL = 0 ;
071 private static final int ROW = 1 ;
072 private static final String CODE = "Windows-31J";
073
074 private int cols1 = 0 ;
075 private int cols2 = 0 ;
076 private int rows1 = 0 ;
077 private int rows2 = 0 ;
078 private int maxColSize = HybsSystem.sysInt( "HTML_AUTOAREA_MAX_COL_SIZE" );
079 private int maxRowSize = HybsSystem.sysInt( "HTML_AUTOAREA_MAX_ROW_SIZE" );
080
081 /**
082 * ãƒ?ƒ•ォルトコンストラクターã€?
083 * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã?
084 *
085 */
086 public Editor_AUTOAREA() {
087 // 4.3.4.4 (2009/01/01)
088 // super();
089 }
090
091 /**
092 * コンストラクター�
093 *
094 * @param clm DBColumnオブジェク�
095 */
096 private Editor_AUTOAREA( final DBColumn clm ) {
097 super( clm );
098 String disabled = clm.isWritable() ? null : "disabled" ;
099
100 int r1 = (clm.getTotalSize()/Integer.parseInt(size1)) + 1; // 4.0.0 (2005/01/31) メソãƒ?ƒ‰å変更
101 if( r1 > 5 ) { rows1 = 5; }
102 else { rows1 = r1; }
103
104 int r2 = (clm.getTotalSize()/Integer.parseInt(size2)) + 1; // 4.0.0 (2005/01/31) メソãƒ?ƒ‰å変更
105 if( r2 > 5 ) { rows2 = 5; }
106 else { rows2 = r2; }
107
108 // 3.8.0.2 (2005/07/11) size ã«ã€?rows-maxRow,cols-maxCols" を指å®?
109 String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() );
110 if( param != null && param.length() != 0 ) {
111 int prmAdrs = param.indexOf( ',' );
112 if( prmAdrs > 0 ) {
113 String rowStr = param.substring( 0,prmAdrs );
114 String colStr = param.substring( prmAdrs+1 );
115
116 int rowAdrs = rowStr.indexOf( '-' ); // rows-maxRow è¨å®šæ™‚ '-' ãŒãªã‘れã°ã€ãŸã??rows
117 if( rowAdrs > 0 ) {
118 rows1 = Integer.parseInt( rowStr.substring( 0,rowAdrs ) );
119 maxRowSize = Integer.parseInt( rowStr.substring( rowAdrs+1 ) );
120 }
121 else {
122 rows1 = Integer.parseInt( rowStr );
123 }
124 rows2 = rows1 ;
125
126 int colAdrs = colStr.indexOf( '-' ); // cols-maxCols è¨å®šæ™‚ '-' ãŒãªã‘れã°ã€ãŸã??cols
127 if( colAdrs > 0 ) {
128 cols1 = Integer.parseInt( colStr.substring( 0,colAdrs ) );
129 maxColSize = Integer.parseInt( colStr.substring( colAdrs+1 ) );
130 }
131 else {
132 cols1 = Integer.parseInt( colStr );
133 }
134 cols2 = cols1;
135 }
136 }
137
138 attributes = new Attributes();
139 attributes.set( "disabled" ,disabled );
140
141 attributes.addAttributes( clm.getEditorAttributes() );
142 attributes.add( "class" ,clm.getDbType() ); // 4.0.0 (2005/01/31)
143
144 optAttr = attributes.get( "optionAttributes" );
145 tagBuffer.add( XHTMLTag.textareaAttri( attributes ) );
146 }
147
148 /**
149 * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã?
150 * 自åˆ??身をã‚ャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?«
151 * ã¾ã‹ã•れã¾ã™ã?
152 *
153 * @param clm DBColumnオブジェク�
154 *
155 * @return CellEditorオブジェク�
156 */
157 public CellEditor newInstance( final DBColumn clm ) {
158 return new Editor_AUTOAREA( clm );
159 }
160
161 /**
162 * ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?—å?ã‚’è¿”ã—ã¾ã™ã?
163 *
164 * @og.rev 4.3.7.2 (2009/06/15) 属æ?ã§idãŒå?力ã•ã‚Œã‚‹å ´åˆã?ã€idã‚’å?力ã—ãªã?
165 * @og.rev 5.1.2.0 (2010/01/01) å…ˆé?ã®'_'ã«ã‚ˆã‚‹æ›¸ãè¾¼ã¿åˆ¶å¾¡ã‚’行ã‚ãªã??(ä»–ã?クラスã¨ã®å®Ÿè£??共通化)
166 * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ãƒ³å®Ÿè£?¦‹ç›´ã?
167 *
168 * @param value 値
169 *
170 * @return ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?—å?
171 */
172 @Override
173 public String getValue( final String value ) {
174 // if( value != null && value.length() >= 1 && value.charAt(0) == '_' ) {
175 // return value.substring( 1 );
176 // }
177
178 int[] rowcol = getRowsCols( value,cols1,rows1 );
179
180 TagBuffer tag = new TagBuffer( "textarea" );
181 tag.add( "name" , name );
182 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
183 tag.add( "id" , name ); // 4.3.6.0 (2009/04/01)
184 }
185 tag.add( "cols" , String.valueOf( rowcol[COL] ) );
186 tag.add( "rows" , String.valueOf( rowcol[ROW] ) );
187 if( maxRowSize > 0 ) {
188 tag.add( "onKeyup" ,"autoArea( this," + maxRowSize + " );" );
189 }
190 else {
191 tag.add( "onKeyup" ,"autoArea( this );" );
192 }
193 tag.add( tagBuffer.makeTag() );
194 tag.add( optAttr ); // 3.5.5.8 (2004/05/20)
195 tag.setBody( value );
196
197 return tag.makeTag();
198 // return tag.makeTag() + createEventColumnJS( name, editor, -1, eventURL ); // 4.3.6.0 (2009/04/01)
199 }
200
201 /**
202 * name属æ?を変ãˆãŸã?ãƒ??タ表示/ç·¨é›?”¨ã®HTMLæ–?—å?を作æ?ã—ã¾ã™ã?
203 * ãƒ??ブル上ã? name 㫠行番å·ã‚’ä»˜åŠ ã—ã¦ã€åå‰_è¡Œç•ªå· ã§ç™»éŒ²ã™ã‚‹ã‚ーを作æ?ã?
204 * ãƒªã‚¯ã‚¨ã‚¹ãƒˆæƒ…å ±ã‚’ï¼‘ã¤æ¯Žã?フィールドã§å‡¦ç?§ãã¾ã™ã?
205 *
206 * @og.rev 4.3.7.2 (2009/06/15) 属æ?ã§idãŒå?力ã•ã‚Œã‚‹å ´åˆã?ã€idã‚’å?力ã—ãªã?
207 * @og.rev 5.1.2.0 (2010/01/01) å…ˆé?ã®'_'ã«ã‚ˆã‚‹æ›¸ãè¾¼ã¿åˆ¶å¾¡ã‚’行ã‚ãªã??(ä»–ã?クラスã¨ã®å®Ÿè£??共通化)
208 * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ãƒ³å®Ÿè£?¦‹ç›´ã?
209 *
210 * @param row 行番å·
211 * @param value 値
212 *
213 * @return ãƒ??タ表示/ç·¨é›?”¨ã®æ–?—å?
214 */
215 @Override
216 public String getValue( final int row,final String value ) {
217 // if( value != null && value.length() >= 1 && value.charAt(0) == '_' ) {
218 // return value.substring( 1 );
219 // }
220
221 int[] rowcol = getRowsCols( value,cols2,rows2 );
222
223 TagBuffer tag = new TagBuffer( "textarea" );
224 String newName = name + HybsSystem.JOINT_STRING + row;
225 // tag.add( "name" , name + HybsSystem.JOINT_STRING + row );
226 tag.add( "name" , newName );
227 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
228 tag.add( "id" , newName ); // 4.3.6.0 (2009/04/01)
229 }
230 tag.add( "cols" , String.valueOf( rowcol[COL] ) );
231 tag.add( "rows" , String.valueOf( rowcol[ROW] ) );
232 if( maxRowSize > 0 ) {
233 tag.add( "onKeyup" ,"autoArea( this," + maxRowSize + " );" );
234 }
235 else {
236 tag.add( "onKeyup" ,"autoArea( this );" );
237 }
238 tag.add( tagBuffer.makeTag() );
239 tag.add( optAttr ); // 3.5.5.8 (2004/05/20)
240 tag.setBody( value );
241
242 return tag.makeTag( row,value );
243 // return tag.makeTag( row,value ) + createEventColumnJS( name, editor, row, eventURL ); //4 3.6.0 (2009/04/01)
244 }
245
246 /**
247 * 自動表示ã™ã‚‹è¡Œå?ã®æ•°ã‚’求ã‚ã¾ã™ã?
248 * 行数ã¯ã€å¼•æ•°ã®æ–?—å?ä¸ã«å«ã¾ã‚Œã‚‹ 改行コードã?個数を求ã‚ã¾ã™ã?
249 * 列数ã¯ã€å„行数ã®ãªã‹ã?æœ?¤§æ¡æ•°ã‚ˆã‚Šæ±‚ã‚ã¾ã™ã?ã“れã«ã¯åŠè§’ã?全角ãŒå«ã¾ã‚Œã‚‹ç‚ºã€?
250 * åŠè§’æ›ç®—ã§ã®æ–?—æ•°ã¨ã?†ã“ã¨ã«ãªã‚Šã¾ã™ã?
251 * 行数ã¨åˆ—æ•°ãŒã?åˆæœŸè¨å®šã?行数ã¨åˆ—数よりå°ã•ã??åˆã?ã€å?期è¨å®šå?ãŒä½¿ç”¨ã•れã¾ã™ã?
252 *
253 * @param value 表示æ–?—å?
254 * @param cols æœ?°ã‚«ãƒ©ãƒ?•°
255 * @param rows æœ?°è¡Œæ•°
256 *
257 * @return 自動計算ã—ãŸè¡Œå?ã®é…å?
258 */
259 private int[] getRowsCols( final String value,final int cols, final int rows ) {
260 if( value == null ) {
261 return new int[] { rows,cols };
262 }
263
264 StringTokenizer token = new StringTokenizer( value, "\n", true );
265
266 int cntRow = 1;
267 int maxCol = 0;
268 while ( token.hasMoreTokens() ) {
269 String val = token.nextToken();
270 if( "\n".equals( val ) ) { cntRow++; }
271 else {
272 byte[] byteValue = StringUtil.makeByte( val,CODE ); // 3.5.5.3 (2004/04/09)
273 int byteSize = byteValue.length;
274 if( maxColSize > 0 && byteSize > maxColSize ) { // æœ?¤§åˆ—æ•°
275 cntRow += (byteSize / maxColSize);
276 maxCol = maxColSize ;
277 }
278 else if( byteSize > maxCol ) { maxCol = byteSize; }
279 }
280 if( maxRowSize > 0 && cntRow >= maxRowSize ) { // æœ?¤§è¡Œæ•°
281 cntRow = maxRowSize;
282 break;
283 }
284 }
285
286 maxCol += 2; // マã?ジン。フォントや画é¢ã‚µã‚¤ã‚ºã«å½±éŸ¿ã™ã‚‹ç‚ºã€æ¯”率ã®ã»ã?Œã‚ˆã„??
287
288 int[] rtn = new int[2];
289 rtn[ROW] = (rows<cntRow) ? cntRow : rows ;
290 rtn[COL] = (cols<maxCol) ? maxCol : cols ;
291
292 return rtn ;
293 }
294 }