package Appletexam;

import java.net.*;
import java.io.*;
import java.util.*;

import com.xckx.Visio.Viewer.*;
import com.xckx.Visio.Interface.*;

/**
 * <p>Title: Visio Example--Applet</p>
 * <p>Description: Show how to use VisioCom ia an Applet</p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: Beijing Dawninfo Tech. Co., Ltd.</p>
 * @author Junjie Ruan
 * @version 1.0
 */

//a subclass which inherit the VisioViewer in VisioCom.jar
public class MyViewer extends VisioViewer {
  PaintPanel panel = null;
  VisioObjectsContainer container;     //!!!Initialize an instance if VisioObjectsContainer
                                       //!!!in VisioCom.jar

  String fileNames[] = {               //!!!document file names on the server
      "label1","label2","label3","label4","label5","label6","label7",
      "label8","label9","label10","label11","label12","label13","label14",
      "label15","label16","label17","label18","label19","label20"
  };

  public MyViewer(PaintPanel pane) {
    super(pane);
    panel = pane;

    setInternetMode();               //!!!setInternetMode method of VisioViewer class
                                     //!!!in VisioCom.jar which indicate this application
                                     //!!!will read file from server via network
    setContextURL(panel.getApplet().appletUrl); //!!!set the server's ContextURL,furthermore

    //!!!below is a container of the VisioViewer Objects,
    //!!!you can create more Containers using different names also,
    //!!!so that each is correspoinding to a category of documents
    container = newContainer("myContainer");

    try {
      readLibrary();
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

  private  void readLibrary() {      //!!!read documents from the server
    int i;
    String file;

    panel.getApplet().showReadingProcess(0, 0, 0, true);
    for (i=0; i<fileNames.length; i++) {
      file = "../VisioLabels/"+fileNames[i]+".xml";
      addDocument("myContainer", file);    //!!!call the addDocument method of VisioViewer
                                           //!!!to read and add Visio XML documents to the
                                           //!!!named container
      panel.getApplet().showReadingProcess(i+1, fileNames.length, 0, false);
    }
  }

}