home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / JDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.8 KB  |  300 lines

  1. package javax.swing;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.AWTEvent;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Dialog;
  8. import java.awt.Dimension;
  9. import java.awt.Frame;
  10. import java.awt.Graphics;
  11. import java.awt.LayoutManager;
  12. import java.awt.Point;
  13. import java.awt.Rectangle;
  14. import java.awt.Window;
  15. import java.awt.event.InputEvent;
  16. import java.awt.event.KeyEvent;
  17. import java.awt.event.WindowEvent;
  18. import javax.accessibility.Accessible;
  19. import javax.accessibility.AccessibleContext;
  20.  
  21. public class JDialog extends Dialog implements WindowConstants, Accessible, RootPaneContainer {
  22.    private int defaultCloseOperation;
  23.    protected JRootPane rootPane;
  24.    protected boolean rootPaneCheckingEnabled;
  25.    protected AccessibleContext accessibleContext;
  26.  
  27.    public JDialog() {
  28.       this((Frame)null, false);
  29.    }
  30.  
  31.    public JDialog(Frame var1) {
  32.       this(var1, false);
  33.    }
  34.  
  35.    public JDialog(Frame var1, boolean var2) {
  36.       this((Frame)var1, (String)null, var2);
  37.    }
  38.  
  39.    public JDialog(Frame var1, String var2) {
  40.       this(var1, var2, false);
  41.    }
  42.  
  43.    public JDialog(Frame var1, String var2, boolean var3) {
  44.       super(var1 == null ? SwingUtilities.getSharedOwnerFrame() : var1, var2, var3);
  45.       this.defaultCloseOperation = 1;
  46.       this.rootPaneCheckingEnabled = false;
  47.       this.accessibleContext = null;
  48.       this.dialogInit();
  49.    }
  50.  
  51.    public JDialog(Dialog var1) {
  52.       this(var1, false);
  53.    }
  54.  
  55.    public JDialog(Dialog var1, boolean var2) {
  56.       this((Dialog)var1, (String)null, var2);
  57.    }
  58.  
  59.    public JDialog(Dialog var1, String var2) {
  60.       this(var1, var2, false);
  61.    }
  62.  
  63.    public JDialog(Dialog var1, String var2, boolean var3) {
  64.       super(var1, var2, var3);
  65.       this.defaultCloseOperation = 1;
  66.       this.rootPaneCheckingEnabled = false;
  67.       this.accessibleContext = null;
  68.       this.dialogInit();
  69.    }
  70.  
  71.    protected void dialogInit() {
  72.       ((Component)this).enableEvents(72L);
  73.       this.setRootPane(this.createRootPane());
  74.       this.setRootPaneCheckingEnabled(true);
  75.    }
  76.  
  77.    protected JRootPane createRootPane() {
  78.       return new JRootPane();
  79.    }
  80.  
  81.    protected void processKeyEvent(KeyEvent var1) {
  82.       super.processKeyEvent(var1);
  83.       if (!((InputEvent)var1).isConsumed()) {
  84.          JComponent.processKeyBindingsForAllComponents(var1, this, ((AWTEvent)var1).getID() == 401);
  85.       }
  86.  
  87.    }
  88.  
  89.    protected void processWindowEvent(WindowEvent var1) {
  90.       super.processWindowEvent(var1);
  91.       if (((AWTEvent)var1).getID() == 201) {
  92.          switch (this.defaultCloseOperation) {
  93.             case 0:
  94.             default:
  95.                break;
  96.             case 1:
  97.                ((Component)this).setVisible(false);
  98.                break;
  99.             case 2:
  100.                ((Component)this).setVisible(false);
  101.                ((Dialog)this).dispose();
  102.          }
  103.       }
  104.  
  105.    }
  106.  
  107.    public void setDefaultCloseOperation(int var1) {
  108.       this.defaultCloseOperation = var1;
  109.    }
  110.  
  111.    public int getDefaultCloseOperation() {
  112.       return this.defaultCloseOperation;
  113.    }
  114.  
  115.    public void update(Graphics var1) {
  116.       ((Container)this).paint(var1);
  117.    }
  118.  
  119.    public void setJMenuBar(JMenuBar var1) {
  120.       this.getRootPane().setMenuBar(var1);
  121.    }
  122.  
  123.    public JMenuBar getJMenuBar() {
  124.       return this.getRootPane().getMenuBar();
  125.    }
  126.  
  127.    protected boolean isRootPaneCheckingEnabled() {
  128.       return this.rootPaneCheckingEnabled;
  129.    }
  130.  
  131.    protected void setRootPaneCheckingEnabled(boolean var1) {
  132.       this.rootPaneCheckingEnabled = var1;
  133.    }
  134.  
  135.    private Error createRootPaneException(String var1) {
  136.       String var2 = this.getClass().getName();
  137.       return new Error("Do not use " + var2 + "." + var1 + "() use " + var2 + ".getContentPane()." + var1 + "() instead");
  138.    }
  139.  
  140.    protected void addImpl(Component var1, Object var2, int var3) {
  141.       if (this.isRootPaneCheckingEnabled()) {
  142.          throw this.createRootPaneException("add");
  143.       } else {
  144.          super.addImpl(var1, var2, var3);
  145.       }
  146.    }
  147.  
  148.    public void remove(Component var1) {
  149.       if (var1 == this.rootPane) {
  150.          super.remove(var1);
  151.       } else {
  152.          this.getContentPane().remove(var1);
  153.       }
  154.  
  155.    }
  156.  
  157.    public void setLayout(LayoutManager var1) {
  158.       if (this.isRootPaneCheckingEnabled()) {
  159.          throw this.createRootPaneException("setLayout");
  160.       } else {
  161.          super.setLayout(var1);
  162.       }
  163.    }
  164.  
  165.    public JRootPane getRootPane() {
  166.       return this.rootPane;
  167.    }
  168.  
  169.    protected void setRootPane(JRootPane var1) {
  170.       if (this.rootPane != null) {
  171.          this.remove(this.rootPane);
  172.       }
  173.  
  174.       this.rootPane = var1;
  175.       if (this.rootPane != null) {
  176.          boolean var2 = this.isRootPaneCheckingEnabled();
  177.  
  178.          try {
  179.             this.setRootPaneCheckingEnabled(false);
  180.             ((Container)this).add(this.rootPane, "Center");
  181.          } finally {
  182.             this.setRootPaneCheckingEnabled(var2);
  183.          }
  184.       }
  185.  
  186.    }
  187.  
  188.    public Container getContentPane() {
  189.       return this.getRootPane().getContentPane();
  190.    }
  191.  
  192.    public void setContentPane(Container var1) {
  193.       this.getRootPane().setContentPane(var1);
  194.    }
  195.  
  196.    public JLayeredPane getLayeredPane() {
  197.       return this.getRootPane().getLayeredPane();
  198.    }
  199.  
  200.    public void setLayeredPane(JLayeredPane var1) {
  201.       this.getRootPane().setLayeredPane(var1);
  202.    }
  203.  
  204.    public Component getGlassPane() {
  205.       return this.getRootPane().getGlassPane();
  206.    }
  207.  
  208.    public void setGlassPane(Component var1) {
  209.       this.getRootPane().setGlassPane(var1);
  210.    }
  211.  
  212.    public void setLocationRelativeTo(Component var1) {
  213.       Container var2 = null;
  214.       if (var1 != null) {
  215.          if (!(var1 instanceof Window) && !(var1 instanceof Applet)) {
  216.             for(Container var3 = var1.getParent(); var3 != null; var3 = ((Component)var3).getParent()) {
  217.                if (var3 instanceof Window || var3 instanceof Applet) {
  218.                   var2 = var3;
  219.                   break;
  220.                }
  221.             }
  222.          } else {
  223.             var2 = (Container)var1;
  224.          }
  225.       }
  226.  
  227.       if ((var1 == null || var1.isShowing()) && var2 != null && ((Component)var2).isShowing()) {
  228.          Dimension var10 = var1.getSize();
  229.          Point var11;
  230.          if (var2 instanceof Applet) {
  231.             var11 = var1.getLocationOnScreen();
  232.          } else {
  233.             var11 = new Point(0, 0);
  234.  
  235.             for(Object var5 = var1; var5 != null; var5 = ((Component)var5).getParent()) {
  236.                Point var6 = ((Component)var5).getLocation();
  237.                var11.x += var6.x;
  238.                var11.y += var6.y;
  239.                if (var5 == var2) {
  240.                   break;
  241.                }
  242.             }
  243.          }
  244.  
  245.          Rectangle var12 = ((Component)this).getBounds();
  246.          int var13 = var11.x + (var10.width - var12.width >> 1);
  247.          int var7 = var11.y + (var10.height - var12.height >> 1);
  248.          Dimension var8 = ((Window)this).getToolkit().getScreenSize();
  249.          if (var7 + var12.height > var8.height) {
  250.             var7 = var8.height - var12.height;
  251.             var13 = var11.x < var8.width >> 1 ? var11.x + var10.width : var11.x - var12.width;
  252.          }
  253.  
  254.          if (var13 + var12.width > var8.width) {
  255.             var13 = var8.width - var12.width;
  256.          }
  257.  
  258.          if (var13 < 0) {
  259.             var13 = 0;
  260.          }
  261.  
  262.          if (var7 < 0) {
  263.             var7 = 0;
  264.          }
  265.  
  266.          ((Component)this).setLocation(var13, var7);
  267.       } else {
  268.          Dimension var9 = ((Component)this).getSize();
  269.          Dimension var4 = ((Window)this).getToolkit().getScreenSize();
  270.          ((Component)this).setLocation((var4.width - var9.width) / 2, (var4.height - var9.height) / 2);
  271.       }
  272.  
  273.    }
  274.  
  275.    protected String paramString() {
  276.       String var1;
  277.       if (this.defaultCloseOperation == 1) {
  278.          var1 = "HIDE_ON_CLOSE";
  279.       } else if (this.defaultCloseOperation == 2) {
  280.          var1 = "DISPOSE_ON_CLOSE";
  281.       } else if (this.defaultCloseOperation == 0) {
  282.          var1 = "DO_NOTHING_ON_CLOSE";
  283.       } else {
  284.          var1 = "";
  285.       }
  286.  
  287.       String var2 = this.rootPane != null ? this.rootPane.toString() : "";
  288.       String var3 = this.rootPaneCheckingEnabled ? "true" : "false";
  289.       return super.paramString() + ",defaultCloseOperation=" + var1 + ",rootPane=" + var2 + ",rootPaneCheckingEnabled=" + var3;
  290.    }
  291.  
  292.    public AccessibleContext getAccessibleContext() {
  293.       if (this.accessibleContext == null) {
  294.          this.accessibleContext = new AccessibleJDialog(this);
  295.       }
  296.  
  297.       return this.accessibleContext;
  298.    }
  299. }
  300.