home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / corel / BARISTA / AUTOSCROLL.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-24  |  4.4 KB  |  229 lines

  1. import corel.transitions.Transition;
  2. import java.applet.AudioClip;
  3.  
  4. public class AutoScroll implements Runnable {
  5.    public static final int m_iConstScrollOnUndefined = 0;
  6.    public static final int m_iConstScrollOnTime = 1;
  7.    public static final int m_iConstScrollOnEvents = 2;
  8.    public static final int m_iConstScrollOnSound = 3;
  9.    public static final int m_iConstStatusScrollingStopped = 1;
  10.    private VDoc m_Document;
  11.    private int[] m_iAutoScrollPauseTypes;
  12.    private long[] m_lAutoScrollPauseTimes;
  13.    private String[] m_strAutoScrollPauseSounds;
  14.    private boolean[] m_bNonDefaultValues;
  15.    private boolean m_bForward;
  16.    private boolean m_bScrollingStopped;
  17.    private Thread m_ThreadAutoScroll;
  18.    private boolean m_bViewUpdated;
  19.    private Transition m_Transition;
  20.    private AudioClip m_AudioClip;
  21.  
  22.    public AutoScroll(VDoc var1, int var2) {
  23.       int var4 = var1.m_nNumOfPages;
  24.       this.m_Document = var1;
  25.       this.m_iAutoScrollPauseTypes = new int[var4];
  26.       this.m_lAutoScrollPauseTimes = new long[var4];
  27.       this.m_strAutoScrollPauseSounds = new String[var4];
  28.       this.m_bNonDefaultValues = new boolean[var4];
  29.  
  30.       for(int var3 = 0; var3 < var4; ++var3) {
  31.          this.m_iAutoScrollPauseTypes[var3] = 2;
  32.       }
  33.  
  34.       this.m_Transition = new Transition(this.m_Document.m_Applet, var4, this.m_Document.m_Applet.GetVersionStatusString());
  35.    }
  36.  
  37.    public void run() {
  38.       this.m_bViewUpdated = false;
  39.       this.DoScrollActions();
  40.       if (this.m_ThreadAutoScroll.isAlive()) {
  41.          try {
  42.             this.m_ThreadAutoScroll.stop();
  43.          } catch (ThreadDeath var2) {
  44.             this.m_ThreadAutoScroll = null;
  45.             throw var2;
  46.          }
  47.       }
  48.    }
  49.  
  50.    private final void DoScrollActions() {
  51.       label40: {
  52.          if (this.m_Document.m_nNumOfPages > 1 && (this.m_bForward && this.m_Document.m_iCurrPage < this.m_Document.m_nNumOfPages || !this.m_bForward && this.m_Document.m_iCurrPage > 1)) {
  53.             switch (this.m_iAutoScrollPauseTypes[this.m_Document.m_iCurrPage - 1]) {
  54.                case 1:
  55.                case 3:
  56.                   if (this.m_Transition.DoingTransition()) {
  57.                      do {
  58.                         this.WaitScrollTime(200L);
  59.                      } while(this.m_Transition.DoingTransition());
  60.                   }
  61.  
  62.                   if (!this.WaitScrollTime(0L)) {
  63.                      break;
  64.                   }
  65.  
  66.                   if (this.m_bScrollingStopped) {
  67.                      return;
  68.                   }
  69.                case 2:
  70.                   break label40;
  71.             }
  72.          }
  73.  
  74.          return;
  75.       }
  76.  
  77.       this.ScrollPage();
  78.    }
  79.  
  80.    public final boolean Start(boolean var1, boolean var2, boolean var3) {
  81.       if (var3) {
  82.          if (!this.m_bScrollingStopped) {
  83.             this.m_bScrollingStopped = true;
  84.             this.ShowStatus();
  85.             this.NotifyScrollTime();
  86.             if (this.m_AudioClip != null) {
  87.                this.m_AudioClip.stop();
  88.             }
  89.  
  90.             return true;
  91.          }
  92.  
  93.          this.m_bScrollingStopped = false;
  94.          this.ShowStatus();
  95.          this.PlayAudioClip(this.m_Document.m_iCurrPage - 1);
  96.          if (this.m_iAutoScrollPauseTypes[this.m_Document.m_iCurrPage - 1] == 2) {
  97.             return true;
  98.          }
  99.       } else if (this.m_bScrollingStopped) {
  100.          return true;
  101.       }
  102.  
  103.       switch (this.m_iAutoScrollPauseTypes[this.m_Document.m_iCurrPage - 1]) {
  104.          case 1:
  105.          case 3:
  106.             if (!this.m_bViewUpdated) {
  107.                return false;
  108.             }
  109.             break;
  110.          case 2:
  111.             if (!var1) {
  112.                return false;
  113.             }
  114.       }
  115.  
  116.       if (this.m_ThreadAutoScroll != null && this.m_ThreadAutoScroll.isAlive()) {
  117.          return false;
  118.       } else {
  119.          this.m_bForward = var2;
  120.          this.m_ThreadAutoScroll = new Thread(this);
  121.          this.m_ThreadAutoScroll.start();
  122.          return true;
  123.       }
  124.    }
  125.  
  126.    private final synchronized boolean WaitScrollTime(long var1) {
  127.       try {
  128.          this.wait(var1 == 0L ? this.m_lAutoScrollPauseTimes[this.m_Document.m_iCurrPage - 1] : var1);
  129.          return true;
  130.       } catch (InterruptedException var3) {
  131.          return false;
  132.       } catch (IllegalMonitorStateException var4) {
  133.          return false;
  134.       }
  135.    }
  136.  
  137.    private final synchronized void NotifyScrollTime() {
  138.       try {
  139.          this.notify();
  140.       } catch (IllegalMonitorStateException var1) {
  141.       }
  142.    }
  143.  
  144.    private final synchronized void ScrollPage() {
  145.       if (this.m_bForward) {
  146.          this.m_Document.NextPage();
  147.       } else {
  148.          this.m_Document.PrevPage();
  149.       }
  150.    }
  151.  
  152.    public final void ViewUpdated() {
  153.       this.m_bViewUpdated = true;
  154.    }
  155.  
  156.    public final Transition GetTransition() {
  157.       return this.m_Transition;
  158.    }
  159.  
  160.    public final boolean DoingTransition() {
  161.       return !this.m_bViewUpdated || this.m_Transition.DoingTransition();
  162.    }
  163.  
  164.    public final boolean StoreData(int var1, int var2, int var3, int var4, int var5, long var6, String var8) {
  165.       if (var1 >= this.m_Document.m_nNumOfPages) {
  166.          return false;
  167.       } else {
  168.          if (!this.m_bNonDefaultValues[var1]) {
  169.             this.m_bNonDefaultValues[var1] = true;
  170.  
  171.             do {
  172.                this.m_iAutoScrollPauseTypes[var1] = var2;
  173.                this.m_lAutoScrollPauseTimes[var1] = var6;
  174.                this.m_strAutoScrollPauseSounds[var1] = var8;
  175.                if (!this.m_Transition.StoreData(var1, var3, var4, var5)) {
  176.                   return false;
  177.                }
  178.  
  179.                ++var1;
  180.             } while(var1 < this.m_Document.m_nNumOfPages && !this.m_bNonDefaultValues[var1]);
  181.          }
  182.  
  183.          return true;
  184.       }
  185.    }
  186.  
  187.    public final void ShowStatus() {
  188.       if (this.m_bScrollingStopped) {
  189.          this.m_Document.m_Applet.showStatus(this.m_Document.m_Applet.m_BaristaLoc.m_StringAutoScrollStopped);
  190.       } else {
  191.          this.m_Document.m_Applet.showStatus(this.m_Document.m_Applet.GetVersionStatusString());
  192.       }
  193.    }
  194.  
  195.    public final boolean ScrollingStatus(int var1) {
  196.       switch (var1) {
  197.          case 1:
  198.             return this.m_bScrollingStopped;
  199.          default:
  200.             return false;
  201.       }
  202.    }
  203.  
  204.    public final void PlayAudioClip(int var1) {
  205.       if (this.m_iAutoScrollPauseTypes[var1] == 3 && !this.m_bScrollingStopped && this.m_strAutoScrollPauseSounds[var1] != null) {
  206.          AudioClip var2 = null;
  207.  
  208.          try {
  209.             if (this.m_Document.m_PageDirName != null) {
  210.                var2 = this.m_Document.m_Applet.getAudioClip(this.m_Document.m_Applet.getDocumentBase(), this.m_Document.m_PageDirName + "/" + this.m_strAutoScrollPauseSounds[var1]);
  211.             } else {
  212.                var2 = this.m_Document.m_Applet.getAudioClip(this.m_Document.m_Applet.getDocumentBase(), this.m_strAutoScrollPauseSounds[var1]);
  213.             }
  214.          } catch (Exception var3) {
  215.          }
  216.  
  217.          if (this.m_AudioClip != null) {
  218.             this.m_AudioClip.stop();
  219.          }
  220.  
  221.          this.m_AudioClip = var2;
  222.          if (this.m_AudioClip != null) {
  223.             this.m_AudioClip.play();
  224.          }
  225.       }
  226.  
  227.    }
  228. }
  229.