1 22 23 27 28 package org.netbeans.lib.terminalemulator; 29 30 31 public class RegionManager { 32 private ActiveRegion root = new ActiveRegion(null, new Coord(), false); 33 private ActiveRegion parent = null; 34 private ActiveRegion region = root; 35 36 39 public void reset() { 40 root = new ActiveRegion(null, new Coord(), false); 41 parent = null; 42 region = root; 43 } 44 45 48 public ActiveRegion root() { 49 return root; 50 } 51 52 59 public ActiveRegion beginRegion(Coord begin) throws RegionException { 60 if (region != null) { 61 ActiveRegion child = new ActiveRegion(region, begin, true); 63 region.addChild(child); 64 parent = region; 65 region = child; 66 67 } else { 68 region = new ActiveRegion(parent, begin, false); 70 parent.addChild(region); 71 } 72 73 return region; 74 } 75 76 81 public void endRegion(Coord end) throws RegionException { 82 if (region == null) { 83 throw new RegionException("endRegion(): ", "no current active region"); } else if (region == root) { 86 throw new RegionException("endRegion(): ", "cannot end root region"); } 89 90 region.setEnd(end); 91 92 if (region.nested) { 93 region = parent; 94 parent = region.parent; 95 } else { 96 region = null; 97 } 98 } 99 100 106 public void cancelRegion() throws RegionException { 107 if (region == null) { 108 throw new RegionException("cancelRegion(): ", "no current active region"); } else if (region == root) { 111 throw new RegionException("cancelRegion(): ", "cannot cancel root region"); } 114 115 parent.removeChild(region); 116 region = null; 117 } 118 119 127 128 133 public ActiveRegion findRegion(Coord acoord) { 134 return root.contains(acoord); 136 } 137 138 141 void relocate(int from, int to) { 142 int delta = to - from; 143 root.relocate(delta); 144 } 145 146 156 void cull(int origin) { 157 root.cull(origin); 158 } 159 } 160 | Popular Tags |