Back to index

wims  3.65+svn20090927
DragThread.java
Go to the documentation of this file.
00001 /*
00002  * Created on 26.10.2005
00003  *
00004  */
00005 package rene.zirkel;
00006 
00007 import java.awt.event.MouseEvent;
00008 
00014 class DragThread extends Thread
00015 {      MouseEvent EWaiting=null;
00016        ZirkelCanvas ZC;
00017        Object Ready=new Object();
00018        boolean Working=false;
00019        
00020        public DragThread (ZirkelCanvas zc)
00021        {      ZC=zc;
00022               start();
00023        }
00024        
00025        public void run ()
00026        {      MouseEvent e;
00027               while (true)
00028               {      if (EWaiting==null)
00029                      {      try
00030                             {      synchronized (this)
00031                                    {      wait();
00032                                    }
00033                             }
00034                             catch (Exception ex) {}
00035                      }
00036                      if (EWaiting!=null)
00037                      {      synchronized (this)
00038                             {      e=EWaiting;
00039                                    EWaiting=null;
00040                             }
00041                             Working=true;
00042                             ZC.doMouseDragged(e);
00043                             try
00044                             {      sleep(0);
00045                             }
00046                             catch (Exception ex) {}
00047                             Working=false;
00048                             synchronized (Ready)
00049                             {      Ready.notify();
00050                             }
00051                      }
00052               }
00053        }
00054        
00055        public synchronized void mouseDragged (MouseEvent e)
00056        {      EWaiting=e;
00057               notify();
00058        }
00059        
00060        public void waitReady ()
00061        {      if (!Working) return;
00062               synchronized (Ready)
00063               {      try
00064                      {      Thread.currentThread().wait(1000);
00065                      }
00066                      catch (Exception ex) {}
00067               }
00068        }
00069 }
00070 
00071