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