home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 July / PCO_07_97.ISO / NET_COM / cc32e40.exe / nav40.z / java40.jar / netscape / applet / ConsoleFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-07  |  4.7 KB  |  196 lines

  1. package netscape.applet;
  2.  
  3. import java.awt.Button;
  4. import java.awt.Container;
  5. import java.awt.Event;
  6. import java.awt.Frame;
  7. import java.awt.GridBagConstraints;
  8. import java.awt.GridBagLayout;
  9. import java.awt.Insets;
  10. import java.awt.TextArea;
  11. import java.awt.Window;
  12.  
  13. class ConsoleFrame extends Frame {
  14.    Console console;
  15.    TextArea text;
  16.    Button reset;
  17.    Button hide;
  18.  
  19.    ConsoleFrame(Console var1) {
  20.       this.console = var1;
  21.       ((Frame)this).setTitle("Java Console");
  22.       GridBagLayout var2 = new GridBagLayout();
  23.       ((Container)this).setLayout(var2);
  24.       this.text = new TextArea(20, 60);
  25.       this.text.setEditable(false);
  26.       GridBagConstraints var3 = new GridBagConstraints();
  27.       var3.fill = 1;
  28.       var3.weightx = (double)1.0F;
  29.       var3.weighty = (double)1.0F;
  30.       var3.gridwidth = 0;
  31.       var2.setConstraints(this.text, var3);
  32.       ((Container)this).add(this.text);
  33.       HorizontalRule var4 = new HorizontalRule();
  34.       GridBagConstraints var5 = new GridBagConstraints();
  35.       var5.fill = 2;
  36.       var5.weightx = (double)1.0F;
  37.       var5.insets = new Insets(1, 1, 0, 0);
  38.       var5.gridwidth = 0;
  39.       var2.setConstraints(var4, var5);
  40.       ((Container)this).add(var4);
  41.       this.reset = new Button("Clear");
  42.       GridBagConstraints var6 = new GridBagConstraints();
  43.       var6.insets = new Insets(4, 0, 2, 4);
  44.       var6.anchor = 13;
  45.       var2.setConstraints(this.reset, var6);
  46.       ((Container)this).add(this.reset);
  47.       this.hide = new Button("Close");
  48.       GridBagConstraints var7 = new GridBagConstraints();
  49.       var7.insets = new Insets(4, 0, 2, 4);
  50.       var7.anchor = 13;
  51.       var2.setConstraints(this.hide, var7);
  52.       ((Container)this).add(this.hide);
  53.       ((Window)this).pack();
  54.    }
  55.  
  56.    public boolean handleEvent(Event var1) {
  57.       if (var1.id != 201 && (var1.target != this.hide || var1.id != 1001)) {
  58.          if (var1.target == this.reset && var1.id == 1001) {
  59.             this.console.reset();
  60.             return true;
  61.          } else {
  62.             return super.handleEvent(var1);
  63.          }
  64.       } else {
  65.          this.console.hide();
  66.          return true;
  67.       }
  68.    }
  69.  
  70.    public boolean keyDown(Event var1, int var2) {
  71.       if (var2 >= 48 && var2 <= 57) {
  72.          MozillaAppletContext.debug = var2 - 48;
  73.          System.err.println("# Applet debug level set to " + MozillaAppletContext.debug);
  74.          return true;
  75.       } else if (var2 != 100 && var2 != 68) {
  76.          if (var2 != 119 && var2 != 87) {
  77.             if (var2 != 103 && var2 != 71) {
  78.                if (var2 != 102 && var2 != 70) {
  79.                   if (var2 != 109 && var2 != 77) {
  80.                      if (var2 == 120) {
  81.                         System.err.print("# Dumping memory to 'memory.out'...");
  82.                         Console.dumpMemory(false);
  83.                         System.err.println("done.");
  84.                         return true;
  85.                      } else if (var2 == 88) {
  86.                         System.err.print("# Dumping memory to 'memory.out'...");
  87.                         Console.dumpMemory(true);
  88.                         System.err.println("done.");
  89.                         return true;
  90.                      } else if (var2 != 115 && var2 != 83) {
  91.                         if (var2 != 116 && var2 != 84) {
  92.                            if (var2 != 107 && var2 != 75) {
  93.                               if (var2 != 99 && var2 != 67) {
  94.                                  if (var2 != 113 && var2 != 81) {
  95.                                     if (var2 != 104 && var2 != 72 && var2 != 63 && var2 != 32) {
  96.                                        if (var2 != 119 && var2 != 87) {
  97.                                           if (var2 != 108 && var2 != 76) {
  98.                                              return super.keyDown(var1, var2);
  99.                                           } else {
  100.                                              boolean var3 = !AppletClassLoader.getCaptureClassFiles();
  101.                                              AppletClassLoader.setCaptureClassFiles(var3);
  102.                                              System.err.println("# Class file capture " + (var3 ? "enabled" : "disabled"));
  103.                                              return true;
  104.                                           }
  105.                                        } else {
  106.                                           System.err.print("# Dumping application heaps...");
  107.                                           Console.dumpApplicationHeaps();
  108.                                           System.err.println("done.");
  109.                                           return true;
  110.                                        }
  111.                                     } else {
  112.                                        this.printConsoleHelp();
  113.                                        return true;
  114.                                     }
  115.                                  } else {
  116.                                     this.console.hide();
  117.                                     return true;
  118.                                  }
  119.                               } else {
  120.                                  this.reset();
  121.                                  return true;
  122.                               }
  123.                            } else {
  124.                               System.err.print("# Checkpointing memory...");
  125.                               Console.checkpointMemory();
  126.                               System.err.println("done.");
  127.                               return true;
  128.                            }
  129.                         } else {
  130.                            System.err.print("# Dumping thread info to 'memory.out'...");
  131.                            Console.dumpNSPRInfo();
  132.                            System.err.println("done.");
  133.                            return true;
  134.                         }
  135.                      } else {
  136.                         System.err.print("# Dumping memory summary to 'memory.out'...");
  137.                         Console.dumpMemorySummary();
  138.                         System.err.println("done.");
  139.                         return true;
  140.                      }
  141.                   } else {
  142.                      this.printMemoryStats("Memory");
  143.                      return true;
  144.                   }
  145.                } else {
  146.                   System.err.println("# Performing finalization...");
  147.                   System.runFinalization();
  148.                   this.printMemoryStats("Finalization complete: memory");
  149.                   return true;
  150.                }
  151.             } else {
  152.                System.err.println("# Performing a garbage collection...");
  153.                System.gc();
  154.                this.printMemoryStats("GC complete: memory");
  155.                return true;
  156.             }
  157.          } else {
  158.             System.err.print("# Dumping application heaps...");
  159.             Console.dumpApplicationHeaps();
  160.             System.err.println("done.");
  161.             return true;
  162.          }
  163.       } else {
  164.          MozillaAppletContext.dumpState(System.err);
  165.          return true;
  166.       }
  167.    }
  168.  
  169.    void printMemoryStats(String var1) {
  170.       Runtime var2 = Runtime.getRuntime();
  171.       System.err.println("# " + var1 + ": " + var2.totalMemory() + " free: " + var2.freeMemory() + " (" + var2.freeMemory() * 100L / var2.totalMemory() + "%)");
  172.    }
  173.  
  174.    void printConsoleHelp() {
  175.       System.out.println("Netscape Java Console Commands:");
  176.       System.out.println("  c:   clear console window");
  177.       System.out.println("  d:   dump applet context state to console");
  178.       System.out.println("  f:   finalize objects on finalization queue");
  179.       System.out.println("  g:   garbage collect");
  180.       System.out.println("  h:   print this help message");
  181.       System.out.println("  l:   capture all classes loaded by an applet to a directory");
  182.       System.out.println("  m:   print current memory use to console");
  183.       System.out.println("  q:   hide console");
  184.       System.out.println("  s:   dump memory summary to \"memory.out\"");
  185.       System.out.println("  t:   dump thread info to \"memory.out\"");
  186.       System.out.println("  x:   dump memory to \"memory.out\"");
  187.       System.out.println("  X:   dump memory (detailed) to \"memory.out\"");
  188.       System.out.println("  0-9: set applet debug level to <n>");
  189.       System.out.println();
  190.    }
  191.  
  192.    void reset() {
  193.       this.text.setText("");
  194.    }
  195. }
  196.