home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Netobjs / Install.exe / data1.cab / Components / TimeBasedApplet / TimeBasedComp.jar / TimeBasedComp / TimeBasedComp.class (.txt)
Encoding:
Java Class File  |  1998-11-17  |  8.3 KB  |  330 lines

  1. package TimeBasedComp;
  2.  
  3. import com.netobjects.nfc.api.CStringArray;
  4. import com.netobjects.nfc.api.ComponentApp;
  5. import com.netobjects.nfc.api.DAssetManager;
  6. import com.netobjects.nfc.api.DDrawJava;
  7. import com.netobjects.nfc.api.DImage;
  8. import com.netobjects.nfc.api.DLayout;
  9. import com.netobjects.nfc.api.DRect;
  10. import com.netobjects.nfc.api.DSite;
  11. import com.netobjects.nfc.api.DSize;
  12. import com.netobjects.nfc.api.DStyle;
  13. import com.netobjects.nfc.api.IDInspector;
  14.  
  15. public class TimeBasedComp extends ComponentApp {
  16.    int maxWidth;
  17.    int maxHeight;
  18.    int numImages;
  19.    static final int MaxImages = 24;
  20.    DDrawJava theJavaApplet;
  21.    int[] imageNames;
  22.    int[] imageURLs;
  23.    String[] linkTargets;
  24.    int[] imageStarts;
  25.    DAssetManager assetMan;
  26.  
  27.    public void migrationPatch() {
  28.       if (this.imageNames == null) {
  29.          this.imageNames = new int[24];
  30.       }
  31.  
  32.       if (this.imageURLs == null) {
  33.          this.imageURLs = new int[24];
  34.       }
  35.  
  36.       if (this.linkTargets == null) {
  37.          this.linkTargets = new String[24];
  38.       }
  39.  
  40.    }
  41.  
  42.    public void onCopy() {
  43.       int[] imageNamesOld = this.imageNames;
  44.       int[] imageURLsOld = this.imageURLs;
  45.       this.imageNames = new int[24];
  46.       this.imageURLs = new int[24];
  47.  
  48.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  49.          this.imageNames[cnt] = imageNamesOld[cnt];
  50.          this.imageURLs[cnt] = imageURLsOld[cnt];
  51.          if (this.imageNames[cnt] != 0) {
  52.             this.assetMan.CopyAsset(this.imageNames[cnt]);
  53.          }
  54.  
  55.          if (this.imageURLs[cnt] != 0) {
  56.             this.assetMan.CopyAsset(this.imageURLs[cnt]);
  57.          }
  58.       }
  59.  
  60.    }
  61.  
  62.    public void onDrop(DLayout layout, DRect r, int fDrop) {
  63.       if (fDrop == 1) {
  64.          this.maxWidth = 0;
  65.          this.maxHeight = 0;
  66.          this.numImages = 3;
  67.          this.imageURLs = new int[24];
  68.          this.linkTargets = new String[24];
  69.          this.imageNames = new int[24];
  70.          this.imageStarts = new int[24];
  71.  
  72.          for(int i = 0; i < 24; this.imageStarts[i] = i++) {
  73.             this.imageNames[i] = 0;
  74.             this.imageURLs[i] = 0;
  75.          }
  76.  
  77.          this.theJavaApplet = new DDrawJava();
  78.          this.theJavaApplet.setImageFile(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner.gif")));
  79.          this.theJavaApplet.setAppletFileName(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("TimeBased.class")));
  80.          this.theJavaApplet.setStretch(1);
  81.          this.theJavaApplet.setAltTag("Time Based Loader");
  82.          int xPos = r.getLeft();
  83.          int yPos = r.getTop();
  84.          this.theJavaApplet.AddParam("Number of Images", "String", "3");
  85.          this.imageNames[0] = this.assetMan.AddAsset(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner.gif")), "Image", "");
  86.          this.imageNames[1] = this.assetMan.AddAsset(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner2.gif")), "Image", "");
  87.          this.imageNames[2] = this.assetMan.AddAsset(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner3.gif")), "Image", "");
  88.          DImage imageSizer = new DImage();
  89.          imageSizer.setImageFile(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner.gif")));
  90.          DSize currentImageSize = imageSizer.getSize();
  91.          if (currentImageSize.getHeight() > this.maxHeight) {
  92.             this.maxHeight = currentImageSize.getHeight();
  93.             if (currentImageSize.getWidth() > this.maxWidth) {
  94.                this.maxWidth = currentImageSize.getWidth();
  95.             }
  96.  
  97.             this.theJavaApplet.SetPositionRect(xPos, yPos, xPos + this.maxWidth, yPos + this.maxHeight);
  98.          } else if (currentImageSize.getWidth() > this.maxWidth) {
  99.             this.maxWidth = currentImageSize.getWidth();
  100.             this.theJavaApplet.SetPositionRect(xPos, yPos, xPos + this.maxWidth, yPos + this.maxHeight);
  101.          }
  102.  
  103.          layout.AddObject(this.theJavaApplet);
  104.       }
  105.    }
  106.  
  107.    protected void onFinalize() {
  108.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  109.          if (this.imageNames[cnt] != 0) {
  110.             this.assetMan.RemoveAsset(this.imageNames[cnt]);
  111.          }
  112.       }
  113.  
  114.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  115.          if (this.imageURLs[cnt] != 0) {
  116.             this.assetMan.RemoveAsset(this.imageURLs[cnt]);
  117.          }
  118.       }
  119.  
  120.    }
  121.  
  122.    public void onInspect(CStringArray Names, CStringArray Types) {
  123.       Names.Set("Number of Images");
  124.       Types.Set("Collection");
  125.  
  126.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  127.          Names.Set(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1))));
  128.          Types.Set("Image");
  129.          Names.Set(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1))));
  130.          Types.Set("Link");
  131.          Names.Set(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1))));
  132.          Types.Set("Set(12am|1am|2am|3am|4am|5am|6am|7am|8am|9am|10am|11am|12pm|1pm|2pm|3pm|4pm|5pm|6pm|7pm|8pm|9pm|10pm|11pm)");
  133.       }
  134.  
  135.    }
  136.  
  137.    public String onInstall(DAssetManager cam, String codebase) {
  138.       this.assetMan = cam;
  139.       return "Time Based Picture";
  140.    }
  141.  
  142.    public void onPublish(DAssetManager asm, int context) {
  143.       this.migrationPatch();
  144.       if (context == 1) {
  145.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  146.             String theLoc = this.assetMan.GetAssetLocation(this.imageNames[cnt], context, 0);
  147.             theLoc.replace('|', ':');
  148.             this.theJavaApplet.AddParam(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", theLoc);
  149.          }
  150.       } else {
  151.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  152.             this.theJavaApplet.AddParam(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", this.assetMan.GetAssetRelativeLocation(this.imageNames[cnt], context, 0));
  153.          }
  154.       }
  155.  
  156.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  157.          String theURL;
  158.          if (this.imageURLs[cnt] != 0) {
  159.             theURL = this.assetMan.GetAssetLocation(this.imageURLs[cnt], context, 1);
  160.          } else {
  161.             theURL = "";
  162.          }
  163.  
  164.          this.theJavaApplet.AddParam(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", theURL);
  165.          this.theJavaApplet.AddParam(String.valueOf("target").concat(String.valueOf(Integer.toString(cnt + 1))), "String", this.linkTargets[cnt]);
  166.          this.theJavaApplet.AddParam(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", Integer.toString(this.imageStarts[cnt]));
  167.       }
  168.  
  169.       this.theJavaApplet.AddParam("Image Width", "String", Integer.toString(this.maxWidth));
  170.       this.theJavaApplet.AddParam("Image Height", "String", Integer.toString(this.maxHeight));
  171.       DRect thePosition = this.theJavaApplet.getObjectRect();
  172.       this.theJavaApplet.AddParam("X Position", "String", Integer.toString(thePosition.getLeft()));
  173.       this.theJavaApplet.AddParam("Y Position", "String", Integer.toString(thePosition.getTop() + 7));
  174.       DLayout layout = this.theJavaApplet.getLayout();
  175.       DSite site = layout.getSite();
  176.       DStyle style = site.getCurrentStyle();
  177.       int backgroundStyle = layout.getBackgroundStyle();
  178.       if (backgroundStyle != 0) {
  179.          if (backgroundStyle == 1) {
  180.             this.theJavaApplet.AddParam("BackgroundColor", "String", Integer.toString(layout.getBackgroundColor()));
  181.          } else if (backgroundStyle == 2) {
  182.             int backID = this.assetMan.AddAsset(layout.getBackgroundImage(), "Image", "");
  183.             String theParam = this.assetMan.GetAssetRelativeLocation(backID, context, 1);
  184.             if (context == 1) {
  185.                theParam = theParam;
  186.             }
  187.  
  188.             this.theJavaApplet.AddParam("BackgroundImage", "String", theParam);
  189.          }
  190.       } else {
  191.          backgroundStyle = style.getBackgroundStyle();
  192.          if (backgroundStyle == 1) {
  193.             this.theJavaApplet.AddParam("BackgroundColor", "String", Integer.toString(style.getBackgroundColor()));
  194.          } else if (backgroundStyle == 2) {
  195.             int backID = this.assetMan.AddAsset(style.getBackgroundImage(), "Image", "");
  196.             String theParam = this.assetMan.GetAssetRelativeLocation(backID, context, 1);
  197.             if (context == 1) {
  198.                theParam = theParam;
  199.             }
  200.  
  201.             this.theJavaApplet.AddParam("BackgroundImage", "String", theParam);
  202.          }
  203.       }
  204.  
  205.    }
  206.  
  207.    public void onUnInstall(DAssetManager cam) {
  208.    }
  209.  
  210.    public String PropertyListener(String Event, String Value, int Get, int propIndex, IDInspector insp) {
  211.       this.migrationPatch();
  212.       if (Get == 1) {
  213.          if (Event.compareTo("Number of Images") == 0) {
  214.             return Integer.toString(this.numImages);
  215.          }
  216.  
  217.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  218.             if (Event.compareTo(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) {
  219.                return Integer.toString(this.imageNames[cnt]);
  220.             }
  221.  
  222.             if (Event.compareTo(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) {
  223.                return Integer.toString(this.imageURLs[cnt]);
  224.             }
  225.  
  226.             if (Event.compareTo(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) {
  227.                return Integer.toString(this.imageStarts[cnt]);
  228.             }
  229.          }
  230.       } else if (Event.compareTo("Number of Images") == 0) {
  231.          int newNumImages = Integer.parseInt(Value, 10);
  232.          if (newNumImages < 1) {
  233.             return "";
  234.          }
  235.  
  236.          if (newNumImages > 24) {
  237.             newNumImages = 24;
  238.          }
  239.  
  240.          for(int i = 0; i < newNumImages; ++i) {
  241.             if (this.imageNames[i] != 0) {
  242.                String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[i], 1, 1);
  243.                this.theJavaApplet.setImageFile(theImageFile);
  244.                break;
  245.             }
  246.          }
  247.  
  248.          if (newNumImages < this.numImages) {
  249.             for(int i = newNumImages; i < this.numImages; ++i) {
  250.                this.imageURLs[i] = 0;
  251.             }
  252.  
  253.             DImage imageSizer = new DImage();
  254.             this.maxHeight = this.maxWidth = 0;
  255.  
  256.             for(int iter = 0; iter < newNumImages; ++iter) {
  257.                String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[iter], 1, 1);
  258.                imageSizer.setImageFile(theImageFile);
  259.                DSize currentImageSize = imageSizer.getSize();
  260.                if (currentImageSize.getHeight() > this.maxHeight) {
  261.                   this.maxHeight = currentImageSize.getHeight();
  262.                }
  263.  
  264.                if (currentImageSize.getWidth() > this.maxWidth) {
  265.                   this.maxWidth = currentImageSize.getWidth();
  266.                }
  267.             }
  268.  
  269.             this.theJavaApplet.SetSize(this.maxWidth, this.maxHeight);
  270.          }
  271.  
  272.          while(newNumImages < this.numImages) {
  273.             this.assetMan.RemoveAsset(this.imageNames[--this.numImages]);
  274.          }
  275.  
  276.          this.numImages = newNumImages;
  277.          this.theJavaApplet.AddParam(Event, "String", Integer.toString(this.numImages));
  278.       } else {
  279.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  280.             if (Event.compareTo(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) {
  281.                if (this.imageNames[cnt] != 0) {
  282.                   this.assetMan.RemoveAsset(this.imageNames[cnt]);
  283.                }
  284.  
  285.                this.imageNames[cnt] = Integer.parseInt(Value, 10);
  286.                String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[cnt], 1, 1);
  287.                this.theJavaApplet.setImageFile(theImageFile);
  288.                DImage imageSizer = new DImage();
  289.                this.maxHeight = this.maxWidth = 0;
  290.  
  291.                for(int iter = 0; iter < this.numImages; ++iter) {
  292.                   theImageFile = this.assetMan.GetAssetLocation(this.imageNames[iter], 1, 1);
  293.                   imageSizer.setImageFile(theImageFile);
  294.                   DSize currentImageSize = imageSizer.getSize();
  295.                   if (currentImageSize.getHeight() > this.maxHeight) {
  296.                      this.maxHeight = currentImageSize.getHeight();
  297.                   }
  298.  
  299.                   if (currentImageSize.getWidth() > this.maxWidth) {
  300.                      this.maxWidth = currentImageSize.getWidth();
  301.                   }
  302.                }
  303.  
  304.                this.theJavaApplet.SetSize(this.maxWidth, this.maxHeight);
  305.             }
  306.  
  307.             if (Event.compareTo(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) {
  308.                this.imageURLs[cnt] = Integer.parseInt(Value, 10);
  309.                if (this.assetMan.LinkHasFrames(this.imageURLs[cnt]) != 0) {
  310.                   this.linkTargets[cnt] = this.assetMan.GetTargetFromLink(this.imageURLs[cnt]);
  311.                } else {
  312.                   this.linkTargets[cnt] = "";
  313.                }
  314.             }
  315.  
  316.             if (Event.compareTo(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) {
  317.                this.imageStarts[cnt] = Integer.parseInt(Value, 10);
  318.                if (this.imageStarts[cnt] > 23) {
  319.                   this.imageStarts[cnt] = 23;
  320.                } else if (this.imageStarts[cnt] < 0) {
  321.                   this.imageStarts[cnt] = 0;
  322.                }
  323.             }
  324.          }
  325.       }
  326.  
  327.       return "";
  328.    }
  329. }
  330.