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.fukurou.util.StringUtil;
019 import org.opengion.fukurou.util.TagBuffer;
020 import org.opengion.hayabusa.common.HybsSystem;
021 import org.opengion.hayabusa.db.AbstractRenderer;
022 import org.opengion.hayabusa.db.CellRenderer;
023 import org.opengion.hayabusa.db.DBColumn;
024
025 /**
026 * TEXTAREA レン?は、カラ????タをテキストエリアで表示する場合に
027 * 使用するクラスです?
028 * readonlyの?ストエリアでclass=renderer-textareaとして出力し?
029 * name属?は付けません???タは送信されません)
030 * エリアの縦、横サイズはエ?タの?ストエリアと同様にして算?されます?
031 *
032 * カラ??表示に?な属?は, DBColumn オブジェク?より取り出します?
033 * こ?クラスは、DBColumn オブジェクト毎に?つ作?されます?
034 *
035 * @og.rev 4.3.5.7 (2009/03/22) 新規作?
036 * @og.group ??タ編?
037 *
038 * @version 4.0
039 * @author Takahashi Masakazu
040 * @since JDK5.0,
041 */
042 public class Renderer_TEXTAREA extends AbstractRenderer {
043 //* こ?プログラ??VERSION??を設定します? {@value} */
044 private static final String VERSION = "4.3.5.7 (2009/03/22)" ;
045
046 private final int COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_COLUMNS_MAXSIZE" ) ; // 表示フィールド?大きさ
047 // viewタグで表示する場合?カラ??大きさ
048 private final int VIEW_COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_VIEW_COLUMNS_MAXSIZE" ) ;
049
050 private final TagBuffer tagBuffer = new TagBuffer();
051
052 private String rows1;
053 private String rows2;
054 private String size1;
055 private String size2;
056
057 /**
058 * ?ォルトコンストラクター?
059 * こ?コンストラクターで、基本オブジェクトを作?します?
060 *
061 */
062 public Renderer_TEXTAREA() {
063 // 何もありません?super を呼び出しません)
064 }
065
066 /**
067 * コンストラクター
068 * textareaのサイズを決めるため、sizeとrowを決定す?
069 * editorの計算を移植?
070 *
071 * @param clm DBColumnオブジェク?
072 */
073 private Renderer_TEXTAREA( final DBColumn clm ) {
074 String size = clm.getViewLength();
075 int maxlength = clm.getTotalSize();
076
077 if( size != null ) {
078 if( size.indexOf( ',' ) >= 0 ) {
079 size = size.substring( 0, size.indexOf( ',' ) );
080 }
081 size1 = size;
082 size2 = size;
083 }
084 else {
085 size1 = String.valueOf( clm.getFieldSize( maxlength, COLUMNS_MAXSIZE ) );
086 size2 = String.valueOf( clm.getFieldSize( maxlength, VIEW_COLUMNS_MAXSIZE ) );
087 }
088
089 int r1 = ( clm.getTotalSize() / Integer.parseInt( size1 ) ) + 1;
090 if( r1 > 5 ) {
091 rows1 = "5";
092 }
093 else {
094 rows1 = String.valueOf( r1 );
095 }
096
097 int r2 = ( clm.getTotalSize() / Integer.parseInt( size2 ) ) + 1;
098 if( r2 > 5 ) {
099 rows2 = "5";
100 }
101 else {
102 rows2 = String.valueOf( r2 );
103 }
104
105 String param = StringUtil.nval( clm.getRendererParam(), clm.getViewLength() );
106 if( param != null && param.length() != 0 ) {
107 int st = param.indexOf( ',' );
108 if( st > 0 ) {
109 rows1 = param.substring( 0, st );
110 rows2 = rows1;
111 size1 = param.substring( st + 1 );
112 size2 = size1;
113 }
114 }
115 }
116
117 /**
118 * ?ブジェクトから???インスタンスを返します?
119 * 自??身をキャ?ュするのか?新たに作?するのか?、各サブクラスの実?
120 * まかされます?
121 *
122 * @param clm DBColumnオブジェク?
123 *
124 * @return CellEditorオブジェク?
125 */
126 public CellRenderer newInstance( final DBColumn clm ) {
127 return new Renderer_TEXTAREA( clm );
128 }
129
130 /**
131 * ??タの表示用??を返します?
132 *
133 * @param value 入力?
134 *
135 * @return ??タの表示用??
136 */
137 @Override
138 public String getValue( final String value ) {
139
140 TagBuffer tag = new TagBuffer( "textarea" );
141 tag.add( "cols" , size1 );
142 tag.add( "rows" , rows1 );
143 tag.add( "readonly", "readonly" );
144 tag.add( "class" , "renderer-textarea" );
145 tag.add( tagBuffer.makeTag() );
146 tag.setBody( value );
147
148 return tag.makeTag();
149 }
150
151 /**
152 * ??タの表示用??を返します?
153 *
154 * @param row 行番号
155 * @param value 入力?
156 *
157 * @return ??タ表示用の??
158 */
159 @Override
160 public String getValue( final int row,final String value ) {
161
162 TagBuffer tag = new TagBuffer( "textarea" );
163 tag.add( "cols" , size2 );
164 tag.add( "rows" , rows2 );
165 tag.add( "readonly", "readonly" );
166 tag.add( "class" , "renderer-textarea" );
167 tag.add( tagBuffer.makeTag() );
168 tag.setBody( value );
169
170 return tag.makeTag( row,value );
171 }
172 }