/src/org/mt4j/components/css/style/CSSFont.java

http://mt4j.googlecode.com/ · Java · 333 lines · 171 code · 36 blank · 126 comment · 43 complexity · f67f5075ac2d147e1bd9fe5de79b4cde MD5 · raw file

  1. package org.mt4j.components.css.style;
  2. import org.mt4j.components.css.util.CSSKeywords.CSSFontFamily;
  3. import org.mt4j.components.css.util.CSSKeywords.CSSFontStyle;
  4. import org.mt4j.components.css.util.CSSKeywords.CSSFontWeight;
  5. import org.mt4j.util.MTColor;
  6. /**
  7. * The Class CSSFont.
  8. */
  9. public class CSSFont {
  10. /** The font family. */
  11. private CSSFontFamily family = CSSFontFamily.CUSTOM;
  12. /** The font style. */
  13. private CSSFontStyle style = CSSFontStyle.NORMAL;
  14. /** The custom font file string. */
  15. private String customType = "";
  16. /** The font weight. */
  17. private CSSFontWeight weight = CSSFontWeight.NORMAL;
  18. /** The font size. */
  19. private int fontsize = 16;
  20. /** The font color. */
  21. private MTColor color = new MTColor(255, 255, 255, 255);
  22. /** Has the font been modified. */
  23. private boolean modified = false;
  24. /**
  25. * Instantiates a new CSS font using the color
  26. *
  27. * @param color the color
  28. */
  29. public CSSFont(MTColor color) {
  30. super();
  31. this.color = color;
  32. this.modified = true;
  33. }
  34. /**
  35. * Instantiates a new default CSS font.
  36. */
  37. public CSSFont() {
  38. super();
  39. this.family = CSSFontFamily.DEFAULT;
  40. }
  41. /**
  42. * Instantiates a new CSS font using the font size
  43. *
  44. * @param fontsize the fontsize
  45. */
  46. public CSSFont(int fontsize) {
  47. super();
  48. this.fontsize = fontsize;
  49. this.modified = true;
  50. }
  51. /**
  52. * Instantiates a new CSS font using a custom font file name
  53. *
  54. * @param customType the custom custom font file name
  55. */
  56. public CSSFont(String customType) {
  57. super();
  58. this.customType = customType;
  59. this.modified = true;
  60. }
  61. /**
  62. * Instantiates a new CSS font using the font style
  63. *
  64. * @param style the font style
  65. */
  66. public CSSFont(CSSFontStyle style) {
  67. super();
  68. this.style = style;
  69. this.modified = true;
  70. }
  71. /**
  72. * Instantiates a new CSS font using the font family
  73. *
  74. * @param family the font family
  75. */
  76. public CSSFont(CSSFontFamily family) {
  77. super();
  78. this.family = family;
  79. this.modified = true;
  80. }
  81. /**
  82. * Instantiates a new CSS font using the font weight
  83. *
  84. * @param weight the font weight
  85. */
  86. public CSSFont(CSSFontWeight weight) {
  87. super();
  88. this.weight = weight;
  89. this.modified = true;
  90. }
  91. /**
  92. * Gets the color.
  93. *
  94. * @return the color
  95. */
  96. public MTColor getColor() {
  97. return color;
  98. }
  99. /**
  100. * Sets the color.
  101. *
  102. * @param color the new color
  103. */
  104. public void setColor(MTColor color) {
  105. this.color = color;
  106. this.modified = true;
  107. }
  108. /**
  109. * Gets the font size.
  110. *
  111. * @return the font size
  112. */
  113. public int getFontsize() {
  114. return fontsize;
  115. }
  116. /**
  117. * Sets the font size.
  118. *
  119. * @param fontsize the new font size
  120. */
  121. public void setFontsize(int fontsize) {
  122. this.fontsize = fontsize;
  123. this.modified = true;
  124. debugOutput();
  125. }
  126. /**
  127. * Gets the weight.
  128. *
  129. * @return the weight
  130. */
  131. public CSSFontWeight getWeight() {
  132. return weight;
  133. }
  134. /**
  135. * Sets the weight.
  136. *
  137. * @param weight the new weight
  138. */
  139. public void setWeight(CSSFontWeight weight) {
  140. this.weight = weight;
  141. this.modified = true;
  142. debugOutput();
  143. }
  144. /**
  145. * Gets the family.
  146. *
  147. * @return the family
  148. */
  149. public CSSFontFamily getFamily() {
  150. return family;
  151. }
  152. /**
  153. * Sets the family.
  154. *
  155. * @param family the new family
  156. */
  157. public void setFamily(CSSFontFamily family) {
  158. this.family = family;
  159. this.modified = true;
  160. debugOutput();
  161. }
  162. /**
  163. * Gets the font style.
  164. *
  165. * @return the font style
  166. */
  167. public CSSFontStyle getStyle() {
  168. return style;
  169. }
  170. /**
  171. * Sets the font style.
  172. *
  173. * @param style the new font style
  174. */
  175. public void setStyle(CSSFontStyle style) {
  176. this.style = style;
  177. this.modified = true;
  178. debugOutput();
  179. }
  180. /**
  181. * Gets the file name of custom fonts
  182. *
  183. * @return the file name of the custom font
  184. */
  185. public String getCustomType() {
  186. return customType;
  187. }
  188. /**
  189. * Sets the file name of custom fonts
  190. *
  191. * @param customType the file name of the custom font
  192. */
  193. public void setCustomType(String customType) {
  194. this.customType = customType;
  195. this.modified = true;
  196. debugOutput();
  197. }
  198. /**
  199. * Sets, if the font has been modified
  200. *
  201. * @param modified the new modified
  202. */
  203. public void setModified(boolean modified) {
  204. this.modified = modified;
  205. }
  206. /**
  207. * Checks if the font is modified.
  208. *
  209. * @return true, if is modified
  210. */
  211. public boolean isModified() {
  212. return modified;
  213. }
  214. /**
  215. * Debug output.
  216. */
  217. private void debugOutput() {
  218. /*Logger logger = Logger.getLogger("MT4J Extensions");
  219. logger.debug("Font Family: " + family + ", Font Style: " + style
  220. + ", Font Weight: " + weight + ", Font Size: " + fontsize
  221. + ", Custom TTF Font: " + customType);*/
  222. }
  223. /* (non-Javadoc)
  224. * @see java.lang.Object#hashCode()
  225. */
  226. @Override
  227. public int hashCode() {
  228. final int prime = 31;
  229. int result = 1;
  230. result = prime * result + ((color == null) ? 0 : color.hashCode());
  231. result = prime * result
  232. + ((customType == null) ? 0 : customType.hashCode());
  233. result = prime * result + ((family == null) ? 0 : family.hashCode());
  234. result = prime * result + fontsize;
  235. result = prime * result + ((style == null) ? 0 : style.hashCode());
  236. result = prime * result + ((weight == null) ? 0 : weight.hashCode());
  237. return result;
  238. }
  239. /* (non-Javadoc)
  240. * @see java.lang.Object#equals(java.lang.Object)
  241. */
  242. @Override
  243. public boolean equals(Object obj) {
  244. if (this == obj)
  245. return true;
  246. if (obj == null)
  247. return false;
  248. if (getClass() != obj.getClass())
  249. return false;
  250. CSSFont other = (CSSFont) obj;
  251. if (color == null) {
  252. if (other.color != null)
  253. return false;
  254. } else if (!color.equals(other.color))
  255. return false;
  256. if (customType == null) {
  257. if (other.customType != null)
  258. return false;
  259. } else if (!customType.equals(other.customType))
  260. return false;
  261. if (family == null) {
  262. if (other.family != null)
  263. return false;
  264. } else if (!family.equals(other.family))
  265. return false;
  266. if (fontsize != other.fontsize)
  267. return false;
  268. if (style == null) {
  269. if (other.style != null)
  270. return false;
  271. } else if (!style.equals(other.style))
  272. return false;
  273. if (weight == null) {
  274. if (other.weight != null)
  275. return false;
  276. } else if (!weight.equals(other.weight))
  277. return false;
  278. return true;
  279. }
  280. public CSSFont clone() {
  281. CSSFont newFont = new CSSFont();
  282. newFont.color = this.color.getCopy();
  283. newFont.customType = this.customType.substring(0);
  284. newFont.family = this.family;
  285. newFont.fontsize = this.fontsize;
  286. newFont.modified = this.modified;
  287. newFont.style = this.style;
  288. newFont.weight =this.weight;
  289. return newFont;
  290. }
  291. public CSSFont clone(int fontsize) {
  292. CSSFont newFont = this.clone();
  293. newFont.setFontsize(fontsize);
  294. newFont.setModified(true);
  295. return newFont;
  296. }
  297. }