1 21 24 package org.lobobrowser.html.renderer; 25 26 import java.awt.*; 27 import java.awt.event.MouseEvent ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.SortedSet ; 31 import java.util.TreeSet ; 32 33 import org.lobobrowser.html.*; 34 import org.lobobrowser.html.domimpl.*; 35 36 class RTable extends BaseElementRenderable { 37 private final TableMatrix tableMatrix; 38 private SortedSet positionedRenderables; 39 private int otherOrdinal; 40 41 public RTable(HTMLElementImpl modelNode, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext, RenderableContainer container) { 42 super(container, modelNode, pcontext); 43 this.tableMatrix = new TableMatrix(modelNode, pcontext, rcontext, frameContext, this, this); 44 } 45 46 public int getVAlign() { 47 return VALIGN_BASELINE; 49 } 50 51 protected void applyStyle() { 52 super.applyStyle(); 53 Insets bi = this.borderInsets; 54 if(bi == null) { 55 HTMLElementImpl element = (HTMLElementImpl) this.modelNode; 56 String borderText = element.getAttribute("border"); 57 int border = 0; 58 if(borderText != null) { 59 try { 60 border = Integer.parseInt(borderText); 61 if(border < 0) { 62 border = 0; 63 } 64 } catch(NumberFormatException nfe) { 65 } 67 } 68 if(border > 0) { 69 this.borderInsets = new Insets(border, border, border, border); 70 } 71 } 72 if(this.borderTopColor == null && this.borderLeftColor == null) { 73 this.borderTopColor = this.borderLeftColor = Color.LIGHT_GRAY; 74 } 75 if(this.borderBottomColor == null && this.borderRightColor == null) { 76 this.borderBottomColor = this.borderRightColor = Color.DARK_GRAY; 77 } 78 } 79 80 public void paint(Graphics g) { 81 try { 82 this.prePaint(g); 83 Dimension size = this.getSize(); 84 TableMatrix tm = this.tableMatrix; 86 tm.paint(g, size); 87 Collection prs = this.positionedRenderables; 88 if(prs != null) { 89 Iterator i = prs.iterator(); 90 while(i.hasNext()) { 91 PositionedRenderable pr = (PositionedRenderable) i.next(); 92 BoundableRenderable r = pr.renderable; 93 r.paintTranslated(g); 94 } 95 } 96 } finally { 97 super.paint(g); 99 } 100 } 101 102 private volatile int lastAvailWidth = -1; 103 private volatile int lastAvailHeight = -1; 104 106 public void doLayout(int availWidth, int availHeight, boolean expandWidth, boolean expandHeight) { 107 if (availWidth != this.lastAvailWidth || availHeight != this.lastAvailHeight) { 108 Collection prs = this.positionedRenderables; 109 if(prs != null) { 110 prs.clear(); 111 } 112 this.otherOrdinal = 0; 113 this.clearGUIComponents(); 114 this.clearDelayedPairs(); 115 this.applyStyle(); 116 this.lastAvailHeight = availHeight; 117 this.lastAvailWidth = availWidth; 118 TableMatrix tm = this.tableMatrix; 119 Insets insets = this.getInsets(false, false); 120 tm.reset(insets, availWidth, availHeight); 121 tm.build(availWidth, availHeight); 123 tm.doLayout(insets); 124 this.width = tm.getTableWidth(); 125 this.height = tm.getTableHeight(); 126 127 Collection pairs = this.delayedPairs; 132 if(pairs != null) { 133 Iterator i = pairs.iterator(); 134 while(i.hasNext()) { 135 DelayedPair pair = (DelayedPair) i.next(); 136 if(pair.targetParent == this) { 137 this.importDelayedPair(pair); 138 } 139 } 140 } 141 142 } else { 143 } 145 this.sendGUIComponentsToParent(); 146 this.sendDelayedPairsToParent(); 147 } 148 149 160 public void invalidateLayoutLocal() { 161 super.invalidateLayoutLocal(); 162 this.lastAvailHeight = -1; 163 this.lastAvailWidth = -1; 164 } 165 166 169 public RenderableSpot getLowestRenderableSpot(int x, int y) { 170 Collection prs = this.positionedRenderables; 171 if(prs != null) { 172 Iterator i = prs.iterator(); 173 while(i.hasNext()) { 174 PositionedRenderable pr = (PositionedRenderable) i.next(); 175 BoundableRenderable r = pr.renderable; 176 int childX = x - r.getX(); 177 int childY = y - r.getY(); 178 RenderableSpot rs = r.getLowestRenderableSpot(childX, childY); 179 if(rs != null) { 180 return rs; 181 } 182 } 183 } 184 RenderableSpot rs = this.tableMatrix.getLowestRenderableSpot(x, y); 185 if(rs != null) { 186 return rs; 187 } 188 return new RenderableSpot(this, x, y); 189 } 190 191 194 public boolean onMouseClick(MouseEvent event, int x, int y) { 195 Collection prs = this.positionedRenderables; 196 if(prs != null) { 197 Iterator i = prs.iterator(); 198 while(i.hasNext()) { 199 PositionedRenderable pr = (PositionedRenderable) i.next(); 200 BoundableRenderable r = pr.renderable; 201 Rectangle bounds = r.getBounds(); 202 if(bounds.contains(x, y)) { 203 int childX = x - r.getX(); 204 int childY = y - r.getY(); 205 if(!r.onMouseClick(event, childX, childY)) { 206 return false; 207 } 208 } 209 } 210 } 211 return this.tableMatrix.onMouseClick(event, x, y); 212 } 213 214 public boolean onDoubleClick(MouseEvent event, int x, int y) { 215 Collection prs = this.positionedRenderables; 216 if(prs != null) { 217 Iterator i = prs.iterator(); 218 while(i.hasNext()) { 219 PositionedRenderable pr = (PositionedRenderable) i.next(); 220 BoundableRenderable r = pr.renderable; 221 Rectangle bounds = r.getBounds(); 222 if(bounds.contains(x, y)) { 223 int childX = x - r.getX(); 224 int childY = y - r.getY(); 225 if(!r.onDoubleClick(event, childX, childY)) { 226 return false; 227 } 228 } 229 } 230 } 231 return this.tableMatrix.onDoubleClick(event, x, y); 232 } 233 234 237 public boolean onMouseDisarmed(MouseEvent event) { 238 return this.tableMatrix.onMouseDisarmed(event); 239 } 240 241 244 public boolean onMousePressed(MouseEvent event, int x, int y) { 245 Collection prs = this.positionedRenderables; 246 if(prs != null) { 247 Iterator i = prs.iterator(); 248 while(i.hasNext()) { 249 PositionedRenderable pr = (PositionedRenderable) i.next(); 250 BoundableRenderable r = pr.renderable; 251 Rectangle bounds = r.getBounds(); 252 if(bounds.contains(x, y)) { 253 int childX = x - r.getX(); 254 int childY = y - r.getY(); 255 if(!r.onMousePressed(event, childX, childY)) { 256 return false; 257 } 258 } 259 } 260 } 261 return this.tableMatrix.onMousePressed(event, x, y); 262 } 263 264 267 public boolean onMouseReleased(MouseEvent event, int x, int y) { 268 Collection prs = this.positionedRenderables; 269 if(prs != null) { 270 Iterator i = prs.iterator(); 271 while(i.hasNext()) { 272 PositionedRenderable pr = (PositionedRenderable) i.next(); 273 BoundableRenderable r = pr.renderable; 274 Rectangle bounds = r.getBounds(); 275 if(bounds.contains(x, y)) { 276 int childX = x - r.getX(); 277 int childY = y - r.getY(); 278 if(!r.onMouseReleased(event, childX, childY)) { 279 return false; 280 } 281 } 282 } 283 } 284 return this.tableMatrix.onMouseReleased(event, x, y); 285 } 286 287 290 public Iterator getRenderables() { 291 Collection prs = this.positionedRenderables; 292 if(prs != null) { 293 Collection c = new java.util.LinkedList (); 294 Iterator i = prs.iterator(); 295 while(i.hasNext()) { 296 PositionedRenderable pr = (PositionedRenderable) i.next(); 297 BoundableRenderable r = pr.renderable; 298 c.add(r); 299 } 300 Iterator i2 = this.tableMatrix.getRenderables(); 301 while(i2.hasNext()) { 302 c.add(i2.next()); 303 } 304 return c.iterator(); 305 } 306 else { 307 return this.tableMatrix.getRenderables(); 308 } 309 } 310 311 public void repaint(ModelNode modelNode) { 312 } 314 315 318 public Color getPaintedBackgroundColor() { 319 return this.container.getPaintedBackgroundColor(); 320 } 321 322 private final void addPositionedRenderable(BoundableRenderable renderable, boolean verticalAlignable) { 323 SortedSet others = this.positionedRenderables; 325 if(others == null) { 326 others = new TreeSet (new ZIndexComparator()); 327 this.positionedRenderables = others; 328 } 329 others.add(new PositionedRenderable(renderable, verticalAlignable, this.otherOrdinal++)); 330 renderable.setParent(this); 331 if(renderable instanceof RUIControl) { 332 this.container.add(((RUIControl) renderable).widget.getComponent()); 333 } 334 } 335 336 private void importDelayedPair(DelayedPair pair) { 337 BoundableRenderable r = pair.child; 338 r.setOrigin(pair.x, pair.y); 339 this.addPositionedRenderable(r, false); 340 } 341 342 public String toString() { 343 return "RTable[this=" + System.identityHashCode(this) + ",node=" + this.modelNode + "]"; 344 } 345 } 346 | Popular Tags |