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