KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The XAMJ 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.renderer;
22
23 import java.awt.*;
24
25 class OffsetFloatingBounds implements FloatingBounds {
26     private final FloatingBounds ancestorFloatingBounds;
27     private final RBlockViewport ancestor;
28     private final RBlockViewport target;
29     private final Insets ancestorPadding;
30     private final Insets targetPadding;
31     
32     public OffsetFloatingBounds(final FloatingBounds ancestorFloatingBounds, final RBlockViewport ancestor, Insets ancestorPadding, final RBlockViewport target, Insets targetPadding) {
33         this.ancestorFloatingBounds = ancestorFloatingBounds;
34         this.ancestor = ancestor;
35         this.target = target;
36         this.ancestorPadding = ancestorPadding;
37         this.targetPadding = targetPadding;
38     }
39
40     public int getClearY(int y) {
41         int ancestorY = this.translateToAncestorY(y);
42         int ancestorClearY = this.ancestorFloatingBounds.getClearY(ancestorY);
43         return this.translateAncestorY(ancestorClearY);
44     }
45
46     public int getLeft(int y) {
47         int ancestorY = this.translateToAncestorY(y);
48         Insets ap = this.ancestorPadding;
49         int aleft = ap == null ? 0 : ap.left;
50         int ancestorX = this.ancestorFloatingBounds.getLeft(ancestorY) + aleft;
51         Insets tp = this.targetPadding;
52         int tleft = tp == null ? 0 : tp.left;
53         int localX = this.translateAncestorX(ancestorX) - tleft;
54         return localX > 0 ? localX : 0;
55     }
56
57     public int getRight(int y) {
58         int ancestorY = this.translateToAncestorY(y);
59         Insets ancestorPadding = this.ancestorPadding;
60         Insets targetPadding = this.targetPadding;
61         int aleft = ancestorPadding == null ? 0 : ancestorPadding.left;
62         int tleft = targetPadding == null ? 0 : targetPadding.left;
63         int ancestorX = aleft + this.ancestor.getAvailContentWidth() - this.ancestorFloatingBounds.getRight(ancestorY);
64         int right = tleft + this.target.getAvailContentWidth() - this.translateAncestorX(ancestorX);
65         return right > 0 ? right : 0;
66     }
67     
68     private final int translateToAncestorY(int y) {
69         //OPTIMIZE: It could be assumed that the offset is always the same?
70
RBlockViewport ancestor = this.ancestor;
71         BoundableRenderable current = this.target;
72         while(current != null && current != ancestor) {
73             y += current.getY();
74             current = current.getParent();
75         }
76         return y;
77     }
78
79     private final int translateAncestorY(int y) {
80         //OPTIMIZE: It could be assumed that the offset is always the same?
81
RBlockViewport ancestor = this.ancestor;
82         BoundableRenderable current = this.target;
83         while(current != null && current != ancestor) {
84             y -= current.getY();
85             current = current.getParent();
86         }
87         return y;
88     }
89
90     private final int translateAncestorX(int x) {
91         //OPTIMIZE: It could be assumed that the offset is always the same?
92
RBlockViewport ancestor = this.ancestor;
93         BoundableRenderable current = this.target;
94         while(current != null && current != ancestor) {
95             x -= current.getX();
96             current = current.getParent();
97         }
98         return x;
99     }
100     
101     public boolean equals(Object JavaDoc other) {
102         if(!(other instanceof OffsetFloatingBounds)) {
103             return false;
104         }
105         OffsetFloatingBounds ofb = (OffsetFloatingBounds) other;
106         return ofb.ancestor == this.ancestor &&
107             ofb.target == this.target &&
108             org.lobobrowser.util.Objects.equals(ofb.ancestorFloatingBounds, this.ancestorFloatingBounds);
109     }
110 }
111
Popular Tags