home *** CD-ROM | disk | FTP | other *** search
/ Print Shop Ensemble 3 / the-print-shop-ensemble-iii.iso / worldnet / disk2 / java.z / MOZ2_01.ZIP / netscape / applet / MozillaWindow.class (.txt) < prev   
Encoding:
Java Class File  |  1996-03-08  |  3.2 KB  |  97 lines

  1. package netscape.applet;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Enumeration;
  5. import java.util.Hashtable;
  6.  
  7. class MozillaWindow {
  8.    int MWContext;
  9.    Hashtable frames;
  10.    static int totalFrames;
  11.    private static Hashtable windows = new Hashtable();
  12.  
  13.    MozillaWindow(int MWContext) {
  14.       this.MWContext = MWContext;
  15.       this.frames = new Hashtable();
  16.    }
  17.  
  18.    void add(MozillaFrame frame) {
  19.       this.frames.put(new Integer(frame.MWContext), frame);
  20.       ++totalFrames;
  21.    }
  22.  
  23.    void remove(MozillaFrame frame) {
  24.       this.frames.remove(new Integer(frame.MWContext));
  25.       --totalFrames;
  26.       if (this.frames.size() == 0) {
  27.          if (MozillaAppletContext.debug > 0) {
  28.             System.err.println("# Remove window " + this.MWContext);
  29.          }
  30.  
  31.          windows.remove(new Integer(this.MWContext));
  32.       }
  33.  
  34.    }
  35.  
  36.    void change(MozillaFrame frame, int oldMWContext, int newMWContext) {
  37.       this.frames.remove(new Integer(oldMWContext));
  38.       this.frames.put(new Integer(newMWContext), frame);
  39.    }
  40.  
  41.    MozillaFrame lookupFrame(int MWContext) {
  42.       MozillaFrame frame = (MozillaFrame)this.frames.get(new Integer(MWContext));
  43.       return frame;
  44.    }
  45.  
  46.    static int numWindows() {
  47.       return windows.size();
  48.    }
  49.  
  50.    static MozillaWindow lookupOrCreate(int MWContext) {
  51.       Integer key = new Integer(MWContext);
  52.       MozillaWindow win = (MozillaWindow)windows.get(key);
  53.       if (win == null) {
  54.          win = new MozillaWindow(MWContext);
  55.          windows.put(key, win);
  56.          if (MozillaAppletContext.debug > 0) {
  57.             System.err.println("# New window " + MWContext);
  58.          }
  59.       }
  60.  
  61.       return win;
  62.    }
  63.  
  64.    static void dumpState(PrintStream out) {
  65.       Enumeration e = windows.elements();
  66.  
  67.       while(e.hasMoreElements()) {
  68.          MozillaWindow w = (MozillaWindow)e.nextElement();
  69.          w.dumpState(out, 0);
  70.       }
  71.  
  72.    }
  73.  
  74.    static void indent(PrintStream out, int i) {
  75.       while(true) {
  76.          --i;
  77.          if (i < 0) {
  78.             return;
  79.          }
  80.  
  81.          out.print(" ");
  82.       }
  83.    }
  84.  
  85.    void dumpState(PrintStream out, int i) {
  86.       indent(out, i);
  87.       out.println("MozillaWindow MWContext=" + this.MWContext + "(" + this.frames.size() + " frames)");
  88.       Enumeration e = this.frames.elements();
  89.  
  90.       while(e.hasMoreElements()) {
  91.          MozillaFrame f = (MozillaFrame)e.nextElement();
  92.          f.dumpState(out, i + 1);
  93.       }
  94.  
  95.    }
  96. }
  97.