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}