home *** CD-ROM | disk | FTP | other *** search
Wrap
package TimeBasedComp; import com.netobjects.nfc.api.CStringArray; import com.netobjects.nfc.api.ComponentApp; import com.netobjects.nfc.api.DAssetManager; import com.netobjects.nfc.api.DDrawJava; import com.netobjects.nfc.api.DImage; import com.netobjects.nfc.api.DLayout; import com.netobjects.nfc.api.DRect; import com.netobjects.nfc.api.DSite; import com.netobjects.nfc.api.DSize; import com.netobjects.nfc.api.DStyle; import com.netobjects.nfc.api.IDInspector; public class TimeBasedComp extends ComponentApp { int maxWidth; int maxHeight; int numImages; static final int MaxImages = 24; DDrawJava theJavaApplet; int[] imageNames; int[] imageURLs; String[] linkTargets; int[] imageStarts; DAssetManager assetMan; public void migrationPatch() { if (this.imageNames == null) { this.imageNames = new int[24]; } if (this.imageURLs == null) { this.imageURLs = new int[24]; } if (this.linkTargets == null) { this.linkTargets = new String[24]; } } public void onCopy() { int[] imageNamesOld = this.imageNames; int[] imageURLsOld = this.imageURLs; this.imageNames = new int[24]; this.imageURLs = new int[24]; for(int cnt = 0; cnt < this.numImages; ++cnt) { this.imageNames[cnt] = imageNamesOld[cnt]; this.imageURLs[cnt] = imageURLsOld[cnt]; if (this.imageNames[cnt] != 0) { this.assetMan.CopyAsset(this.imageNames[cnt]); } if (this.imageURLs[cnt] != 0) { this.assetMan.CopyAsset(this.imageURLs[cnt]); } } } public void onDrop(DLayout layout, DRect r, int fDrop) { if (fDrop == 1) { this.maxWidth = 0; this.maxHeight = 0; this.numImages = 3; this.imageURLs = new int[24]; this.linkTargets = new String[24]; this.imageNames = new int[24]; this.imageStarts = new int[24]; for(int i = 0; i < 24; this.imageStarts[i] = i++) { this.imageNames[i] = 0; this.imageURLs[i] = 0; } this.theJavaApplet = new DDrawJava(); this.theJavaApplet.setImageFile(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner.gif"))); this.theJavaApplet.setAppletFileName(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("TimeBased.class"))); this.theJavaApplet.setStretch(1); this.theJavaApplet.setAltTag("Time Based Loader"); int xPos = r.getLeft(); int yPos = r.getTop(); this.theJavaApplet.AddParam("Number of Images", "String", "3"); this.imageNames[0] = this.assetMan.AddAsset(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner.gif")), "Image", ""); this.imageNames[1] = this.assetMan.AddAsset(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner2.gif")), "Image", ""); this.imageNames[2] = this.assetMan.AddAsset(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner3.gif")), "Image", ""); DImage imageSizer = new DImage(); imageSizer.setImageFile(String.valueOf(this.theJavaApplet.getCodeBase()).concat(String.valueOf("banner.gif"))); DSize currentImageSize = imageSizer.getSize(); if (currentImageSize.getHeight() > this.maxHeight) { this.maxHeight = currentImageSize.getHeight(); if (currentImageSize.getWidth() > this.maxWidth) { this.maxWidth = currentImageSize.getWidth(); } this.theJavaApplet.SetPositionRect(xPos, yPos, xPos + this.maxWidth, yPos + this.maxHeight); } else if (currentImageSize.getWidth() > this.maxWidth) { this.maxWidth = currentImageSize.getWidth(); this.theJavaApplet.SetPositionRect(xPos, yPos, xPos + this.maxWidth, yPos + this.maxHeight); } layout.AddObject(this.theJavaApplet); } } protected void onFinalize() { for(int cnt = 0; cnt < this.numImages; ++cnt) { if (this.imageNames[cnt] != 0) { this.assetMan.RemoveAsset(this.imageNames[cnt]); } } for(int cnt = 0; cnt < this.numImages; ++cnt) { if (this.imageURLs[cnt] != 0) { this.assetMan.RemoveAsset(this.imageURLs[cnt]); } } } public void onInspect(CStringArray Names, CStringArray Types) { Names.Set("Number of Images"); Types.Set("Collection"); for(int cnt = 0; cnt < this.numImages; ++cnt) { Names.Set(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1)))); Types.Set("Image"); Names.Set(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))); Types.Set("Link"); Names.Set(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))); 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)"); } } public String onInstall(DAssetManager cam, String codebase) { this.assetMan = cam; return "Time Based Picture"; } public void onPublish(DAssetManager asm, int context) { this.migrationPatch(); if (context == 1) { for(int cnt = 0; cnt < this.numImages; ++cnt) { String theLoc = this.assetMan.GetAssetLocation(this.imageNames[cnt], context, 0); theLoc.replace('|', ':'); this.theJavaApplet.AddParam(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", theLoc); } } else { for(int cnt = 0; cnt < this.numImages; ++cnt) { this.theJavaApplet.AddParam(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", this.assetMan.GetAssetRelativeLocation(this.imageNames[cnt], context, 0)); } } for(int cnt = 0; cnt < this.numImages; ++cnt) { String theURL; if (this.imageURLs[cnt] != 0) { theURL = this.assetMan.GetAssetLocation(this.imageURLs[cnt], context, 1); } else { theURL = ""; } this.theJavaApplet.AddParam(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", theURL); this.theJavaApplet.AddParam(String.valueOf("target").concat(String.valueOf(Integer.toString(cnt + 1))), "String", this.linkTargets[cnt]); this.theJavaApplet.AddParam(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1))), "String", Integer.toString(this.imageStarts[cnt])); } this.theJavaApplet.AddParam("Image Width", "String", Integer.toString(this.maxWidth)); this.theJavaApplet.AddParam("Image Height", "String", Integer.toString(this.maxHeight)); DRect thePosition = this.theJavaApplet.getObjectRect(); this.theJavaApplet.AddParam("X Position", "String", Integer.toString(thePosition.getLeft())); this.theJavaApplet.AddParam("Y Position", "String", Integer.toString(thePosition.getTop() + 7)); DLayout layout = this.theJavaApplet.getLayout(); DSite site = layout.getSite(); DStyle style = site.getCurrentStyle(); int backgroundStyle = layout.getBackgroundStyle(); if (backgroundStyle != 0) { if (backgroundStyle == 1) { this.theJavaApplet.AddParam("BackgroundColor", "String", Integer.toString(layout.getBackgroundColor())); } else if (backgroundStyle == 2) { int backID = this.assetMan.AddAsset(layout.getBackgroundImage(), "Image", ""); String theParam = this.assetMan.GetAssetRelativeLocation(backID, context, 1); if (context == 1) { theParam = theParam; } this.theJavaApplet.AddParam("BackgroundImage", "String", theParam); } } else { backgroundStyle = style.getBackgroundStyle(); if (backgroundStyle == 1) { this.theJavaApplet.AddParam("BackgroundColor", "String", Integer.toString(style.getBackgroundColor())); } else if (backgroundStyle == 2) { int backID = this.assetMan.AddAsset(style.getBackgroundImage(), "Image", ""); String theParam = this.assetMan.GetAssetRelativeLocation(backID, context, 1); if (context == 1) { theParam = theParam; } this.theJavaApplet.AddParam("BackgroundImage", "String", theParam); } } } public void onUnInstall(DAssetManager cam) { } public String PropertyListener(String Event, String Value, int Get, int propIndex, IDInspector insp) { this.migrationPatch(); if (Get == 1) { if (Event.compareTo("Number of Images") == 0) { return Integer.toString(this.numImages); } for(int cnt = 0; cnt < this.numImages; ++cnt) { if (Event.compareTo(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) { return Integer.toString(this.imageNames[cnt]); } if (Event.compareTo(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) { return Integer.toString(this.imageURLs[cnt]); } if (Event.compareTo(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) { return Integer.toString(this.imageStarts[cnt]); } } } else if (Event.compareTo("Number of Images") == 0) { int newNumImages = Integer.parseInt(Value, 10); if (newNumImages < 1) { return ""; } if (newNumImages > 24) { newNumImages = 24; } for(int i = 0; i < newNumImages; ++i) { if (this.imageNames[i] != 0) { String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[i], 1, 1); this.theJavaApplet.setImageFile(theImageFile); break; } } if (newNumImages < this.numImages) { for(int i = newNumImages; i < this.numImages; ++i) { this.imageURLs[i] = 0; } DImage imageSizer = new DImage(); this.maxHeight = this.maxWidth = 0; for(int iter = 0; iter < newNumImages; ++iter) { String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[iter], 1, 1); imageSizer.setImageFile(theImageFile); DSize currentImageSize = imageSizer.getSize(); if (currentImageSize.getHeight() > this.maxHeight) { this.maxHeight = currentImageSize.getHeight(); } if (currentImageSize.getWidth() > this.maxWidth) { this.maxWidth = currentImageSize.getWidth(); } } this.theJavaApplet.SetSize(this.maxWidth, this.maxHeight); } while(newNumImages < this.numImages) { this.assetMan.RemoveAsset(this.imageNames[--this.numImages]); } this.numImages = newNumImages; this.theJavaApplet.AddParam(Event, "String", Integer.toString(this.numImages)); } else { for(int cnt = 0; cnt < this.numImages; ++cnt) { if (Event.compareTo(String.valueOf("Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) { if (this.imageNames[cnt] != 0) { this.assetMan.RemoveAsset(this.imageNames[cnt]); } this.imageNames[cnt] = Integer.parseInt(Value, 10); String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[cnt], 1, 1); this.theJavaApplet.setImageFile(theImageFile); DImage imageSizer = new DImage(); this.maxHeight = this.maxWidth = 0; for(int iter = 0; iter < this.numImages; ++iter) { theImageFile = this.assetMan.GetAssetLocation(this.imageNames[iter], 1, 1); imageSizer.setImageFile(theImageFile); DSize currentImageSize = imageSizer.getSize(); if (currentImageSize.getHeight() > this.maxHeight) { this.maxHeight = currentImageSize.getHeight(); } if (currentImageSize.getWidth() > this.maxWidth) { this.maxWidth = currentImageSize.getWidth(); } } this.theJavaApplet.SetSize(this.maxWidth, this.maxHeight); } if (Event.compareTo(String.valueOf("URL for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) { this.imageURLs[cnt] = Integer.parseInt(Value, 10); if (this.assetMan.LinkHasFrames(this.imageURLs[cnt]) != 0) { this.linkTargets[cnt] = this.assetMan.GetTargetFromLink(this.imageURLs[cnt]); } else { this.linkTargets[cnt] = ""; } } if (Event.compareTo(String.valueOf("Start Time for Image ").concat(String.valueOf(Integer.toString(cnt + 1)))) == 0) { this.imageStarts[cnt] = Integer.parseInt(Value, 10); if (this.imageStarts[cnt] > 23) { this.imageStarts[cnt] = 23; } else if (this.imageStarts[cnt] < 0) { this.imageStarts[cnt] = 0; } } } } return ""; } }