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 018import org.opengion.hayabusa.db.AbstractEditor; 019import org.opengion.hayabusa.db.CellEditor; 020import org.opengion.hayabusa.db.DBColumn; 021import org.opengion.fukurou.util.XHTMLTag; 022import org.opengion.hayabusa.common.HybsSystem; 023import org.opengion.fukurou.util.Attributes; 024import org.opengion.fukurou.util.StringUtil; 025import org.opengion.fukurou.util.TagBuffer; 026 027/** 028 * QRCODE エディターは、jsQR.js を利用した、カメラ映像からQRコードを読み込むクラスです。 029 * 読み込んだ文字列は テキストエリアに書き出します。 030 * 031 * 基本的な構造は、カメラ映像描画開始ボタン、映像表示領域(video)、textarea で構成されます。 032 * 映像表示領域(video)に、有効なQRコードが表示されると、スキャンを停止して、テキストエリアに 033 * 文字列を表示します。現在は、5秒後に、再スキャンを始めます。その際に、なにかQRコードが見つかると 034 * 新しいコードに書き換えます。 035 * 036 * <button type='button' id='vidStart' onClick='videoStart();qrScan();'>Video Start</button> 037 * <video id='player' autoplay style='background-color: black;'></video> 038 * <textarea name='≪カラム名≫' id='outdata' rows='10'cols='80'> </textarea> 039 * 040 * script に CDNサービス を使うと、無線環境(iPad等)ではものすごく遅くなったため、ローカルに配置することにします。 041 * <script src="https://cdn.jsdelivr.net/npm/jsqr@latest/dist/jsQR.min.js"><!-- --></script> 042 * 043 * script は、jsQR.min.js を使います。現在、1画面1つしかカメラは使えません。 044 * これらは、使用する画面に、組み込んでください。 045 * <script src="{@SYS.JSP}/option/jsQR.min.js"><!-- --></script> 046 * <script src="{@SYS.JSP}/option/videocamera.js"><!-- --></script> 047 * 048 * を使用するページに設定します。 049 * 050 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 051 * @og.group データ編集 052 * 053 * @version 7.4 054 * @author Kazuhiko Hasegawa 055 * @since JDK11.0, 056 */ 057public class Editor_QRCODE extends AbstractEditor { 058 /** このプログラムのVERSION文字列を設定します。 {@value} */ 059 private static final String VERSION = "7.4.2.1 (2021/05/21)" ; 060 061// // 7.4.2.2 (2021/05/28) システム定数のJSPを使用します。(※ SYS.JSP + SYS.IMAGE_DIR) 062// private static final String JSP_OPT = HybsSystem.sys( "JSP" ) + "/option/" ; 063 064// private static final String JS_SRC = "<script src='" + JSP_OPT + "jsQR.min.js' ><!-- --></script>" 065// + CR + "<script src='" + JSP_OPT + "videocamera.js' ><!-- --></script>" ; 066 067 private static final String BASE_HTML = 068 "<button type='button' id='vidStart' onClick='videoStart();qrScan();'>Video Start</button><br />" 069 + CR + "<video id='player' autoplay style='background-color: black;'></video>" ; 070 071 /** 列1 */ protected String cols1 ; 072 /** 列2 */ protected String cols2 ; 073 /** 行1 */ protected String rows1 ; 074 /** 行2 */ protected String rows2 ; 075 076 /** 077 * デフォルトコンストラクター。 078 * このコンストラクターで、基本オブジェクトを作成します。 079 * 080 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 081 * 082 */ 083 public Editor_QRCODE() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 084 085 /** 086 * コンストラクター。 087 * 088 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 089 * 090 * @param clm DBColumnオブジェクト 091 */ 092 protected Editor_QRCODE( final DBColumn clm ) { 093 super( clm ); 094 final String disabled = clm.isWritable() ? null : "disabled" ; 095 096 final int r1 = clm.getTotalSize()/Integer.parseInt(size1) + 1; 097 rows1 = String.valueOf( r1 ); 098 099 final int r2 = clm.getTotalSize()/Integer.parseInt(size2) + 1; 100 rows2 = String.valueOf( r2 ); 101 102 // size に、"rows,cols" を指定できるように変更 103 final String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 104 if( param != null && param.length() != 0 ) { 105 final int st = param.indexOf( ',' ); 106 if( st > 0 ) { 107 rows1 = param.substring( 0,st ); 108 rows2 = rows1 ; 109 cols1 = param.substring( st+1 ); 110 cols2 = cols1; 111 } 112 } 113 114 // size1,size2 を使わずに、cols1,cols2 を使用。 115 if( cols1 == null || cols2 == null ) { 116 cols1 = size1 ; 117 cols2 = size2 ; 118 } 119 120 // Attributesの連結記述 121 attributes = new Attributes() 122 .set( "disabled" , disabled ) 123 .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 124 .add( "class" , clm.getDbType() ); 125 126 tagBuffer.add( XHTMLTag.textareaAttri( attributes ) ); 127 } 128 129 /** 130 * 各オブジェクトから自分のインスタンスを返します。 131 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 132 * まかされます。 133 * 134 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 135 * 136 * @param clm DBColumnオブジェクト 137 * 138 * @return CellEditorオブジェクト 139 * @og.rtnNotNull 140 */ 141 public CellEditor newInstance( final DBColumn clm ) { 142 return new Editor_QRCODE( clm ); 143 } 144 145 /** 146 * データの編集用文字列を返します。 147 * 148 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 149 * 150 * @param value 入力値 151 * 152 * @return データの編集用文字列 153 * @og.rtnNotNull 154 */ 155 @Override 156 public String getValue( final String value ) { 157 // TagBufferの連結記述 158 return BASE_HTML 159 + new TagBuffer( "textarea" ) 160 .add( "name" , name ) 161 .add( "id" , "outdata" ) // ID 固定です。 162 .add( "cols" , cols2 ) 163 .add( "rows" , rows2 ) 164 .add( tagBuffer.makeTag() ) 165 .addBody( value ) 166 .makeTag(); 167 } 168 169 /** 170 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 171 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し、 172 * リクエスト情報を1つ毎のフィールドで処理できます。 173 * 174 * @og.rev 7.4.2.1 (2021/05/21) 新規作成 175 * 176 * @param row 行番号 177 * @param value 入力値 178 * 179 * @return データ表示/編集用の文字列 180 * @og.rtnNotNull 181 */ 182 @Override 183 public String getValue( final int row,final String value ) { 184 final String newName = name + HybsSystem.JOINT_STRING + row; 185 186 // TagBufferの連結記述 187 return BASE_HTML 188 + new TagBuffer( "textarea" ) 189 .add( "name" , newName ) 190 .add( "id" , "outdata" ) // ID 固定です。 191 .add( "cols" , cols2 ) 192 .add( "rows" , rows2 ) 193 .add( tagBuffer.makeTag() ) 194 .addBody( value ) 195 .makeTag( row,value ); 196 } 197}