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 */ 016package org.opengion.plugin.column; 017 018// import org.opengion.hayabusa.db.AbstractEditor; 019import org.opengion.hayabusa.db.CellEditor; 020import org.opengion.hayabusa.db.DBColumn; 021// import org.opengion.fukurou.util.XHTMLTag; 022import 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/** 028 * OCR2 エディターは tesseract.js を利用した カメラ映像 で取り込んだvideoを 029 * canvasにキャプチャしてから、文字に変換して、テキストエリアに書き出すクラスです。 030 * 031 * 基本的な構造は、カメラ映像描画開始ボタン、静止画キャプチャボタン、映像表示領域(video)、 032 * 静止画描画領域(canvas)、進捗(progressbar)、textarea で構成されます。 033 * 映像表示領域(video)でキャプチャすると、静止画を同じ場所に上書きします。もう一度押すと再度映像に切り替わります。 034 * textarea の name 以外は、固定です。よって、各ページに、1つしか設定できません。 035 * 036 * <button type="button" id="vidStart" onclick="videoStart()" >Video Start</button> 037 * <button type="button" id="capStart" onclick="capture()" >Capture</button><br> 038 * <div id="videotop" style="display:flex;" > 039 * <video id="player" autoplay style="background-color: black;position: absolute;z-index: 1;" ></video> 040 * <canvas id="snapshot" style="visibility: hidden;z-index: 2;' "></canvas> 041 * </div> 042 * <progress id="progressbar" max="1" value="0" > </progress><br> 043 * <textarea name="outdata" id="outdata" rows="10" cols="80" > </textarea> 044 * 045 * script に CDNサービス を使うと、無線環境(iPad等)ではものすごく遅くなったため、ローカルに配置することにします。 046 * <script src="https://unpkg.com/tesseract.js"><!-- --></script> 047 * 048 * script は、tesseract.min.js を使います。現在、1画面1つしかカメラは使えません。 049 * これらは、使用する画面に、組み込んでください。 050 * <script src="{@SYS.JSP}/common/option/tesseract.min.js"><!-- --></script> 051 * <script src="{@SYS.JSP}/common/option/videocamera.js"><!-- --></script> 052 * 053 * を使用するページに設定します。 054 * 055 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 056 * @og.rev 8.5.6.1 (2024/03/29) Editor_TEXTAREA を継承します。 057 * @og.group データ編集 058 * 059 * @version 7.4 060 * @author Kazuhiko Hasegawa 061 * @since JDK11.0, 062 */ 063// public class Editor_OCR2 extends AbstractEditor { 064public class Editor_OCR2 extends Editor_TEXTAREA { 065 /** このプログラムのVERSION文字列を設定します。 {@value} */ 066 private static final String VERSION = "8.5.6.1 (2024/03/29)" ; 067 068// // 7.4.2.2 (2021/05/28) システム定数のJSPを使用します。(※ SYS.JSP + SYS.IMAGE_DIR) 069// private static final String JSP_OPT = HybsSystem.sys( "JSP" ) + "/option/" ; 070 071// private static final String JS_SRC = "<script src='" + JSP_OPT + "tesseract.min.js' ><!-- --></script>" 072// + CR + "<script src='" + JSP_OPT + "videocamera.js' ><!-- --></script>" ; 073 074 // 8.5.3.0 (2023/09/08) HTML5廃止対応 progress要素から min='0' 削除 075 private static final String BASE_HTML = 076 "<button type='button' id='vidStart' onclick='videoStart()' >Video Start</button>" 077 + CR + "<button type='button' id='capStart' onclick='capture()' >Capture</button><br>" 078 + CR + "<div id='videotop' style='display:flex;' >" 079 + CR + " <video id='player' autoplay style='background-color: black;position: absolute;z-index: 1;' ></video>" 080 + CR + " <canvas id='snapshot' style='visibility: hidden;z-index: 2;' ></canvas>" 081 + CR + "</div>" 082 + CR + "<progress id='progressbar' max='1' value='0' > </progress><br>" ; 083 084// 8.5.6.1 (2024/03/29) 継承元と同じなので削除 085// /** 列1 */ protected String cols1; 086// /** 列2 */ protected String cols2; 087// /** 行1 */ protected String rows1; 088// /** 行2 */ protected String rows2; 089 090 /** 091 * デフォルトコンストラクター。 092 * このコンストラクターで、基本オブジェクトを作成します。 093 * 094 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 095 * 096 */ 097 public Editor_OCR2() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 098 099 /** 100 * コンストラクター。 101 * 102 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 103 * @og.rev 8.5.5.1 (2024/02/29) spotbugs CT_CONSTRUCTOR_THROW(コンストラクタで、Excweptionを出さない) 104 * @og.rev 8.5.6.1 (2024/03/29) 継承元と同じなので削除 105 * 106 * @param clm DBColumnオブジェクト 107 */ 108 protected Editor_OCR2( final DBColumn clm ) { 109 super( clm ); 110// final String disabled = clm.isWritable() ? null : "disabled" ; 111// 112// // 8.5.5.1 (2024/02/29) spotbugs CT_CONSTRUCTOR_THROW(コンストラクタで、Excweptionを出さない) 113//// final int r1 = clm.getTotalSize()/Integer.parseInt(size1) + 1; 114//// rows1 = String.valueOf( r1 ); 115//// 116//// final int r2 = clm.getTotalSize()/Integer.parseInt(size2) + 1; 117//// rows2 = String.valueOf( r2 ); 118// final int totalSize = clm.getTotalSize(); // 8.5.5.1 (2024/02/29) 119// rows1 = RowSizeUtil.getRowSize( totalSize,size1 ); // 8.5.5.1 (2024/02/29) 120// rows2 = RowSizeUtil.getRowSize( totalSize,size2 ); // 8.5.5.1 (2024/02/29) 121// 122// // size に、"rows,cols" を指定できるように変更 123// final String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 124// if( param != null && param.length() != 0 ) { 125// final int st = param.indexOf( ',' ); 126// if( st > 0 ) { 127// rows1 = param.substring( 0,st ); 128// rows2 = rows1; 129// cols1 = param.substring( st+1 ); 130// cols2 = cols1; 131// } 132// } 133// 134// // size1,size2 を使わずに、cols1,cols2 を使用。 135// if( cols1 == null || cols2 == null ) { 136// cols1 = size1 ; 137// cols2 = size2 ; 138// } 139// 140// // Attributesの連結記述 141// attributes = new Attributes() 142// .set( "disabled" , disabled ) 143// .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 144// .add( "class" , clm.getDbType() ); 145// 146// tagBuffer.add( XHTMLTag.textareaAttri( attributes ) ); 147 } 148 149 /** 150 * 各オブジェクトから自分のインスタンスを返します。 151 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 152 * まかされます。 153 * 154 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 155 * 156 * @param clm DBColumnオブジェクト 157 * @return CellEditorオブジェクト 158 * @og.rtnNotNull 159 */ 160 public CellEditor newInstance( final DBColumn clm ) { 161 return new Editor_OCR2( clm ); 162 } 163 164 /** 165 * データの編集用文字列を返します。 166 * 167 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 168 * @og.rev 8.5.6.1 (2024/03/29) Editor_TEXTAREA を継承します。 169 * 170 * @param value 入力値 171 * @return データの編集用文字列 172 * @og.rtnNotNull 173 */ 174 @Override 175 public String getValue( final String value ) { 176 // TagBufferの連結記述 177// return BASE_HTML 178// + new TagBuffer( "textarea" ) 179// .add( "name" , name ) 180// .add( "id" , "outdata" ) // ID 固定です。 181// .add( "cols" , cols2 ) ← 多分、cols1 の間違い 182// .add( "rows" , rows2 ) 183// .add( tagBuffer.makeTag() ) 184// .addBody( value ) 185// .makeTag(); 186 return BASE_HTML 187 + makeTagBuffer( name,cols1,rows1 ) 188 .add( "id" , "outdata" ) // ID 固定です。 189 .addBody( value ) 190 .makeTag(); 191 } 192 193 /** 194 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 195 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し、 196 * リクエスト情報を1つ毎のフィールドで処理できます。 197 * 198 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 199 * @og.rev 8.5.6.1 (2024/03/29) Editor_TEXTAREA を継承します。 200 * 201 * @param row 行番号 202 * @param value 入力値 203 * @return データ表示/編集用の文字列 204 * @og.rtnNotNull 205 */ 206 @Override 207 public String getValue( final int row,final String value ) { 208 final String newName = name + HybsSystem.JOINT_STRING + row; 209 210 // TagBufferの連結記述 211// return BASE_HTML 212// + new TagBuffer( "textarea" ) 213// .add( "name" , newName ) 214// .add( "id" , "outdata" ) // ID 固定です。 215// .add( "cols" , cols2 ) 216// .add( "rows" , rows2 ) 217// .add( tagBuffer.makeTag() ) 218// .addBody( value ) 219// .makeTag( row,value ); 220 return BASE_HTML 221 + makeTagBuffer( newName,cols2,rows2 ) 222 .add( "id" , "outdata" ) // ID 固定です。 223 .addBody( value ) 224 .makeTag( row,value ); 225 } 226}