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.common.HybsSystem; 019 import org.opengion.hayabusa.db.AbstractRenderer; 020 import org.opengion.hayabusa.db.CellRenderer; 021 import org.opengion.hayabusa.db.DBColumn; 022 023 /** 024 * SLABEL レンãƒ?ƒ©ãƒ¼ã¯ã€æ¡æ•°ã®é•·ã?ƒ‡ãƒ¼ã‚¿ã‚’コンパクトã«è¡¨ç¤ºã•ã›ã‚? 025 * LABEL レンãƒ?ƒ©ãƒ¼ã®é¡žä¼¼ã‚¯ãƒ©ã‚¹ã§ã™ã? 026 * 027 * 全角2Byte / åŠè§’ãŠã‚ˆã?åŠè§’カタカナを ?‘Byte ã§ç°¡æ˜“計算ã—ã€æŒ‡å®šã? 028 * æ¡æ•°ã§ã‚«ãƒ?ƒˆã—ã¾ã™ã? 029 * åˆæœŸå€¤ã¯ã€?0Byteã§ã€æ¡æ•°ã¯ã€è¡¨ç¤ºãƒ‘ラメータ(RENDERER_PARAM)ã§æŒ?®šã—ã¾ã™ã? 030 * æ–?—ã‚’ã‚«ãƒ?ƒˆã—ãŸå ´åˆã?ã€æœ€å¾Œã«ã€?..ã€ã‚’追åŠ?—ã€ã‚«ãƒ?ƒˆå‰ã?æ–?—ã‚’ title 属æ?ã« 031 * è¨å®šã™ã‚‹ã“ã¨ã§ã€ã?ウスをカãƒ?ƒˆå¾Œã?æ–?—ã«è¼‰ã›ã‚‹ã¨ã€ã‚«ãƒ?ƒˆå‰ã?値ãŒãƒãƒ??表示 032 * ã•れã¾ã™ã? 033 * <span title="ã‚«ãƒ?ƒˆå‰ã?値">ã‚«ãƒ?ƒˆæ–??..</span> 034 * ã‚«ãƒ?ƒˆã•れãªã‹ã£ãŸå?åˆã?ã€å?ã®æ–?—ãŒãã?ã¾ã¾è¡¨ç¤ºã•れã¾ã™ã? 035 * 036 * カラãƒ??表示ã«å¿?¦ãªå±žæ?ã¯, DBColumn オブジェクãƒ?よりå–り出ã—ã¾ã™ã? 037 * ã“ã?クラスã¯ã€è¡¨ç¤ºãƒ‘ラメータã«ãªã«ã‚‚指定ã—ãªã?ãƒ?ƒ•ォルãƒ?å ´åˆã?ã€? 038 * ã™ã¹ã¦åŒä¸??オブジェクトを返ã—ã¾ã™ã?ãれ以外ã?ã€DBColumn オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã? 039 * 040 * @og.rev 3.5.6.2 (2004/07/05) æ–°è¦ä½œæ? 041 * @og.group ãƒ??タ表示 042 * 043 * @version 4.0 044 * @author Kazuhiko Hasegawa 045 * @since JDK5.0, 046 */ 047 public class Renderer_SLABEL extends AbstractRenderer { 048 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */ 049 private static final String VERSION = "4.0.0.0 (2005/08/31)" ; 050 051 private static final CellRenderer dbCell = new Renderer_SLABEL() ; // 20Byteã§ã‚«ãƒ?ƒˆ 052 private final int cutSize; 053 054 /** 055 * ãƒ?ƒ•ォルトコンストラクターã€? 056 * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã? 057 * 058 */ 059 public Renderer_SLABEL() { 060 cutSize = 20; 061 } 062 063 /** 064 * ãƒ?ƒ•ォルトコンストラクターã€? 065 * 066 * @param clm DBColumnオブジェクãƒ? 067 */ 068 private Renderer_SLABEL( final DBColumn clm ) { 069 String param = clm.getRendererParam(); 070 cutSize = Integer.parseInt( param ); 071 } 072 073 /** 074 * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã? 075 * 自åˆ??身をã‚ャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?« 076 * ã¾ã‹ã•れã¾ã™ã? 077 * 078 * @param clm DBColumnオブジェクãƒ? 079 * 080 * @return CellRendererオブジェクãƒ? 081 */ 082 public CellRenderer newInstance( final DBColumn clm ) { 083 String param = clm.getRendererParam(); 084 085 if( param != null && param.length() > 0 ) { 086 return new Renderer_SLABEL( clm ); 087 } 088 else { 089 return dbCell; 090 } 091 } 092 093 /** 094 * ãƒ??ã‚¿ã®è¡¨ç¤ºç”¨æ–?—å?ã‚’è¿”ã—ã¾ã™ã? 095 * 096 * 全角2Byte / åŠè§’ãŠã‚ˆã?åŠè§’カタカナを ?‘Byte ã§ç°¡æ˜“計算ã—ã€æŒ‡å®šã? 097 * æ¡æ•°ã§ã‚«ãƒ?ƒˆã—ã¾ã™ã? 098 * åˆæœŸå€¤ã¯ã€?0Byteã§ã€æ¡æ•°ã¯ã€è¡¨ç¤ºãƒ‘ラメータ(RENDERER_PARAM)ã§æŒ?®šã—ã¾ã™ã? 099 * 100 * @param value 入力å? 101 * 102 * @return ãƒ??ã‚¿ã®è¡¨ç¤ºç”¨æ–?—å? 103 */ 104 @Override 105 public String getValue( final String value ) { 106 107 // 簡易的処ç??ã™ã¹ã¦ãŒå?è§’ã§ã‚ã£ã¦ã‚‚ã?制é™ä»¥å†?§ã‚ã‚‹ã€? 108 int len = value.length(); 109 if( len*2 <= cutSize ) { return value; } 110 111 int byteSize = 0; 112 int adrs; 113 for( adrs=0; adrs<len && byteSize<cutSize ; adrs++ ) { 114 char ch = value.charAt(adrs); 115 if( ch <= 0x7f || ( ch >= 0xff61 && ch <= 0xff9f ) ) { 116 byteSize ++; 117 } 118 else { 119 byteSize +=2; 120 } 121 } 122 123 // æ£ç¢ºã«ã‚«ã‚¦ãƒ³ãƒˆã—ãŸçµæžœã€åˆ¶é™ä»¥å†?§ã‚ã£ãŸãŸã‚ã? 124 if( adrs==len && byteSize<=cutSize ) { 125 return value; 126 } 127 else if( byteSize>cutSize ) { // オーãƒã?ã—ãŸå ´å? 128 adrs-- ; 129 } 130 131 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_SMALL ); 132 buf.append( "<span title=\"" ); 133 buf.append( value ); 134 buf.append( "\">" ); 135 buf.append( value.substring( 0,adrs ) ); // åˆ?‚Šå‡ºã? 136 buf.append( "...</span>" ); 137 138 return buf.toString(); 139 } 140 }