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

  1. import corel.transitions.Transition;
  2. import java.applet.Applet;
  3. import java.awt.Dimension;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.Rectangle;
  7. import java.awt.Window;
  8. import java.io.DataInputStream;
  9. import java.io.IOException;
  10. import java.util.Hashtable;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13.  
  14. public final class VDoc {
  15.    public Barista m_Applet;
  16.    private Hashtable m_AppParams;
  17.    private static final int m_iNoOfCachePgs = 5;
  18.    int m_nPrevPage;
  19.    int m_iCurrPage;
  20.    int m_nNumOfPages;
  21.    int m_cBkColor;
  22.    int m_defaultDpi = 96;
  23.    int m_xyDpi = 96;
  24.    short m_sVersion;
  25.    short m_fZoomFactor = 1;
  26.    String m_PageDirName;
  27.    boolean m_bDisplayToolBar = true;
  28.    boolean m_bIsMultiPage = true;
  29.    boolean m_bPageChanged = false;
  30.    Dimension m_LogExtent;
  31.    Dimension m_DevExtent;
  32.    DataInputStream m_HtmlDataInpStream;
  33.    ZStorage m_Storage;
  34.    VPanel m_MainPanel;
  35.    Window m_PopUp;
  36.    Vector m_skBookmarkList;
  37.    private AutoScroll m_AutoScroll;
  38.    private Transition m_Transition;
  39.    public boolean m_bDoubleBufferingDisabled = false;
  40.  
  41.    public VDoc(Applet var1) {
  42.       this.m_Applet = (Barista)var1;
  43.       this.m_nPrevPage = 1;
  44.       this.m_iCurrPage = 1;
  45.       this.m_nNumOfPages = 1;
  46.       this.m_skBookmarkList = new Vector(40);
  47.       this.m_LogExtent = new Dimension(1, 1);
  48.       this.m_DevExtent = new Dimension(1, 1);
  49.       this.m_AppParams = new Hashtable();
  50.       this.m_Storage = new ZStorage(this);
  51.       if (this.m_PageDirName != null) {
  52.          this.m_Storage.start(this.m_iCurrPage, true);
  53.       } else {
  54.          this.m_Storage.start();
  55.       }
  56.    }
  57.  
  58.    VPage GetCurrPage() {
  59.       return this.m_Storage != null ? (VPage)this.m_Storage.get("P" + this.m_iCurrPage) : null;
  60.    }
  61.  
  62.    VPage GetPage(String var1) {
  63.       return this.m_Storage != null ? (VPage)this.m_Storage.get(var1) : null;
  64.    }
  65.  
  66.    boolean NextPage() {
  67.       if (this.m_iCurrPage < this.m_nNumOfPages) {
  68.          this.m_Applet.m_Document.PrevView(this.m_Applet.m_Document.m_iCurrPage);
  69.          ++this.m_iCurrPage;
  70.          if (this.m_PageDirName != null) {
  71.             int var1 = this.GetFreeMemPercent();
  72.             if (var1 <= 15) {
  73.                this.m_Storage.DelPgFromMem();
  74.             }
  75.          }
  76.  
  77.          this.m_bPageChanged = true;
  78.          this.m_Storage.start(this.m_iCurrPage, true);
  79.          this.m_MainPanel.SetPage("P" + this.m_iCurrPage);
  80.          this.UpdateView();
  81.          return false;
  82.       } else {
  83.          return true;
  84.       }
  85.    }
  86.  
  87.    boolean PrevPage() {
  88.       if (this.m_iCurrPage > 1) {
  89.          this.m_Applet.m_Document.PrevView(this.m_Applet.m_Document.m_iCurrPage);
  90.          --this.m_iCurrPage;
  91.          if (this.m_PageDirName != null) {
  92.             int var1 = this.GetFreeMemPercent();
  93.             if (var1 <= 15) {
  94.                this.m_Storage.DelPgFromMem();
  95.             }
  96.          }
  97.  
  98.          this.m_bPageChanged = true;
  99.          this.m_Storage.start(this.m_iCurrPage, true);
  100.          this.m_MainPanel.SetPage("P" + this.m_iCurrPage);
  101.          this.UpdateView();
  102.          return false;
  103.       } else {
  104.          return true;
  105.       }
  106.    }
  107.  
  108.    void PrevView(int var1) {
  109.       this.m_nPrevPage = var1;
  110.    }
  111.  
  112.    void GoToPage(int var1) {
  113.       if (var1 == this.m_iCurrPage - 1) {
  114.          this.PrevPage();
  115.       } else if (var1 == this.m_iCurrPage + 1) {
  116.          this.NextPage();
  117.       } else if (var1 != this.m_iCurrPage) {
  118.          if (var1 >= 1 && var1 <= this.m_nNumOfPages) {
  119.             this.m_Applet.m_Document.PrevView(this.m_Applet.m_Document.m_iCurrPage);
  120.             this.m_iCurrPage = var1;
  121.             if (this.m_PageDirName != null) {
  122.                int var2 = this.GetFreeMemPercent();
  123.                if (var2 <= 20) {
  124.                   for(int var3 = 0; var3 < 5; ++var3) {
  125.                      this.m_Storage.DelPgFromMem();
  126.                   }
  127.                }
  128.             }
  129.  
  130.             this.m_bPageChanged = true;
  131.             this.m_Storage.start(this.m_iCurrPage, true);
  132.             this.m_MainPanel.SetPage("P" + this.m_iCurrPage);
  133.             this.UpdateView();
  134.          }
  135.  
  136.       }
  137.    }
  138.  
  139.    private final int GetFreeMemPercent() {
  140.       Runtime var1 = Runtime.getRuntime();
  141.       long var2 = var1.totalMemory();
  142.       float var4 = (float)var2;
  143.       long var5 = var1.freeMemory();
  144.       float var7 = (float)var5;
  145.       float var8 = var7 / var4;
  146.       float var9 = var8 * 100.0F;
  147.       int var10 = (int)var9;
  148.       return var10;
  149.    }
  150.  
  151.    void SetMainPanel(VPanel var1) {
  152.       this.m_MainPanel = var1;
  153.    }
  154.  
  155.    void UpdateView() {
  156.       if (this.m_MainPanel != null) {
  157.          this.UpdateToolBar();
  158.          this.m_MainPanel.validate();
  159.          this.m_MainPanel.repaint();
  160.       }
  161.  
  162.    }
  163.  
  164.    void UpdateToolBar() {
  165.       if (this.m_bDisplayToolBar) {
  166.          if (this.m_Applet.m_ToolBarTop != null) {
  167.             ((VToolbar)this.m_Applet.m_ToolBarTop).UpdateButtons(this.m_iCurrPage);
  168.          }
  169.  
  170.          if (this.m_Applet.m_ToolBarBot != null) {
  171.             ((VToolbar)this.m_Applet.m_ToolBarBot).UpdateButtons(this.m_iCurrPage);
  172.          }
  173.       }
  174.  
  175.    }
  176.  
  177.    public void ZoomWindow(int var1) {
  178.    }
  179.  
  180.    public void destroy() {
  181.    }
  182.  
  183.    String GetValueGivenName(String var1) {
  184.       String var2 = null;
  185.       if (this.m_AppParams != null) {
  186.          var2 = (String)this.m_AppParams.get(var1.toLowerCase());
  187.       }
  188.  
  189.       return var2;
  190.    }
  191.  
  192.    public void ParsePageHTML() {
  193.       if (this.m_HtmlDataInpStream != null) {
  194.          Object var2 = null;
  195.  
  196.          while(true) {
  197.             try {
  198.                if (this.m_HtmlDataInpStream != null) {
  199.                   var10 = this.m_HtmlDataInpStream.readLine();
  200.                } else {
  201.                   var10 = null;
  202.                }
  203.  
  204.                if (var10 == null || var10.equalsIgnoreCase("</HTML>")) {
  205.                   break;
  206.                }
  207.             } catch (IOException var8) {
  208.                break;
  209.             }
  210.  
  211.             if (this.CheckIfTokenExists(var10, "param")) {
  212.                Object var3 = null;
  213.                Object var4 = null;
  214.  
  215.                try {
  216.                   while(var10.indexOf(62) == -1) {
  217.                      String var13 = this.m_HtmlDataInpStream.readLine();
  218.                      if (var13 != null) {
  219.                         var13 = var13.trim();
  220.                         String var11 = var10.concat(" ");
  221.                         var10 = var11.concat(var13);
  222.                      }
  223.                   }
  224.                } catch (IOException var9) {
  225.                }
  226.  
  227.                String var12 = this.GetKey(var10);
  228.                var12.toLowerCase();
  229.                int var5 = var10.indexOf(34);
  230.                int var6 = var10.lastIndexOf(34);
  231.                String var1 = var10.substring(var5 + 1, var6);
  232.                if (var12 != null && var1 != null) {
  233.                   this.m_AppParams.put(var12.toLowerCase(), var1);
  234.                }
  235.             }
  236.          }
  237.  
  238.          try {
  239.             if (this.m_HtmlDataInpStream != null) {
  240.                this.m_HtmlDataInpStream.close();
  241.             }
  242.          } catch (IOException var7) {
  243.          }
  244.  
  245.          this.m_HtmlDataInpStream = null;
  246.       }
  247.  
  248.    }
  249.  
  250.    private String GetKey(String var1) {
  251.       StringTokenizer var2 = new StringTokenizer(var1);
  252.       var2.nextToken("=");
  253.       String var3 = var2.nextToken(" ");
  254.       return var3.substring(1);
  255.    }
  256.  
  257.    private boolean CheckIfTokenExists(String var1, String var2) {
  258.       if (var1 != null) {
  259.          String var3 = new String(var1);
  260.          StringTokenizer var4 = new StringTokenizer(var3);
  261.  
  262.          for(int var5 = 0; var5 < var4.countTokens(); ++var5) {
  263.             String var6 = var4.nextToken();
  264.             if (var6.charAt(0) == '<') {
  265.                var6 = var6.substring(1);
  266.             }
  267.  
  268.             if (var6.equalsIgnoreCase(var2)) {
  269.                return true;
  270.             }
  271.          }
  272.       }
  273.  
  274.       return false;
  275.    }
  276.  
  277.    public void ClearContents() {
  278.       this.m_AppParams.clear();
  279.    }
  280.  
  281.    public final boolean StartAutoScroll(boolean var1, boolean var2, boolean var3, boolean var4) {
  282.       boolean var5 = false;
  283.       if (this.AutoScrollEnabled()) {
  284.          if (var2) {
  285.             this.m_AutoScroll.ViewUpdated();
  286.          }
  287.  
  288.          var5 = this.m_AutoScroll.Start(var1, var3, var4);
  289.          this.UpdateToolBar();
  290.       }
  291.  
  292.       return var5;
  293.    }
  294.  
  295.    public final boolean DoTransition(Graphics var1, VPanel var2, boolean var3) {
  296.       boolean var4 = false;
  297.       if (this.AutoScrollEnabled()) {
  298.          VPage var5 = this.GetCurrPage();
  299.          Rectangle var6;
  300.          if (var5 != null) {
  301.             var6 = var5.GetPageBounds();
  302.          } else {
  303.             var6 = new Rectangle(-1, -1, 0, 0);
  304.          }
  305.  
  306.          var4 = this.m_AutoScroll.GetTransition().DoTransition(var1, var2, this.m_iCurrPage - 1, true, var3, var6);
  307.          if (var3) {
  308.             this.m_AutoScroll.PlayAudioClip(this.m_iCurrPage - 1);
  309.          }
  310.       }
  311.  
  312.       return var4;
  313.    }
  314.  
  315.    public final boolean DoingTransition() {
  316.       return this.AutoScrollEnabled() ? this.m_AutoScroll.DoingTransition() : false;
  317.    }
  318.  
  319.    public final boolean AutoScrollEnabled() {
  320.       return this.m_AutoScroll != null;
  321.    }
  322.  
  323.    public final void CreateAutoScroll(String var1) {
  324.       if (!this.AutoScrollEnabled()) {
  325.          this.m_AutoScroll = new AutoScroll(this, Integer.valueOf(var1));
  326.       }
  327.  
  328.    }
  329.  
  330.    public final boolean StoreAutoScrollData(int var1, AutoScrollObj var2) {
  331.       return this.AutoScrollEnabled() ? this.m_AutoScroll.StoreData(var1, var2.iPauseType, var2.iTransitionType, var2.iTransitionDirection, var2.iTransitionSpeed, var2.lPauseTime, var2.strPauseSound) : false;
  332.    }
  333.  
  334.    public final void ShowAutoScrollStatus() {
  335.       if (this.AutoScrollEnabled()) {
  336.          this.m_AutoScroll.ShowStatus();
  337.       } else {
  338.          this.m_Applet.showStatus(this.m_Applet.GetVersionStatusString());
  339.       }
  340.    }
  341.  
  342.    public final boolean AutoScrollStatus(int var1) {
  343.       return this.AutoScrollEnabled() ? this.m_AutoScroll.ScrollingStatus(var1) : false;
  344.    }
  345.  
  346.    public final void CreateTransition() {
  347.       this.m_Transition = new Transition(this.m_Applet, this.m_nNumOfPages, this.m_Applet.GetVersionStatusString());
  348.    }
  349.  
  350.    public final boolean DoDoubleBuffering(Graphics var1, VPanel var2, boolean var3) {
  351.       if (this.m_Transition != null) {
  352.          VPage var4 = this.GetCurrPage();
  353.          Rectangle var5;
  354.          if (var4 != null) {
  355.             var5 = var4.GetPageBounds();
  356.          } else {
  357.             var5 = new Rectangle(-1, -1, 0, 0);
  358.          }
  359.  
  360.          return this.m_Transition.DoTransition(var1, var2, this.m_iCurrPage - 1, false, var3, var5);
  361.       } else {
  362.          return false;
  363.       }
  364.    }
  365.  
  366.    public final boolean drawImage(Graphics var1, Image var2, int var3, int var4, int var5, int var6, VPanel var7) {
  367.       if (this.AutoScrollEnabled()) {
  368.          return this.m_AutoScroll.GetTransition().drawImage(var1, var2, var3, var4, var5, var6, var7, this.m_iCurrPage - 1);
  369.       } else {
  370.          return this.m_Transition != null ? this.m_Transition.drawImage(var1, var2, var3, var4, var5, var6, var7, this.m_iCurrPage - 1) : var1.drawImage(var2, var3, var4, var5, var6, var7);
  371.       }
  372.    }
  373. }
  374.