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.hayabusa.db.AbstractRenderer; 020 import org.opengion.hayabusa.db.CellRenderer; 021 import org.opengion.hayabusa.db.DBColumn; 022 023 /** 024 * NUMBER レンãƒ?ƒ©ãƒ¼ã¯ã€ã‚«ãƒ©ãƒ??ãƒ??ã‚¿ã‚’æ•°å—表示ã™ã‚‹å ´åˆã«ä½¿ç”¨ã™ã‚‹ã‚¯ãƒ©ã‚¹ã§ã™ã? 025 * x,yã®å½¢å¼ã§è¡¨ç¤ºãƒ‘ラメータを指定å¯èƒ½ã§ã™ã? 026 * è²?•°ã®å ´åˆã?spanã‚¿ã‚°class="minus"を付ã‘ã¦å‡ºåŠ›ã—ã¾ã™ã? 027 * 028 * フォーマットã«ã¯ã€java.text.NumberFormat を使用ã›ãšã«ã€ç‹¬è‡ªã‚¯ãƒ©ã‚¹ã‚’使用ã—ã¦ãŠã‚Š 029 * double 以上ã?精度をもã¤å€¤ã§ã‚‚æ£ç¢ºã«å¤‰æ›ã§ãã¾ã™ã? 030 * カラãƒ??表示ã«å¿?¦ãªå±žæ?ã¯, DBColumn オブジェクãƒ?よりå–り出ã—ã¾ã™ã? 031 * ã“ã?クラスã¯ã€DBColumn オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã? 032 * 033 * @og.group ãƒ??タ表示 034 * @og.rev 5.4.3.6 (2012/01/19) ã‚³ãƒ¡ãƒ³ãƒˆä¿®æ£ 035 * 036 * @version 4.0 037 * @author Kazuhiko Hasegawa 038 * @since JDK5.0, 039 */ 040 public class Renderer_NUMBER extends AbstractRenderer { 041 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */ 042 private static final String VERSION = "5.6.2.3 (2013/03/22)" ; 043 044 private final String defValue ; 045 private final String noDisplayVal ; // 5.6.2.3 (2013/03/22) 046 private final int minFraction; 047 048 // 5.2.2.0 (2010/11/01) defval,size ã®åˆæœŸå€¤è¨å®šã?変更 049 private static final CellRenderer[] dbCell = { 050 new Renderer_NUMBER(), // 0 051 new Renderer_NUMBER("",1), // 1 052 new Renderer_NUMBER("",2), // 2 053 new Renderer_NUMBER("0",0), // 3 054 new Renderer_NUMBER("0",1), // 4 055 new Renderer_NUMBER("0",2) // 5 056 }; 057 058 /** 059 * ãƒ?ƒ•ォルトコンストラクターã€? 060 * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã? 061 * 062 * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ?? 063 * @og.rev 3.3.0.0 (2003/06/23) åˆæœŸå€¤è¨å®šè¿½åŠ?? 064 * @og.rev 4.0.0.0 (2007/11/29) åˆæœŸå€¤ã‚?"ã«å¤‰æ›´ã€? 065 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal å¤‰æ•°åˆæœŸåŒ? 066 * 067 */ 068 public Renderer_NUMBER() { 069 defValue = ""; // 4.0.0.0 (2007/11/29) 070 minFraction = 0; 071 noDisplayVal = null; // 5.5.1.0 (2012/04/03) 072 } 073 074 /** 075 * ãƒ?ƒ•ォルトコンストラクターã€? 076 * 077 * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ?? 078 * @og.rev 3.3.0.0 (2003/06/23) åˆæœŸå€¤è¨å®šè¿½åŠ??NumberFormatクラスã¯ã€å»?¢ã—ã¾ã™ã? 079 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ? 080 * 081 * @param defval åˆæœŸå€¤ 082 * @param size å°æ•°ç‚¹ 083 */ 084 private Renderer_NUMBER( final String defval,final int size ) { 085 defValue = defval; 086 minFraction = size; 087 noDisplayVal = null; // 5.5.1.0 (2012/04/03) 088 } 089 090 /** 091 * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã? 092 * 自åˆ??身をã‚ャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?« 093 * ã¾ã‹ã•れã¾ã™ã? 094 * 095 * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ?? 096 * @og.rev 3.1.2.1 (2003/04/10) synchronized ã‚’ã?削除ã—ã¾ã™ã? 097 * @og.rev 5.2.2.0 (2010/11/01) defval,size ã®åˆæœŸå€¤è¨å®šã?変更 098 * @og.rev 5.3.5.0 (2011/05/01) ↑ã?判定ãƒã‚¸ãƒ?‚¯ã®ãƒã‚°ä¿®æ£ 099 * 100 * @param clm DBColumnオブジェクãƒ? 101 * 102 * @return CellRendererオブジェクãƒ? 103 */ 104 public CellRenderer newInstance( final DBColumn clm ) { 105 String defval = clm.getDefault(); 106 int size = clm.getSizeY(); 107 // if( ( defval == null || defval.length() == 0 || defval.equals( "0" ) ) 108 // && size < dbCell.length ) { 109 // return dbCell[size]; 110 // } 111 112 // 5.2.2.0 (2010/11/01) defval,size ã®åˆæœŸå€¤è¨å®šã?変更 113 // 5.3.5.0 (2011/05/01) ↑ã?判定ãƒã‚¸ãƒ?‚¯ã®ãƒã‚°ä¿®æ£ 114 // if( size < dbCell.length ) { 115 if( size < 3 ) { 116 if( defval == null || defval.length() == 0 ) { 117 return dbCell[size]; // 0,1,2 118 } 119 // else if( defval.equals( "0" ) ) { 120 else if( "0".equals( defval ) ) { // 5.3.0.0 (2010/12/01) リãƒ?ƒ©ãƒ«ã§æ¯”è¼?™ã‚‹ã? 121 return dbCell[size+3]; // 3,4,5 122 } 123 } 124 125 return new Renderer_NUMBER( defval,size ); 126 } 127 128 /** 129 * ãƒ??ã‚¿ã®è¡¨ç¤ºç”¨æ–?—å?ã‚’è¿”ã—ã¾ã™ã? 130 * 131 * @og.rev 3.1.0.0 (2003/03/20) å†?ƒ¨ã«ã€DBColumn オブジェクトをã‚ープã—ãªã?‚ˆã?«å¤‰æ›´ 132 * @og.rev 3.3.0.0 (2003/06/23) NumberFormatクラスã¯ã€å»?¢ã—ã¾ã™ã? 133 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ? 134 * 135 * @param value 入力å? 136 * 137 * @return ãƒ??ã‚¿ã®è¡¨ç¤ºç”¨æ–?—å? 138 */ 139 @Override 140 public String getValue( final String value ) { 141 // 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ? 142 if( noDisplayVal != null && noDisplayVal.equalsIgnoreCase( value ) ) { return "" ; } 143 144 String rtn ; 145 if( value == null || (value.trim()).length() == 0 ) { 146 rtn = defValue; 147 } 148 else { 149 rtn = value; 150 } 151 152 rtn = StringUtil.numberFormat( rtn,minFraction ); 153 if( rtn != null && (rtn.trim()).length() > 0 && rtn.charAt( 0 ) == '-' ) { 154 rtn = "<span class=\"minus\">" + rtn + "</span>"; 155 } 156 return rtn; 157 } 158 }