home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 31 / SUPERCDa.iso / Inet / HotJava / hjava.exe / Windows / resource / jre / lib / rt.jar / java / awt / Window.class (.txt) < prev   
Encoding:
Java Class File  |  1998-11-11  |  7.7 KB  |  354 lines

  1. package java.awt;
  2.  
  3. import java.awt.event.InputEvent;
  4. import java.awt.event.KeyEvent;
  5. import java.awt.event.WindowEvent;
  6. import java.awt.event.WindowListener;
  7. import java.awt.peer.WindowPeer;
  8. import java.io.IOException;
  9. import java.io.ObjectInputStream;
  10. import java.io.ObjectOutputStream;
  11. import java.util.EventObject;
  12. import java.util.Locale;
  13. import sun.awt.im.InputContext;
  14.  
  15. public class Window extends Container {
  16.    String warningString;
  17.    static final int OPENED = 1;
  18.    int state;
  19.    transient WindowListener windowListener;
  20.    private transient boolean active;
  21.    transient InputContext inputContext;
  22.    private FocusManager focusMgr;
  23.    private static final String base = "win";
  24.    private static int nameCounter;
  25.    private static final long serialVersionUID = 4497834738069338734L;
  26.    private int windowSerializedDataVersion;
  27.  
  28.    Window() {
  29.       this.windowSerializedDataVersion = 1;
  30.       this.setWarningString();
  31.       this.focusMgr = new FocusManager(this);
  32.       super.visible = false;
  33.    }
  34.  
  35.    String constructComponentName() {
  36.       return "win" + nameCounter++;
  37.    }
  38.  
  39.    public Window(Frame var1) {
  40.       this();
  41.       if (var1 == null) {
  42.          throw new IllegalArgumentException("null parent frame");
  43.       } else {
  44.          super.parent = var1;
  45.          var1.addOwnedWindow(this);
  46.          ((Container)this).setLayout(new BorderLayout());
  47.       }
  48.    }
  49.  
  50.    public void addNotify() {
  51.       Object var1 = ((Component)this).getTreeLock();
  52.       synchronized(var1){}
  53.  
  54.       try {
  55.          if (super.peer == null) {
  56.             super.peer = this.getToolkit().createWindow(this);
  57.          }
  58.  
  59.          super.addNotify();
  60.       } catch (Throwable var3) {
  61.          throw var3;
  62.       }
  63.  
  64.    }
  65.  
  66.    public void pack() {
  67.       Container var1 = super.parent;
  68.       if (var1 != null && ((Component)var1).getPeer() == null) {
  69.          var1.addNotify();
  70.       }
  71.  
  72.       if (super.peer == null) {
  73.          this.addNotify();
  74.       }
  75.  
  76.       ((Component)this).setSize(((Container)this).getPreferredSize());
  77.       ((Container)this).validate();
  78.    }
  79.  
  80.    public void show() {
  81.       Container var1 = super.parent;
  82.       if (var1 != null && ((Component)var1).getPeer() == null) {
  83.          var1.addNotify();
  84.       }
  85.  
  86.       if (super.peer == null) {
  87.          this.addNotify();
  88.       }
  89.  
  90.       ((Container)this).validate();
  91.       if (super.visible) {
  92.          this.toFront();
  93.       } else {
  94.          super.show();
  95.       }
  96.  
  97.       if ((this.state & 1) == 0) {
  98.          this.postWindowEvent(200);
  99.          this.state |= 1;
  100.       }
  101.  
  102.    }
  103.  
  104.    synchronized void postWindowEvent(int var1) {
  105.       if (this.windowListener != null || (super.eventMask & 64L) != 0L) {
  106.          WindowEvent var2 = new WindowEvent(this, var1);
  107.          Toolkit.getEventQueue().postEvent(var2);
  108.       }
  109.  
  110.    }
  111.  
  112.    public void dispose() {
  113.       Object var1 = ((Component)this).getTreeLock();
  114.       synchronized(var1){}
  115.  
  116.       try {
  117.          if (this.inputContext != null) {
  118.             InputContext var3 = this.inputContext;
  119.             this.inputContext = null;
  120.             var3.dispose();
  121.          }
  122.  
  123.          ((Component)this).hide();
  124.          ((Container)this).removeNotify();
  125.          if (super.parent != null) {
  126.             Frame var6 = (Frame)super.parent;
  127.             var6.removeOwnedWindow(this);
  128.          }
  129.  
  130.          this.postWindowEvent(202);
  131.       } catch (Throwable var5) {
  132.          throw var5;
  133.       }
  134.  
  135.    }
  136.  
  137.    public void toFront() {
  138.       WindowPeer var1 = (WindowPeer)super.peer;
  139.       if (var1 != null) {
  140.          var1.toFront();
  141.       }
  142.  
  143.    }
  144.  
  145.    public void toBack() {
  146.       WindowPeer var1 = (WindowPeer)super.peer;
  147.       if (var1 != null) {
  148.          var1.toBack();
  149.       }
  150.  
  151.    }
  152.  
  153.    public Toolkit getToolkit() {
  154.       return Toolkit.getDefaultToolkit();
  155.    }
  156.  
  157.    public final String getWarningString() {
  158.       return this.warningString;
  159.    }
  160.  
  161.    private void setWarningString() {
  162.       this.warningString = null;
  163.       SecurityManager var1 = System.getSecurityManager();
  164.       if (var1 != null && !var1.checkTopLevelWindow(this)) {
  165.          this.warningString = System.getProperty("awt.appletWarning", "Warning: Applet Window");
  166.       }
  167.  
  168.    }
  169.  
  170.    public Locale getLocale() {
  171.       return super.locale == null ? Locale.getDefault() : super.locale;
  172.    }
  173.  
  174.    synchronized InputContext getInputContext() {
  175.       if (this.inputContext == null) {
  176.          this.inputContext = InputContext.getInstance();
  177.       }
  178.  
  179.       return this.inputContext;
  180.    }
  181.  
  182.    public synchronized void addWindowListener(WindowListener var1) {
  183.       this.windowListener = AWTEventMulticaster.add(this.windowListener, var1);
  184.       super.newEventsOnly = true;
  185.    }
  186.  
  187.    public synchronized void removeWindowListener(WindowListener var1) {
  188.       this.windowListener = AWTEventMulticaster.remove(this.windowListener, var1);
  189.    }
  190.  
  191.    boolean eventEnabled(AWTEvent var1) {
  192.       switch (var1.id) {
  193.          case 200:
  194.          case 201:
  195.          case 202:
  196.          case 203:
  197.          case 204:
  198.          case 205:
  199.          case 206:
  200.             if ((super.eventMask & 64L) == 0L && this.windowListener == null) {
  201.                return false;
  202.             }
  203.  
  204.             return true;
  205.          default:
  206.             return super.eventEnabled(var1);
  207.       }
  208.    }
  209.  
  210.    protected void processEvent(AWTEvent var1) {
  211.       if (var1 instanceof WindowEvent) {
  212.          this.processWindowEvent((WindowEvent)var1);
  213.       } else {
  214.          super.processEvent(var1);
  215.       }
  216.    }
  217.  
  218.    protected void processWindowEvent(WindowEvent var1) {
  219.       if (this.windowListener != null) {
  220.          switch (((AWTEvent)var1).getID()) {
  221.             case 200:
  222.                this.windowListener.windowOpened(var1);
  223.                return;
  224.             case 201:
  225.                this.windowListener.windowClosing(var1);
  226.                return;
  227.             case 202:
  228.                this.windowListener.windowClosed(var1);
  229.                return;
  230.             case 203:
  231.                this.windowListener.windowIconified(var1);
  232.                return;
  233.             case 204:
  234.                this.windowListener.windowDeiconified(var1);
  235.                return;
  236.             case 205:
  237.                this.windowListener.windowActivated(var1);
  238.                return;
  239.             case 206:
  240.                this.windowListener.windowDeactivated(var1);
  241.                return;
  242.          }
  243.       }
  244.  
  245.    }
  246.  
  247.    private boolean handleTabEvent(KeyEvent var1) {
  248.       if (var1.getKeyCode() == 9 && !(((EventObject)var1).getSource() instanceof TextArea)) {
  249.          if ((((InputEvent)var1).getModifiers() & -2) > 0) {
  250.             return false;
  251.          } else {
  252.             int var2 = ((AWTEvent)var1).getID();
  253.             if (var2 != 402 && var2 != 400) {
  254.                return ((InputEvent)var1).isShiftDown() ? this.focusMgr.focusPrevious() : this.focusMgr.focusNext();
  255.             } else {
  256.                return true;
  257.             }
  258.          }
  259.       } else {
  260.          return false;
  261.       }
  262.    }
  263.  
  264.    void preProcessKeyEvent(KeyEvent var1) {
  265.       if (var1.isActionKey() && var1.getKeyCode() == 112 && ((InputEvent)var1).isControlDown() && ((InputEvent)var1).isShiftDown()) {
  266.          ((Container)this).list(System.out, 0);
  267.       }
  268.  
  269.    }
  270.  
  271.    void postProcessKeyEvent(KeyEvent var1) {
  272.       if (this.handleTabEvent(var1)) {
  273.          ((InputEvent)var1).consume();
  274.       }
  275.    }
  276.  
  277.    void setFocusOwner(Component var1) {
  278.       this.focusMgr.setFocusOwner(var1);
  279.    }
  280.  
  281.    void transferFocus(Component var1) {
  282.       this.nextFocus(var1);
  283.    }
  284.  
  285.    boolean isActive() {
  286.       return this.active;
  287.    }
  288.  
  289.    public Component getFocusOwner() {
  290.       return this.active ? this.focusMgr.getFocusOwner() : null;
  291.    }
  292.  
  293.    /** @deprecated */
  294.    void nextFocus(Component var1) {
  295.       this.focusMgr.focusNext(var1);
  296.    }
  297.  
  298.    void dispatchEventImpl(AWTEvent var1) {
  299.       switch (var1.getID()) {
  300.          case 101:
  301.             ((Container)this).invalidate();
  302.             ((Container)this).validate();
  303.             ((Component)this).repaint();
  304.             break;
  305.          case 205:
  306.             this.active = true;
  307.             break;
  308.          case 206:
  309.             this.active = false;
  310.             break;
  311.          case 1004:
  312.             this.setFocusOwner(this);
  313.       }
  314.  
  315.       super.dispatchEventImpl(var1);
  316.    }
  317.  
  318.    /** @deprecated */
  319.    public boolean postEvent(Event var1) {
  320.       if (((Component)this).handleEvent(var1)) {
  321.          var1.consume();
  322.          return true;
  323.       } else {
  324.          return false;
  325.       }
  326.    }
  327.  
  328.    public boolean isShowing() {
  329.       return super.visible;
  330.    }
  331.  
  332.    private void writeObject(ObjectOutputStream var1) throws IOException {
  333.       var1.defaultWriteObject();
  334.       AWTEventMulticaster.save(var1, "windowL", this.windowListener);
  335.       var1.writeObject((Object)null);
  336.    }
  337.  
  338.    private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
  339.       var1.defaultReadObject();
  340.  
  341.       Object var2;
  342.       while((var2 = var1.readObject()) != null) {
  343.          String var3 = ((String)var2).intern();
  344.          if (var3 == "windowL") {
  345.             this.addWindowListener((WindowListener)var1.readObject());
  346.          } else {
  347.             var1.readObject();
  348.          }
  349.       }
  350.  
  351.       this.setWarningString();
  352.    }
  353. }
  354.