001package com.hfg.graphics; 002 003import com.hfg.util.Value; 004 005//------------------------------------------------------------------------------ 006/** 007 Generator for a data stylist. 008 <div> 009 @author J. Alex Taylor, hairyfatguy.com 010 </div> 011 */ 012//------------------------------------------------------------------------------ 013// com.hfg Library 014// 015// This library is free software; you can redistribute it and/or 016// modify it under the terms of the GNU Lesser General Public 017// License as published by the Free Software Foundation; either 018// version 2.1 of the License, or (at your option) any later version. 019// 020// This library is distributed in the hope that it will be useful, 021// but WITHOUT ANY WARRANTY; without even the implied warranty of 022// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 023// Lesser General Public License for more details. 024// 025// You should have received a copy of the GNU Lesser General Public 026// License along with this library; if not, write to the Free Software 027// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 028// 029// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 030// jataylor@hairyfatguy.com 031//------------------------------------------------------------------------------ 032 033public class DataStylistGenerator 034{ 035 private String mLabel; 036 private String mStringFormat; 037 private String mCSSClass; 038 private Colorist mColorist; 039 private ColorSpec mColorSpec; 040 041 //########################################################################### 042 // PUBLIC METHODS 043 //########################################################################### 044 045 //--------------------------------------------------------------------------- 046 public DataStylistGenerator setLabel(String inValue) 047 { 048 mLabel = inValue; 049 return this; 050 } 051 052 //--------------------------------------------------------------------------- 053 public String getLabel() 054 { 055 return mLabel; 056 } 057 058 059 //--------------------------------------------------------------------------- 060 public DataStylistGenerator setStringFormat(String inValue) 061 { 062 mStringFormat = inValue; 063 return this; 064 } 065 066 //--------------------------------------------------------------------------- 067 public String getStringFormat() 068 { 069 return mStringFormat; 070 } 071 072 073 //--------------------------------------------------------------------------- 074 public DataStylistGenerator setCSSClass(String inValue) 075 { 076 mCSSClass = inValue; 077 return this; 078 } 079 080 //--------------------------------------------------------------------------- 081 public String getCSSClass() 082 { 083 return mCSSClass; 084 } 085 086 087 //--------------------------------------------------------------------------- 088 public DataStylistGenerator setColorist(Colorist inValue) 089 { 090 mColorist = inValue; 091 return this; 092 } 093 094 //--------------------------------------------------------------------------- 095 public Colorist getColorist() 096 { 097 return mColorist; 098 } 099 100 101 //--------------------------------------------------------------------------- 102 public DataStylistGenerator setColorSpec(ColorSpec inValue) 103 { 104 mColorSpec = inValue; 105 return this; 106 } 107 108 //--------------------------------------------------------------------------- 109 public ColorSpec getColorSpec() 110 { 111 return mColorSpec; 112 } 113 114 115 //--------------------------------------------------------------------------- 116 public DataStylist generate(Value inValue) 117 { 118 DataStylist dataStylist = new DataStylist() 119 .setLabel(getLabel()) 120 .setStringFormat(getStringFormat()) 121 .setCSSClass(getCSSClass()); 122 123 if (getColorist() != null) 124 { 125 dataStylist.setColorSpec(getColorist().colorByNumber(inValue)); 126 } 127 else if (getColorSpec() != null) 128 { 129 dataStylist.setColorSpec(getColorSpec()); 130 } 131 132 133 return dataStylist; 134 } 135 136 //--------------------------------------------------------------------------- 137 public DataStylist generate(int inValue) 138 { 139 DataStylist dataStylist = new DataStylist() 140 .setLabel(getLabel()) 141 .setStringFormat(getStringFormat()); 142 143 if (getColorist() != null) 144 { 145 dataStylist.setColorSpec(getColorist().colorByNumber(inValue)); 146 } 147 else if (getColorSpec() != null) 148 { 149 dataStylist.setColorSpec(getColorSpec()); 150 } 151 152 return dataStylist; 153 } 154 155 //--------------------------------------------------------------------------- 156 public DataStylist generate(long inValue) 157 { 158 DataStylist dataStylist = new DataStylist() 159 .setLabel(getLabel()) 160 .setStringFormat(getStringFormat()); 161 162 if (getColorist() != null) 163 { 164 dataStylist.setColorSpec(getColorist().colorByNumber(inValue)); 165 } 166 else if (getColorSpec() != null) 167 { 168 dataStylist.setColorSpec(getColorSpec()); 169 } 170 171 return dataStylist; 172 } 173 174 //--------------------------------------------------------------------------- 175 public DataStylist generate(float inValue) 176 { 177 DataStylist dataStylist = new DataStylist() 178 .setLabel(getLabel()) 179 .setStringFormat(getStringFormat()); 180 181 if (getColorist() != null) 182 { 183 dataStylist.setColorSpec(getColorist().colorByNumber(inValue)); 184 } 185 else if (getColorSpec() != null) 186 { 187 dataStylist.setColorSpec(getColorSpec()); 188 } 189 190 return dataStylist; 191 } 192 193 //--------------------------------------------------------------------------- 194 public DataStylist generate(double inValue) 195 { 196 DataStylist dataStylist = new DataStylist() 197 .setLabel(getLabel()) 198 .setStringFormat(getStringFormat()); 199 200 if (getColorist() != null) 201 { 202 dataStylist.setColorSpec(getColorist().colorByNumber(inValue)); 203 } 204 else if (getColorSpec() != null) 205 { 206 dataStylist.setColorSpec(getColorSpec()); 207 } 208 209 return dataStylist; 210 } 211}