home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / JDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  5.5 KB  |  228 lines

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