Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/util/PopupReaper.java

    r315 r1102  
    1313import javax.swing.SwingUtilities;
    1414
    15 import org.expeditee.gui.MouseEventRouter;
     15import org.expeditee.gio.swing.MouseEventRouter;
    1616import org.expeditee.gui.Popup;
    1717import org.expeditee.gui.PopupManager;
     
    1919
    2020/**
    21  * Yet another daemon .. whos job is to hide popups after their lifetimes have passed
     21 * Yet another daemon .. whose job is to hide popups after their lifetimes have passed
    2222 *
    2323 * @author Brook Novak
    2424 */
    2525
    26 public class PopupReaper {
    27        
     26public class PopupReaper
     27{
    2828        private Map<Popup, TemporaryPopup> tempPopups = new HashMap<Popup, TemporaryPopup>();// SHARED RESOURCE - the locker
    2929
     
    3131       
    3232        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        {
    3640                return instance;
    3741        }
     
    6266         *
    6367         */
    64         public void initPopupLifetime(Popup p, PopupAnimator hideAnimation, int lifetime) {
     68        public void initPopupLifetime(Popup p, PopupAnimator hideAnimation, int lifetime)
     69        {
    6570                if (p == null) throw new NullPointerException("p");
    6671                if (lifetime < 0) throw new IllegalArgumentException("lifetime < 0");
     
    8792                                reaper.interrupt();
    8893                        }
    89                        
    90 
    91                        
    92                 }
    93                
     94                }
    9495        }
    9596       
     
    115116         *
    116117         */
    117         public boolean revivePopup(Popup p, int lifetime) {
     118        public boolean revivePopup(Popup p, int lifetime)
     119        {
    118120                if (p == null) throw new NullPointerException("p");
    119121                if (lifetime < 0) throw new IllegalArgumentException("lifetime < 0");
     
    134136
    135137       
    136         private class ReapDaemon extends Thread {
    137                
    138                 ReapDaemon() {
     138        private class ReapDaemon extends Thread
     139        {
     140                ReapDaemon()
     141                {
    139142                        super("Popup Reaper");
    140143                        super.setPriority(Thread.MIN_PRIORITY);
     
    142145                }
    143146       
    144                 public void run() {
    145                        
     147                public void run()
     148                {
    146149                        while (true) {
    147150                       
     
    166169                 *              A Positive wait time, or a negative for nothing to to wait on.
    167170                 */
    168                 private long reap() {
    169 
     171                private long reap()
     172                {
    170173                        Collection<TemporaryPopup> snapshot;
    171174                       
     
    226229         *
    227230         */
    228         private class DoHide implements Runnable {
    229                
     231        private class DoHide implements Runnable
     232        {
    230233                private TemporaryPopup tempPopup;
    231234                public boolean didHide = false;
    232235               
    233                 public DoHide(TemporaryPopup tempPopup) {
     236                public DoHide(TemporaryPopup tempPopup)
     237                {
    234238                        this.tempPopup = tempPopup;
    235239                }
     
    244248                 *              True if screenPoint is over c.
    245249                 */
    246                 private boolean isPointInComponant(Component c, Point screenPoint) {
     250                private boolean isPointInComponant(Component c, Point screenPoint)
     251                {
    247252                        assert(c != null);
    248253                        assert(screenPoint != null);
     
    257262                }
    258263       
    259                 public void run() {
     264                public void run()
     265                {
    260266                        assert(tempPopup != null);
    261267                       
    262268                        MouseEvent me = MouseEventRouter.getCurrentMouseEvent();
    263269                        if (me != null) {
    264                                
    265                                 if (isPointInComponant(tempPopup.popup, me.getLocationOnScreen()))
    266                                         return;
     270                                if (isPointInComponant(tempPopup.popup, me.getLocationOnScreen())) return;
    267271                               
    268272                                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;
    272275                        }
    273276
     
    289292         *
    290293         */
    291         private class TemporaryPopup implements Comparable {
    292 
     294        private class TemporaryPopup implements Comparable<TemporaryPopup>
     295        {
    293296                private Popup popup;
    294297                private PopupAnimator hideAnim;
     
    310313                 *
    311314                 */
    312                 public TemporaryPopup(Popup popup, PopupAnimator anim, int lifetime) {
     315                public TemporaryPopup(Popup popup, PopupAnimator anim, int lifetime)
     316                {
    313317                        assert(popup != null);
    314318                        assert(lifetime >= 0);
     
    320324                }
    321325
    322                 public void setNewLifetime(int lifetime) {
     326                public void setNewLifetime(int lifetime)
     327                {
    323328                        assert(lifetime >= 0);
    324329                        this.lifetime = lifetime;
     
    326331                }
    327332               
    328                 public void resetLifetime() {
     333                public void resetLifetime()
     334                {
    329335                        setNewLifetime(lifetime);
    330336                }
    331337               
    332                 public long getDelay() {
     338                public long getDelay()
     339                {
    333340                        return destructionTime - System.currentTimeMillis();
    334341                }
     
    337344                 * {@inheritDoc}
    338345                 */
    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;
    348353                     
    349354                        return 0;
Note: See TracChangeset for help on using the changeset viewer.