PageRenderTime 48ms CodeModel.GetById 33ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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