1 package org.lobobrowser.html.renderer; 2 3 import java.awt.Graphics ; 4 import java.awt.Point ; 5 import java.awt.Rectangle ; 6 import java.util.Iterator ; 7 8 import org.lobobrowser.html.domimpl.ModelNode; 9 10 abstract class BaseRCollection extends BaseBoundableRenderable implements 11 RCollection { 12 public BaseRCollection(RenderableContainer container, ModelNode modelNode) { 13 super(container, modelNode); 14 } 15 16 public void focus() { 17 this.container.focus(); 18 } 20 21 public void blur() { 22 RCollection parent = this.parent; 23 if(parent != null) { 24 parent.focus(); 25 } 26 else { 27 } 29 } 30 31 35 public void updateWidgetBounds(int guiX, int guiY) { 36 Iterator i = this.getRenderables(); 37 if(i != null) { 38 while(i.hasNext()) { 39 Object r = i.next(); 40 if(r instanceof RCollection) { 41 RCollection rc = (RCollection) r; 43 rc.updateWidgetBounds(guiX + rc.getX(), guiY + rc.getY()); 44 } 45 } 46 } 47 } 48 49 private boolean checkStartSelection(Rectangle bounds, Point selectionPoint) { 50 if(bounds.y > selectionPoint.y) { 51 return true; 52 } 53 else if(selectionPoint.y >= bounds.y && selectionPoint.y < bounds.y + bounds.height && bounds.x > selectionPoint.x) { 54 return true; 55 } 56 else { 57 return false; 58 } 59 } 60 61 private boolean checkEndSelection(Rectangle bounds, Point selectionPoint) { 62 if(bounds.y > selectionPoint.y) { 63 return true; 64 } 65 else if(selectionPoint.y >= bounds.y && selectionPoint.y < bounds.y + bounds.height && selectionPoint.x < bounds.x) { 66 return true; 67 } 68 else { 69 return false; 70 } 71 } 72 73 public boolean paintSelection(Graphics g, boolean inSelection, RenderableSpot startPoint, RenderableSpot endPoint) { 74 Point checkPoint1 = null; 76 Point checkPoint2 = null; 77 if(!inSelection) { 78 boolean isStart = startPoint.renderable == this; 79 boolean isEnd = endPoint.renderable == this; 80 if(isStart && isEnd) { 81 checkPoint1 = startPoint.getPoint(); 82 checkPoint2 = endPoint.getPoint(); 83 } 84 else if(isStart) { 85 checkPoint1 = startPoint.getPoint(); 86 } 87 else if(isEnd) { 88 checkPoint1 = endPoint.getPoint(); 89 } 90 } 91 else { 92 if(startPoint.renderable == this) { 93 checkPoint1 = startPoint.getPoint(); 94 } 95 else if(endPoint.renderable == this) { 96 checkPoint1 = endPoint.getPoint(); 97 } 98 } 99 Iterator i = this.getRenderables(); 100 if(i != null) { 101 while(i.hasNext()) { 102 Object robj = i.next(); 103 if(robj instanceof BoundableRenderable) { 104 BoundableRenderable renderable = (BoundableRenderable) robj; 105 Rectangle bounds = renderable.getBounds(); 106 if(!inSelection) { 107 if(checkPoint1 != null && this.checkStartSelection(bounds, checkPoint1)) { 108 if(checkPoint2 != null) { 109 checkPoint1 = checkPoint2; 110 checkPoint2 = null; 111 } 112 else { 113 checkPoint1 = null; 114 } 115 inSelection = true; 116 } 117 else if(checkPoint2 != null && this.checkStartSelection(bounds, checkPoint2)) { 118 checkPoint1 = null; 119 checkPoint2 = null; 120 inSelection = true; 121 } 122 } 123 else if(inSelection && checkPoint1 != null && this.checkEndSelection(bounds, checkPoint1)) { 124 return false; 125 } 126 int offsetX = bounds.x; 127 int offsetY = bounds.y; 128 g.translate(offsetX, offsetY); 129 try { 130 boolean newInSelection = renderable.paintSelection(g, inSelection, startPoint, endPoint); 131 if(inSelection && !newInSelection) { 132 return false; 133 } 134 inSelection = newInSelection; 135 } finally { 136 g.translate(-offsetX, -offsetY); 137 } 138 } 139 } 140 } 141 if(inSelection && checkPoint1 != null) { 142 return false; 143 } 144 else if(!inSelection && (checkPoint1 != null || checkPoint2 != null) && !(checkPoint1 != null && checkPoint2 != null)) { 145 return true; 149 } 150 return inSelection; 151 } 152 153 public boolean extractSelectionText(StringBuffer buffer, boolean inSelection, RenderableSpot startPoint, RenderableSpot endPoint) { 154 Point checkPoint1 = null; 155 Point checkPoint2 = null; 156 if(!inSelection) { 157 boolean isStart = startPoint.renderable == this; 158 boolean isEnd = endPoint.renderable == this; 159 if(isStart && isEnd) { 160 checkPoint1 = startPoint.getPoint(); 161 checkPoint2 = endPoint.getPoint(); 162 } 163 else if(isStart) { 164 checkPoint1 = startPoint.getPoint(); 165 } 166 else if(isEnd) { 167 checkPoint1 = endPoint.getPoint(); 168 } 169 } 170 else { 171 if(startPoint.renderable == this) { 172 checkPoint1 = startPoint.getPoint(); 173 } 174 else if(endPoint.renderable == this) { 175 checkPoint1 = endPoint.getPoint(); 176 } 177 } 178 Iterator i = this.getRenderables(); 179 if(i != null) { 180 while(i.hasNext()) { 181 Object robj = i.next(); 182 if(robj instanceof BoundableRenderable) { 183 BoundableRenderable renderable = (BoundableRenderable) robj; 184 if(!inSelection) { 185 Rectangle bounds = renderable.getBounds(); 186 if(checkPoint1 != null && this.checkStartSelection(bounds, checkPoint1)) { 187 if(checkPoint2 != null) { 188 checkPoint1 = checkPoint2; 189 checkPoint2 = null; 190 } 191 else { 192 checkPoint1 = null; 193 } 194 inSelection = true; 195 } 196 else if(checkPoint2 != null && this.checkStartSelection(bounds, checkPoint2)) { 197 checkPoint1 = null; 198 checkPoint2 = null; 199 inSelection = true; 200 } 201 } 202 else if(inSelection && checkPoint1 != null && this.checkEndSelection(renderable.getBounds(), checkPoint1)) { 203 return false; 204 } 205 boolean newInSelection = renderable.extractSelectionText(buffer, inSelection, startPoint, endPoint); 206 if(inSelection && !newInSelection) { 207 return false; 208 } 209 inSelection = newInSelection; 210 } 211 } 212 } 213 if(inSelection && checkPoint1 != null) { 214 return false; 215 } 216 else if(!inSelection && (checkPoint1 != null || checkPoint2 != null) && !(checkPoint1 != null && checkPoint2 != null)) { 217 return true; 221 } 222 return inSelection; 223 } 224 225 public void invalidateLayoutDeep() { 226 this.invalidateLayoutLocal(); 230 Iterator renderables = this.getRenderables(); 231 while(renderables.hasNext()) { 232 Object r = renderables.next(); 233 if(r instanceof RCollection) { 234 ((RCollection) r).invalidateLayoutDeep(); 235 } 236 } 237 } 238 } 239 | Popular Tags |