1 22 23 27 28 package org.netbeans.lib.terminalemulator; 29 30 import java.awt.*; 31 import java.awt.event.*; 32 33 public class ActiveTerm extends StreamTerm { 34 35 private ActiveTermListener at_listener; 36 37 private RegionManager rm; 38 39 private Coord last_begin = null; 40 private Coord last_end = null; 41 42 public ActiveTerm() { 43 super(); 44 45 setCursorVisible(false); 46 47 rm = regionManager(); 48 49 getScreen().addMouseListener(new MouseAdapter() { 50 public void mouseClicked(MouseEvent e) { 51 if ( (e.getModifiers() & InputEvent.BUTTON1_MASK) != 52 InputEvent.BUTTON1_MASK) { 53 return; 55 } 56 Point p = mapToBufRowCol(e.getPoint()); 57 BCoord c = new BCoord(p.y, p.x); 58 Coord ac = new Coord(c, firsta); 59 ActiveRegion region = rm.findRegion(ac); 60 if (region != null) { 61 if (region.isSelectable()) 62 setSelectionExtent(region.getExtent()); 63 if (at_listener != null) 64 at_listener.action(region, e); 65 } 66 } 67 } ); 68 69 getScreen().addMouseMotionListener(new MouseMotionAdapter() { 70 public void mouseMoved(MouseEvent e) { 71 Point p = mapToBufRowCol(e.getPoint()); 72 BCoord c = new BCoord(p.y, p.x); 73 Coord ac = new Coord(c, firsta); 74 ActiveRegion region = rm.findRegion(ac); 75 ActiveRegion hl_region = findRegionToHilite(region); 76 77 if (hl_region == null) 78 hilite(null, null); 79 else 80 hilite(hl_region.begin, hl_region.end); 81 } 82 } ); 83 } 84 85 private ActiveRegion findRegionToHilite(ActiveRegion region) { 86 if (region == null) 87 return null; 88 else if (region.isFeedbackEnabled()) 89 return region; 90 else if (region.isFeedbackViaParent()) 91 return findRegionToHilite(region.parent()); 92 else 93 return null; 94 } 95 96 public void setActionListener(ActiveTermListener listener) { 97 this.at_listener = listener; 98 } 99 100 private void hilite_help(Coord begin, Coord end, boolean on) { 101 if (begin == null && end == null) 102 return; setCharacterAttribute(begin, end, 9, on); 104 } 105 106 public void hilite(Coord begin, Coord end) { 107 if (end != null && end.row == 1 && end.col == 0) 108 end = getCursorCoord(); 109 hilite_help(last_begin, last_end, false); 110 last_begin = (begin == null)? null: (Coord) begin.clone(); 111 last_end = (end == null)? null: (Coord) end.clone(); 112 hilite_help(begin, end, true); 113 } 114 115 public void hilite(ActiveRegion region) { 116 hilite(region.begin, region.end); 117 } 118 119 public ActiveRegion beginRegion(boolean hyperlink) { 120 ActiveRegion region = null; 121 try { 122 region = rm.beginRegion(getCursorCoord()); 123 } catch (RegionException x) { 124 ; 125 } 126 if (hyperlink) { 127 setAttribute(34); setAttribute(4); } 130 return region; 131 } 132 133 public void endRegion() { 134 Coord cursor = getCursorCoord(); 135 Coord bcursor = backup(cursor); 136 137 if (bcursor == null) 140 bcursor = cursor; 141 142 try { 143 rm.endRegion(bcursor); 144 } catch (RegionException x) { 145 ; 146 } 147 setAttribute(0); } 149 150 public ActiveRegion findRegion(Coord coord) { 151 return rm.findRegion(coord); 152 } 153 154 public void cancelRegion() { 155 try { 156 rm.cancelRegion(); 157 } catch (RegionException x) { 158 ; 159 } 160 } 161 162 public void clear() { 163 nullLasts(); 164 super.clear (); 165 } 166 167 public void clearHistoryNoRefresh() { 168 nullLasts(); 169 super.clearHistoryNoRefresh (); 170 } 171 172 private void nullLasts() { 173 last_begin = null; 174 last_end = null; 175 } 176 } 177 | Popular Tags |