home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / NETSCAP4.06 / CP32E406.EXE / nav40.z / ifc11.jar / netscape / constructor / PlanLoader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-08-13  |  5.2 KB  |  236 lines

  1. package netscape.constructor;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import netscape.application.ExternalWindow;
  6. import netscape.application.InternalWindow;
  7. import netscape.application.Target;
  8. import netscape.application.Window;
  9. import netscape.util.ClassInfo;
  10. import netscape.util.Codable;
  11. import netscape.util.CodingException;
  12. import netscape.util.Decoder;
  13. import netscape.util.Encoder;
  14. import netscape.util.Vector;
  15.  
  16. public class PlanLoader implements Target, Codable {
  17.    String url;
  18.    boolean isRelativeURL;
  19.    boolean asExternalWindow;
  20.    Plan plan;
  21.    static boolean rememberWindows;
  22.    static Vector windowVector;
  23.    public static final String CREATE_PLAN = "Load Plan";
  24.    static final String HIDE_WINDOWS = "Hide Windows";
  25.    static final String SHOW_WINDOWS = "Show Windows";
  26.    static final String URL_KEY = "Plan URL";
  27.    static final String IS_RELATIVE_KEY = "URL is relative to codebase";
  28.    static final String LOAD_INTO_EXTERNAL_WINDOW = "Use External Window";
  29.  
  30.    public PlanLoader() {
  31.       this.url = null;
  32.       this.plan = null;
  33.       this.isRelativeURL = false;
  34.       this.asExternalWindow = true;
  35.    }
  36.  
  37.    public PlanLoader(String var1) {
  38.       this(var1, false);
  39.    }
  40.  
  41.    public PlanLoader(String var1, boolean var2) {
  42.       this.url = var1;
  43.       this.plan = null;
  44.       this.isRelativeURL = var2;
  45.       this.asExternalWindow = true;
  46.    }
  47.  
  48.    public void setPlan(Plan var1) {
  49.       this.plan = var1;
  50.    }
  51.  
  52.    public Plan plan() {
  53.       return this.plan;
  54.    }
  55.  
  56.    public void setPlanURL(String var1) {
  57.       this.url = var1;
  58.    }
  59.  
  60.    public String planURL() {
  61.       return this.url;
  62.    }
  63.  
  64.    public String fullURL() {
  65.       return this.planURL();
  66.    }
  67.  
  68.    public void setRelativeURL(boolean var1) {
  69.       this.isRelativeURL = var1;
  70.    }
  71.  
  72.    public boolean isRelativeURL() {
  73.       return this.isRelativeURL;
  74.    }
  75.  
  76.    public void performCommand(String var1, Object var2) {
  77.       if ("Load Plan".equals(var1)) {
  78.          this.createPlan();
  79.       } else if ("Hide Windows".equals(var1)) {
  80.          hideWindows();
  81.       } else {
  82.          if ("Show Windows".equals(var1)) {
  83.             showWindows();
  84.          }
  85.  
  86.       }
  87.    }
  88.  
  89.    public boolean loadInExternalWindow() {
  90.       return this.asExternalWindow;
  91.    }
  92.  
  93.    public void setLoadInExternalWindow(boolean var1) {
  94.       this.asExternalWindow = var1;
  95.    }
  96.  
  97.    public void loadPlan() {
  98.       if (this.plan() != null) {
  99.          this.plan.unarchiveObjects();
  100.       } else if (this.planURL() != null && this.planURL().length() >= 1) {
  101.          try {
  102.             FileInputStream var2 = new FileInputStream(this.fullURL());
  103.             this.plan = new Plan();
  104.             int var1 = this.plan.archiveFormatOf(this.fullURL());
  105.             this.plan.initFrom(var2, var1);
  106.             this.plan.unarchiveObjects();
  107.          } catch (IOException var4) {
  108.             try {
  109.                this.plan = new Plan(this.fullURL());
  110.             } catch (IOException var3) {
  111.                System.err.println("PlanLoader could not load plan file: \"" + this.fullURL() + "\"");
  112.             }
  113.          }
  114.       }
  115.    }
  116.  
  117.    public InternalWindow putPlanInInternalWindow() {
  118.       this.loadPlan();
  119.       if (this.plan() == null) {
  120.          return null;
  121.       } else {
  122.          InternalWindow var1 = this.plan().internalWindowWithContents();
  123.          var1.setCloseable(true);
  124.          if (rememberWindows()) {
  125.             windowVector().addElement(var1);
  126.          }
  127.  
  128.          return var1;
  129.       }
  130.    }
  131.  
  132.    public ExternalWindow putPlanInExternalWindow() {
  133.       this.loadPlan();
  134.       if (this.plan() == null) {
  135.          return null;
  136.       } else {
  137.          ExternalWindow var1 = this.plan().externalWindowWithContents();
  138.          if (rememberWindows()) {
  139.             windowVector().addElement(var1);
  140.          }
  141.  
  142.          return var1;
  143.       }
  144.    }
  145.  
  146.    public void createPlan() {
  147.       if (this.asExternalWindow) {
  148.          ExternalWindow var1 = this.putPlanInExternalWindow();
  149.          if (var1 != null) {
  150.             var1.show();
  151.          }
  152.       } else {
  153.          InternalWindow var2 = this.putPlanInInternalWindow();
  154.          if (var2 != null) {
  155.             var2.show();
  156.          }
  157.       }
  158.  
  159.       if (this.plan() != null) {
  160.          this.plan().releaseObjects();
  161.       }
  162.  
  163.    }
  164.  
  165.    public void describeClassInfo(ClassInfo var1) {
  166.       var1.addClass("netscape.constructor.PlanLoader", 1);
  167.       var1.addField("Plan URL", (byte)16);
  168.       var1.addField("URL is relative to codebase", (byte)0);
  169.       var1.addField("Use External Window", (byte)0);
  170.    }
  171.  
  172.    public void encode(Encoder var1) throws CodingException {
  173.       var1.encodeString("Plan URL", this.url);
  174.       var1.encodeBoolean("URL is relative to codebase", this.isRelativeURL);
  175.       var1.encodeBoolean("Use External Window", this.asExternalWindow);
  176.    }
  177.  
  178.    public void decode(Decoder var1) throws CodingException {
  179.       this.url = var1.decodeString("Plan URL");
  180.       this.isRelativeURL = var1.decodeBoolean("URL is relative to codebase");
  181.       this.asExternalWindow = var1.decodeBoolean("Use External Window");
  182.    }
  183.  
  184.    public void finishDecoding() throws CodingException {
  185.    }
  186.  
  187.    public static void setRememberWindows(boolean var0) {
  188.       rememberWindows = var0;
  189.    }
  190.  
  191.    public static boolean rememberWindows() {
  192.       return rememberWindows;
  193.    }
  194.  
  195.    public static Vector windowVector() {
  196.       if (windowVector == null) {
  197.          windowVector = new Vector();
  198.       }
  199.  
  200.       return windowVector;
  201.    }
  202.  
  203.    public static void hideWindows() {
  204.       int var0 = windowVector().count();
  205.       if (var0 >= 1) {
  206.          while(true) {
  207.             --var0;
  208.             if (var0 < 0) {
  209.                windowVector.removeAllElements();
  210.                return;
  211.             }
  212.  
  213.             if (windowVector().elementAt(var0) instanceof ExternalWindow) {
  214.                ((ExternalWindow)windowVector().elementAt(var0)).dispose();
  215.             } else if (windowVector().elementAt(var0) instanceof InternalWindow) {
  216.                ((InternalWindow)windowVector().elementAt(var0)).hide();
  217.             }
  218.          }
  219.       }
  220.    }
  221.  
  222.    public static void showWindows() {
  223.       int var0 = windowVector().count();
  224.       if (var0 >= 1) {
  225.          while(true) {
  226.             --var0;
  227.             if (var0 < 0) {
  228.                return;
  229.             }
  230.  
  231.             ((Window)windowVector().elementAt(var0)).show();
  232.          }
  233.       }
  234.    }
  235. }
  236.