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