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.AbstractRenderer;
019import org.opengion.hayabusa.db.CellRenderer;
020import org.opengion.hayabusa.db.DBColumn;
021import org.opengion.fukurou.util.TagBuffer;                             // 7.0.1.0 (2018/10/15)
022
023/**
024 * LABEL レンデラーは、カラムの値を#FFFFFFの色として表示する場合に
025 * 使用するクラスです。
026 * #FFFFFFのように#付き7桁のデータで設定して下さい。
027 *
028 * このクラスは、不変オブジェクトとして、共有されます。
029 *
030 * @og.group データ表示
031 *
032 * @og.rev 5.5.4.0 (2012/07/02) 新規作成
033 * @og.rev 5.6.3.1 (2013/04/05) input タグから、div へ全面変更
034 *
035 * @version  4.0
036 * @author   Kazuhiko Hasegawa
037 * @since    JDK5.0,
038 */
039public class Renderer_COLOR extends AbstractRenderer {
040        /** このプログラムのVERSION文字列を設定します。   {@value} */
041        private static final String VERSION = "7.0.1.0 (2018/10/15)" ;
042
043        private static final CellRenderer DB_CELL = new Renderer_COLOR() ;
044
045//      private static final String             DIV1 = "<div style=\"background-color:" ;
046//      private static final String             DIV2 = "; color:" ;
047//      private static final String             DIV3 = ";\">" ;
048//      private static final String             DIV4 = "</div>" ;
049
050        // 7.0.1.0 (2018/10/15) divタグの作成に、TagBuffer利用。
051        private static final String             DIV = new TagBuffer( "div" )
052                                                                                                .add( "style" , "background-color:[V]; color:[V];" )
053                                                                                                .add( "title" , "[V]" )
054                                                                                                .addBody( "[V]" )
055                                                                                                .make().toString();
056
057        /**
058         * デフォルトコンストラクター
059         *
060         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
061         */
062        public Renderer_COLOR() { super(); }            // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
063
064        /**
065         * 各オブジェクトから自分のインスタンスを返します。
066         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
067         * まかされます。
068         *
069         * @param       clm     DBColumnオブジェクト
070         *
071         * @return      CellRendererオブジェクト
072         * @og.rtnNotNull
073         */
074        public CellRenderer newInstance( final DBColumn clm ) {
075                return DB_CELL;
076        }
077
078        /**
079         * データの表示用文字列を返します。
080         *
081         * @og.rev 7.0.1.0 (2018/10/15) divタグの作成に、TagBuffer利用。
082         *
083         * @param   value 入力値
084         *
085         * @return  データの表示用文字列
086         * @og.rtnNotNull
087         */
088        @Override
089        public String getValue( final String value ) {
090                // 6.4.1.1 (2016/01/16) PMD refactoring. A method should have only one exit point, and that should be the last statement in the method
091//              return value == null || value.trim().isEmpty() ? "" : DIV1 + value + DIV2 + value + DIV3 + value + DIV4;
092                return value == null || value.trim().isEmpty() ? "" : DIV.replace( "[V]",value );
093        }
094
095        /**
096         * データ出力用の文字列を作成します。
097         * ファイル等に出力する形式を想定しますので、HTMLタグを含まない
098         * データを返します。
099         * 基本は、#getValue( String ) をそのまま返します。
100         *
101         * @og.rev 6.0.4.0 (2014/11/28) データ出力用のレンデラー
102         *
103         * @param   value 入力値
104         *
105         * @return  データ出力用の文字列
106         * @og.rtnNotNull
107         * @see         #getValue( String )
108         */
109        @Override
110        public String getWriteValue( final String value ) {
111                return value == null ? "" : value;
112        }
113}