KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > domimpl > HTMLBaseFontElementImpl


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The Lobo Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 package org.lobobrowser.html.domimpl;
22
23 import org.lobobrowser.html.style.*;
24 import org.lobobrowser.util.gui.ColorFactory;
25 import org.w3c.dom.html2.HTMLBaseFontElement;
26
27 public class HTMLBaseFontElementImpl extends HTMLAbstractUIElement implements
28         HTMLBaseFontElement {
29     public HTMLBaseFontElementImpl(String JavaDoc name) {
30         super(name);
31     }
32
33     public String JavaDoc getColor() {
34         return this.getAttribute("color");
35     }
36
37     public String JavaDoc getFace() {
38         return this.getAttribute("face");
39     }
40
41     public void setColor(String JavaDoc color) {
42         this.setAttribute("color", color);
43     }
44
45     public void setFace(String JavaDoc face) {
46         this.setAttribute("face", face);
47     }
48
49     public int getSize() {
50         try {
51             return Integer.parseInt(this.getAttribute("size"));
52         } catch(Exception JavaDoc thrown) {
53             this.warn("getSize(): Unable to parse size attribute in " + this + ".", thrown);
54             return 0;
55         }
56     }
57
58     public void setSize(int size) {
59         this.setAttribute("size", String.valueOf(size));
60     }
61     
62     protected RenderState createRenderState(RenderState prevRenderState) {
63         String JavaDoc face = this.getAttribute("face");
64         String JavaDoc size = this.getAttribute("size");
65         String JavaDoc color = this.getAttribute("color");
66         if(face != null) {
67             prevRenderState = new FontNameRenderState(prevRenderState, face);
68         }
69         if(size != null) {
70             int fontNumber = HtmlValues.getFontNumberOldStyle(size, prevRenderState);
71             float fontSize = HtmlValues.getFontSize(fontNumber);
72             prevRenderState = new FontSizeRenderState(prevRenderState, fontSize);
73             prevRenderState = new BaseFontRenderState(prevRenderState, fontNumber);
74         }
75         if(color != null) {
76             prevRenderState = new ColorRenderState(prevRenderState, ColorFactory.getInstance().getColor(color));
77         }
78         return prevRenderState;
79     }
80
81 }
82
Popular Tags