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