KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > renderer > RBlank


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 /*
22  * Created on May 21, 2005
23  */

24 package org.lobobrowser.html.renderer;
25 import java.awt.*;
26
27 import org.lobobrowser.html.domimpl.ModelNode;
28 import org.lobobrowser.html.style.RenderState;
29
30 class RBlank extends BaseBoundableRenderable {
31     //TODO: Is there a need for RBlank's at all?
32
public final int ascentPlusLeading;
33     private final FontMetrics fontMetrics;
34     
35     public RBlank(ModelNode me, FontMetrics fm, RenderableContainer container, int ascentPlusLeading, int width, int height) {
36         super(container, me);
37         this.fontMetrics = fm;
38         this.ascentPlusLeading = ascentPlusLeading;
39         // Dimensions set when constructed.
40
this.width = width;
41         this.height = height;
42     }
43     
44     protected void invalidateLayoutLocal() {
45     }
46     
47     public boolean onMouseClick(java.awt.event.MouseEvent JavaDoc event, int x, int y) {
48         ModelNode me = this.modelNode;
49         if(me != null) {
50             return HtmlController.getInstance().onMouseClick(me, event, x, y);
51         }
52         else {
53             return true;
54         }
55     }
56
57     public boolean onDoubleClick(java.awt.event.MouseEvent JavaDoc event, int x, int y) {
58         ModelNode me = this.modelNode;
59         if(me != null) {
60             return HtmlController.getInstance().onDoubleClick(me, event, x, y);
61         }
62         else {
63             return true;
64         }
65     }
66
67     public boolean onMousePressed(java.awt.event.MouseEvent JavaDoc event, int x, int y) {
68         ModelNode me = this.modelNode;
69         if(me != null) {
70             return HtmlController.getInstance().onMouseDown(me, event, x, y);
71         }
72         else {
73             return true;
74         }
75     }
76
77     public boolean onMouseReleased(java.awt.event.MouseEvent JavaDoc event, int x, int y) {
78         ModelNode me = this.modelNode;
79         if(me != null) {
80             return HtmlController.getInstance().onMouseUp(me, event, x, y);
81         }
82         else {
83             return true;
84         }
85     }
86     
87     public boolean onMouseDisarmed(java.awt.event.MouseEvent JavaDoc event) {
88         ModelNode me = this.modelNode;
89         if(me != null) {
90             return HtmlController.getInstance().onMouseDisarmed(me, event);
91         }
92         else {
93             return true;
94         }
95     }
96     
97     /* (non-Javadoc)
98      * @see net.sourceforge.xamj.domimpl.markup.Renderable#paint(java.awt.Graphics)
99      */

100     public final void paint(Graphics g) {
101         RenderState rs = this.modelNode.getRenderState();
102         Color bkg = rs.getTextBackgroundColor();
103         if(bkg != null) {
104             Color oldColor = g.getColor();
105             try {
106                 g.setColor(bkg);
107                 g.fillRect(0, 0, this.width, this.height);
108             } finally {
109                 g.setColor(oldColor);
110             }
111         }
112         int td = rs.getTextDecorationMask();
113         if(td != 0) {
114             if((td & RenderState.MASK_TEXTDECORATION_UNDERLINE) != 0) {
115                 int lineOffset = this.ascentPlusLeading + 2;
116                 g.drawLine(0, lineOffset, this.width, lineOffset);
117             }
118             if ((td & RenderState.MASK_TEXTDECORATION_LINE_THROUGH) != 0) {
119                 FontMetrics fm = this.fontMetrics;
120                 int lineOffset = fm.getLeading() + (fm.getAscent() + fm.getDescent()) / 2;
121                 g.drawLine(0, lineOffset, this.width, lineOffset);
122             }
123             if ((td & RenderState.MASK_TEXTDECORATION_OVERLINE) != 0) {
124                 int lineOffset = this.fontMetrics.getLeading();
125                 g.drawLine(0, lineOffset, this.width, lineOffset);
126             }
127             if ((td & RenderState.MASK_TEXTDECORATION_BLINK) != 0) {
128                 //TODO
129
}
130         }
131         Color over = rs.getOverlayColor();
132         if(over != null) {
133             Color oldColor = g.getColor();
134             try {
135                 g.setColor(over);
136                 g.fillRect(0, 0, width, height);
137             } finally {
138                 g.setColor(oldColor);
139             }
140         }
141     }
142     
143     /* (non-Javadoc)
144      * @see org.xamjwg.html.renderer.BoundableRenderable#paintSelection(java.awt.Graphics, boolean, org.xamjwg.html.renderer.RenderablePoint, org.xamjwg.html.renderer.RenderablePoint)
145      */

146     public boolean paintSelection(Graphics g, boolean inSelection, RenderableSpot startPoint, RenderableSpot endPoint) {
147         if(this == startPoint.renderable || this == endPoint.renderable) {
148             if(inSelection) {
149                 return false;
150             }
151         }
152         else if(!inSelection) {
153             return false;
154         }
155         g.setColor(SELECTION_COLOR);
156         g.setXORMode(SELECTION_XOR);
157         g.fillRect(0, 0, this.width, this.height);
158         g.setPaintMode();
159         return true;
160     }
161     
162     public boolean extractSelectionText(StringBuffer JavaDoc buffer, boolean inSelection, RenderableSpot startPoint, RenderableSpot endPoint) {
163         if(this == startPoint.renderable || this == endPoint.renderable) {
164             if(inSelection) {
165                 return false;
166             }
167         }
168         else if(!inSelection) {
169             return false;
170         }
171         buffer.append(' ');
172         return true;
173     }
174     
175     /* (non-Javadoc)
176      * @see org.xamjwg.html.renderer.BoundableRenderable#getRenderable(int, int)
177      */

178     public RenderableSpot getLowestRenderableSpot(int x, int y) {
179         return new RenderableSpot(this, x, y);
180     }
181 }
182
Popular Tags