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 * MONEY レンãƒ?ƒ©ãƒ¼ã¯ã€ã‚«ãƒ©ãƒ??ãƒ??ã‚¿ã‚’éßé¡è¡¨ç¤ºã™ã‚‹å ´åˆã«ä½¿ç”¨ã™ã‚‹ã‚¯ãƒ©ã‚¹ã§ã™ã? 025 * 026 * マイナス時ã?表示ã¯ã€id="minus" ã‚’ã‚ー㫠CSSãƒ•ã‚¡ã‚¤ãƒ«ã§æŒ?®šã—ã¦ã?¾ã™ã? 027 * 通貨ã¯ã€æ¨™æº–ã§ã¯ã€?¿¥ã§ã™ãŒã€å?:è¨˜å· ã¨ã?†å½¢å¼ã§æŒ?®šã™ã‚Œã?ã€å„値ã”ã¨ã« 028 * 通貨を指定ã§ãã¾ã™ã?(ãŸã ã—ã?通貨変æ›ã¯ã€ã‚µãƒã?トã—ã¦ã?¾ã›ã‚“ã€? 029 * è²?•°ã®å ´åˆã?spanã‚¿ã‚°class="minus"を付ã‘ã¦å‡ºåŠ›ã—ã¾ã™ã? 030 * 031 * カラãƒ??表示ã«å¿?¦ãªå±žæ?ã¯, DBColumn オブジェクãƒ?よりå–り出ã—ã¾ã™ã? 032 * ã“ã?クラスã¯ã€DBColumn オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã? 033 * 034 * @og.group ãƒ??タ表示 035 * @og.rev 5.4.3.6 (2012/01/19) ã‚³ãƒ¡ãƒ³ãƒˆä¿®æ£ 036 * 037 * @version 4.0 038 * @author Kazuhiko Hasegawa 039 * @since JDK5.0, 040 */ 041 public class Renderer_MONEY extends AbstractRenderer { 042 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */ 043 private static final String VERSION = "5.6.2.3 (2013/03/22)" ; 044 045 private static final CellRenderer[] dbCell = { 046 new Renderer_MONEY(), 047 new Renderer_MONEY(1), 048 new Renderer_MONEY(2) 049 }; 050 051 private final int minFraction; 052 private final String noDisplayVal ; // 5.6.2.3 (2013/03/22) 053 054 /** 055 * ãƒ?ƒ•ォルトコンストラクターã€? 056 * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã? 057 * 058 * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ?? 059 * @og.rev 3.3.0.0 (2003/06/23) åˆæœŸå€¤è¨å®šè¿½åŠ?? 060 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal å¤‰æ•°åˆæœŸåŒ? 061 * 062 */ 063 public Renderer_MONEY() { 064 minFraction = 0; 065 noDisplayVal = null; // 5.5.1.0 (2012/04/03) 066 } 067 068 /** 069 * コンストラクターã€? 070 * 071 * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ?? 072 * @og.rev 3.3.0.0 (2003/06/23) åˆæœŸå€¤è¨å®šè¿½åŠ??NumberFormatクラスã¯ã€å»?¢ã—ã¾ã™ã? 073 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ? 074 * 075 * @param size å°æ•°ç‚¹ 076 */ 077 private Renderer_MONEY( final int size ) { 078 minFraction = size ; 079 noDisplayVal = null; // 5.5.1.0 (2012/04/03) 080 } 081 082 /** 083 * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã? 084 * 自åˆ??身をã‚ャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?« 085 * ã¾ã‹ã•れã¾ã™ã? 086 * 087 * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ?? 088 * @og.rev 3.1.2.1 (2003/04/10) synchronized ã‚’ã?削除ã—ã¾ã™ã? 089 * 090 * @param clm DBColumnオブジェクãƒ? 091 * 092 * @return CellRendererオブジェクãƒ? 093 */ 094 public CellRenderer newInstance( final DBColumn clm ) { 095 int size = clm.getSizeY(); 096 if( size < dbCell.length ) { return dbCell[size]; } 097 return new Renderer_MONEY( size ); 098 } 099 100 /** 101 * ãƒ??ã‚¿ã®è¡¨ç¤ºç”¨æ–?—å?ã‚’è¿”ã—ã¾ã™ã? 102 * 103 * 引数ã®å€¤ãŒã?『数å—åž‹æ–?—å?:通貨ã€ã¨ã?†å€¤ã‚’渡ã™ã“ã¨ã§ã€??貨ã‚? 104 * é ã«ã¤ã‘ã¦é€šè²¨ã”ã¨ã«ç•°ãªã‚‹å?を表示ã•ã›ã‚‹ã“ã¨ãŒã§ãã‚‹ã€? 105 * 106 * @og.rev 3.1.0.0 (2003/03/20) å†?ƒ¨ã«ã€DBColumn オブジェクトをã‚ープã—ãªã?‚ˆã?«å¤‰æ›´ 107 * @og.rev 3.3.0.0 (2003/06/23) NumberFormatクラスã¯ã€å»?¢ã—ã¾ã™ã? 108 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ? 109 * 110 * @param value 入力å? 111 * 112 * @return ãƒ??ã‚¿ã®è¡¨ç¤ºç”¨æ–?—å? 113 */ 114 @Override 115 public String getValue( final String value ) { 116 // 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ? 117 if( noDisplayVal != null && noDisplayVal.equalsIgnoreCase( value ) ) { return "" ; } 118 119 String rtn ; 120 if( value == null || (value.trim()).length() == 0 ) { 121 rtn = "0" ; 122 } 123 else { 124 rtn = value; 125 } 126 127 boolean minus = false ; 128 if( rtn.charAt( 0 ) == '-' ) { 129 minus = true; 130 rtn = rtn.substring( 1 ); 131 } 132 133 String tuuka = "?¥"; 134 int taniPos = rtn.indexOf( ':' ); 135 if( taniPos >= 0 ) { 136 tuuka = rtn.substring( taniPos+1 ); 137 rtn = rtn.substring( 0,taniPos ); 138 } 139 140 rtn = tuuka + StringUtil.numberFormat( rtn,minFraction ) + "-"; 141 142 if( minus ) { 143 rtn = "<span class=\"minus\">-" + rtn + "</span>"; 144 } 145 return rtn; 146 } 147 }