1 package org.joshy.html.box; 2 3 import java.awt.Color ; 4 import java.awt.Image ; 5 import org.joshy.html.Border; 6 import org.w3c.dom.Node ; 7 import org.w3c.dom.Element ; 8 import java.util.List ; 9 import java.util.ArrayList ; 10 import java.awt.Dimension ; 11 import java.util.Iterator ; 12 import org.joshy.u; 13 14 public class Box { 15 public int x; 17 public int y; 18 public int width; 19 public int height; 20 21 public int getHeight() { 22 return height; 23 } 24 25 public int getWidth() { 26 return width; 27 } 28 29 35 36 public boolean contains(int x, int y) { 37 if((x >= 0) && (x<= 0 + this.width)) { 38 if((y>=0) && (y<=0 + this.height)) { 39 return true; 40 } 41 } 42 49 return false; 50 } 51 52 public Node node; 54 private Box parent; 55 56 public Box getParent() { 57 return parent; 58 } 59 public void setParent(Box box) { 60 this.parent = box; 61 } 62 63 public boolean display_none = false; 65 66 public boolean relative = false; 68 public boolean fixed = false; 69 public int top = 0; 70 public int right = 0; 71 public boolean right_set = false; 72 public int bottom = 0; 73 public boolean bottom_set = false; 74 public int left = 0; 75 public boolean floated = false; 76 77 public Color border_color; 79 public Border padding; 80 public Border border; 81 public Border margin; 82 public String border_style; 83 84 public Box click_styles; 85 86 public Color color; 88 89 public Color background_color; 91 public Image background_image; 92 public String repeat; 93 public String attachment; 94 public int background_position_vertical = 0; 95 public int background_position_horizontal = 0; 96 public boolean clicked = false; 97 98 private List boxes; 100 public void addChild(Box child) { 101 child.setParent(this); 102 boxes.add(child); 103 } 105 106 public int getChildCount() { 107 return boxes.size(); 108 } 109 110 public Box getChild(int i) { 111 return (Box) boxes.get(i); 112 } 113 114 public Iterator getChildIterator() { 115 return boxes.iterator(); 116 } 117 118 119 public Element getElement() { 121 return (Element )node; 122 } 123 public boolean isElement() { 124 if(node.getNodeType() == node.ELEMENT_NODE) { 125 return true; 126 } 127 return false; 128 } 129 public boolean isAnonymous() { 130 return false; 131 } 132 133 public Box() { 135 this(true); 136 } 137 138 public Box(boolean create_substyles) { 139 boxes = new ArrayList (); 140 if(create_substyles) { 141 this.click_styles = new Box(false); 142 } 143 } 144 145 public Box(int x, int y, int width, int height) { 146 this(); 147 this.x = x; 148 this.y = y; 149 this.width = width; 150 this.height = height; 151 } 152 153 public Dimension getInternalDimension() { 154 int w = this.getWidth() - totalHorizontalPadding(); 155 int h = this.getHeight() - totalVerticalPadding(); 156 return new Dimension (w,h); 157 } 158 public int totalHorizontalPadding() { 159 int pd = 0; 160 if(this.margin != null) { 161 pd+= this.margin.left + this.margin.right; 162 } 163 if(this.padding != null) { 164 pd+= this.padding.left + this.padding.right; 165 } 166 if(this.border != null) { 167 pd+= this.border.left + this.border.right; 168 } 169 return pd; 170 } 171 public int totalVerticalPadding() { 172 int pd = 0; 173 if(this.margin != null) { 174 pd+= this.margin.top + this.margin.bottom; 175 } 176 if(this.padding != null) { 177 pd+= this.padding.top + this.padding.bottom; 178 } 179 if(this.border != null) { 180 pd+= this.border.top + this.border.bottom; 181 } 182 return pd; 183 } 184 185 public int totalTopPadding() { 186 int pd = 0; 187 if(this.margin != null) { 188 pd+= this.margin.top; 189 } 190 if(this.padding != null) { 191 pd+= this.padding.top; 192 } 193 if(this.border != null) { 194 pd+= this.border.top; 195 } 196 return pd; 197 } 198 199 public int totalLeftPadding() { 200 int pd = 0; 201 if(this.margin != null) { pd+= this.margin.left; } 202 if(this.padding != null) { pd+= this.padding.left; } 203 if(this.border != null) { pd+= this.border.left; } 204 return pd; 205 } 206 207 public String toString() { 208 StringBuffer sb = new StringBuffer (); 209 sb.append("Box: "); 210 if(node == null) { 211 sb.append(" null node, "); 212 } else { 213 sb.append(node.getNodeName()); 214 } 215 sb.append(" (" + x + ","+y+")->("+width+" x "+height+")"); 216 return sb.toString(); 217 } 218 219 } 220 | Popular Tags |