Changeset 1102 for trunk/src/org/apollo/util/PopupReaper.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/util/PopupReaper.java
r315 r1102 13 13 import javax.swing.SwingUtilities; 14 14 15 import org.expeditee.g ui.MouseEventRouter;15 import org.expeditee.gio.swing.MouseEventRouter; 16 16 import org.expeditee.gui.Popup; 17 17 import org.expeditee.gui.PopupManager; … … 19 19 20 20 /** 21 * Yet another daemon .. whos job is to hide popups after their lifetimes have passed21 * Yet another daemon .. whose job is to hide popups after their lifetimes have passed 22 22 * 23 23 * @author Brook Novak 24 24 */ 25 25 26 public class PopupReaper {27 26 public class PopupReaper 27 { 28 28 private Map<Popup, TemporaryPopup> tempPopups = new HashMap<Popup, TemporaryPopup>();// SHARED RESOURCE - the locker 29 29 … … 31 31 32 32 private static PopupReaper instance = new PopupReaper(); 33 private PopupReaper() { 34 } 35 public static PopupReaper getInstance() { 33 34 private PopupReaper() 35 { 36 } 37 38 public static PopupReaper getInstance() 39 { 36 40 return instance; 37 41 } … … 62 66 * 63 67 */ 64 public void initPopupLifetime(Popup p, PopupAnimator hideAnimation, int lifetime) { 68 public void initPopupLifetime(Popup p, PopupAnimator hideAnimation, int lifetime) 69 { 65 70 if (p == null) throw new NullPointerException("p"); 66 71 if (lifetime < 0) throw new IllegalArgumentException("lifetime < 0"); … … 87 92 reaper.interrupt(); 88 93 } 89 90 91 92 } 93 94 } 94 95 } 95 96 … … 115 116 * 116 117 */ 117 public boolean revivePopup(Popup p, int lifetime) { 118 public boolean revivePopup(Popup p, int lifetime) 119 { 118 120 if (p == null) throw new NullPointerException("p"); 119 121 if (lifetime < 0) throw new IllegalArgumentException("lifetime < 0"); … … 134 136 135 137 136 private class ReapDaemon extends Thread { 137 138 ReapDaemon() { 138 private class ReapDaemon extends Thread 139 { 140 ReapDaemon() 141 { 139 142 super("Popup Reaper"); 140 143 super.setPriority(Thread.MIN_PRIORITY); … … 142 145 } 143 146 144 public void run() {145 147 public void run() 148 { 146 149 while (true) { 147 150 … … 166 169 * A Positive wait time, or a negative for nothing to to wait on. 167 170 */ 168 private long reap() {169 171 private long reap() 172 { 170 173 Collection<TemporaryPopup> snapshot; 171 174 … … 226 229 * 227 230 */ 228 private class DoHide implements Runnable {229 231 private class DoHide implements Runnable 232 { 230 233 private TemporaryPopup tempPopup; 231 234 public boolean didHide = false; 232 235 233 public DoHide(TemporaryPopup tempPopup) { 236 public DoHide(TemporaryPopup tempPopup) 237 { 234 238 this.tempPopup = tempPopup; 235 239 } … … 244 248 * True if screenPoint is over c. 245 249 */ 246 private boolean isPointInComponant(Component c, Point screenPoint) { 250 private boolean isPointInComponant(Component c, Point screenPoint) 251 { 247 252 assert(c != null); 248 253 assert(screenPoint != null); … … 257 262 } 258 263 259 public void run() { 264 public void run() 265 { 260 266 assert(tempPopup != null); 261 267 262 268 MouseEvent me = MouseEventRouter.getCurrentMouseEvent(); 263 269 if (me != null) { 264 265 if (isPointInComponant(tempPopup.popup, me.getLocationOnScreen())) 266 return; 270 if (isPointInComponant(tempPopup.popup, me.getLocationOnScreen())) return; 267 271 268 272 Component invoker = PopupManager.getInstance().getInvoker(tempPopup.popup); 269 if (invoker != null && isPointInComponant(invoker, me.getLocationOnScreen())) 270 return; 271 273 274 if (invoker != null && isPointInComponant(invoker, me.getLocationOnScreen())) return; 272 275 } 273 276 … … 289 292 * 290 293 */ 291 private class TemporaryPopup implements Comparable {292 294 private class TemporaryPopup implements Comparable<TemporaryPopup> 295 { 293 296 private Popup popup; 294 297 private PopupAnimator hideAnim; … … 310 313 * 311 314 */ 312 public TemporaryPopup(Popup popup, PopupAnimator anim, int lifetime) { 315 public TemporaryPopup(Popup popup, PopupAnimator anim, int lifetime) 316 { 313 317 assert(popup != null); 314 318 assert(lifetime >= 0); … … 320 324 } 321 325 322 public void setNewLifetime(int lifetime) { 326 public void setNewLifetime(int lifetime) 327 { 323 328 assert(lifetime >= 0); 324 329 this.lifetime = lifetime; … … 326 331 } 327 332 328 public void resetLifetime() { 333 public void resetLifetime() 334 { 329 335 setNewLifetime(lifetime); 330 336 } 331 337 332 public long getDelay() { 338 public long getDelay() 339 { 333 340 return destructionTime - System.currentTimeMillis(); 334 341 } … … 337 344 * {@inheritDoc} 338 345 */ 339 public int compareTo(Object o) { 340 341 long dt2 = ((TemporaryPopup)o).destructionTime; 342 343 if (destructionTime < dt2) 344 return -1; 345 346 if (destructionTime > dt2) 347 return 1; 346 public int compareTo(TemporaryPopup o) 347 { 348 long dt2 = o.destructionTime; 349 350 if (destructionTime < dt2) return -1; 351 352 if (destructionTime > dt2) return 1; 348 353 349 354 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.