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 }