1 22 23 27 28 package org.netbeans.lib.terminalemulator; 29 30 import java.util.LinkedList ; 31 import java.util.ListIterator ; 32 33 public class ActiveRegion { 34 public Coord begin = new Coord(); 35 public Coord end = new Coord(); 36 37 ActiveRegion parent; 39 boolean nested; 40 41 private LinkedList children; 42 private boolean has_end; 43 44 ActiveRegion(ActiveRegion parent, Coord begin, boolean nested) { 45 this.parent = parent; 46 this.begin.copyFrom(begin); 47 this.nested = nested; 48 } 49 50 public ActiveRegion parent() { 51 return this.parent; 52 } 53 54 public Extent getExtent() { 55 if (has_end) 56 return new Extent(begin, end); 57 else 58 return new Extent(begin, begin); 59 } 60 61 void setEnd(Coord end) { 62 this.end.copyFrom(end); 63 has_end = true; 64 } 65 66 void addChild(ActiveRegion child) { 67 if (children == null) 68 children = new LinkedList (); 69 children.add(child); 70 } 71 72 void removeChild(ActiveRegion child) { 73 if (children == null) 74 return; 75 children.remove(child); 76 } 77 78 ActiveRegion contains(Coord coord) { 79 80 boolean coord_past_end = has_end && coord.compareTo(end) > 0; 83 if (this.parent != null && (coord.compareTo(begin) < 0 || 84 coord_past_end)) { 85 return null; } 87 88 if (children != null) { 89 ListIterator iter = children.listIterator(); 90 while(iter.hasNext()) { 91 ActiveRegion child = (ActiveRegion) iter.next(); 92 if (coord.compareTo(child.begin) < 0) 93 break; ActiveRegion target = child.contains(coord); 96 if (target != null) 97 return target; 98 } 99 } 100 return this; 101 } 102 103 104 106 void relocate(int delta) { 107 this.begin.row += delta; 108 this.end.row += delta; 109 if (children != null) { 110 ListIterator iter = children.listIterator(); 111 while(iter.hasNext()) { 112 ActiveRegion child = (ActiveRegion) iter.next(); 113 child.relocate(delta); 114 } 115 } 116 } 117 118 void cull(int origin) { 119 120 123 if (children == null) 124 return; 125 126 int nculled = 0; 127 128 ListIterator iter = children.listIterator(); 129 while(iter.hasNext()) { 130 ActiveRegion child = (ActiveRegion) iter.next(); 131 if (child.begin.row < origin) { 132 iter.remove(); 133 nculled++; 134 } else 135 break; } 137 138 } 140 141 142 147 public void setSelectable(boolean selectable) { 148 this.selectable = selectable; 149 } 150 151 154 public boolean isSelectable() { 155 return selectable; 156 } 157 private boolean selectable; 158 159 160 166 public void setFeedbackEnabled(boolean feedback) { 167 this.feedback_enabled = feedback; 168 } 169 170 173 public boolean isFeedbackEnabled() { 174 return feedback_enabled; 175 } 176 private boolean feedback_enabled; 177 178 182 public void setFeedbackViaParent(boolean feedback_via_parent) { 183 this.feedback_via_parent = feedback_via_parent; 184 } 185 186 public boolean isFeedbackViaParent() { 187 return feedback_via_parent; 188 } 189 190 private boolean feedback_via_parent; 191 192 195 public void setLink(boolean link) { 196 this.link = link; 197 } 198 public boolean isLink() { 199 return link; 200 } 201 private boolean link; 202 203 204 205 208 public void setUserObject(Object object) { 209 this.user_object = object; 210 } 211 212 216 public Object getUserObject() { 217 return user_object; 218 } 219 private Object user_object; 220 221 222 223 240 241 244 public ActiveRegion firstChild() { 245 if (children == null) 246 return null; 247 return (ActiveRegion) children.getFirst(); 248 } 249 250 253 public ActiveRegion lastChild() { 254 if (children == null) 255 return null; 256 return (ActiveRegion) children.getLast(); 257 } 258 259 260 263 public ActiveRegion getPreviousSibling() { 264 if (parent != null) 265 return parent.previous_sibling_of(this); 266 else 267 return null; 268 } 269 270 273 public ActiveRegion getNextSibling() { 274 if (parent != null) 275 return parent.next_sibling_of(this); 276 else 277 return null; 278 } 279 280 private ActiveRegion previous_sibling_of(ActiveRegion child) { 281 ListIterator iter = children.listIterator(); 282 ActiveRegion previousChild = null; 283 while (iter.hasNext()) { 284 ActiveRegion candidate = (ActiveRegion) iter.next(); 285 if (candidate == child) { 286 return previousChild; 290 } 291 previousChild = candidate; 292 } 293 return null; 294 } 295 296 private ActiveRegion next_sibling_of(ActiveRegion child) { 297 ListIterator iter = children.listIterator(); 298 while (iter.hasNext()) { 299 ActiveRegion candidate = (ActiveRegion) iter.next(); 300 if (candidate == child) { 301 return (ActiveRegion) (iter.hasNext()? iter.next(): null); 302 } 303 } 304 return null; 305 } 306 } 307 | Popular Tags |