home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / JDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  5.9 KB  |  246 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.WindowEvent;
  16. import javax.accessibility.Accessible;
  17. import javax.accessibility.AccessibleContext;
  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, String var2) {
  34.       this(var1, var2, false);
  35.    }
  36.  
  37.    public JDialog(Frame var1, String var2, boolean var3) {
  38.       super(var1 == null ? SwingUtilities.getSharedOwnerFrame() : var1, var2, var3);
  39.       this.defaultCloseOperation = 1;
  40.       this.rootPaneCheckingEnabled = false;
  41.       this.accessibleContext = null;
  42.       this.dialogInit();
  43.    }
  44.  
  45.    public JDialog(Frame var1, boolean var2) {
  46.       this(var1, (String)null, var2);
  47.    }
  48.  
  49.    protected void addImpl(Component var1, Object var2, int var3) {
  50.       if (this.isRootPaneCheckingEnabled()) {
  51.          throw this.createRootPaneException("add");
  52.       } else {
  53.          super.addImpl(var1, var2, var3);
  54.       }
  55.    }
  56.  
  57.    protected JRootPane createRootPane() {
  58.       return new JRootPane();
  59.    }
  60.  
  61.    private Error createRootPaneException(String var1) {
  62.       String var2 = this.getClass().getName();
  63.       return new Error("Do not use " + var2 + "." + var1 + "() use " + var2 + ".getContentPane()." + var1 + "() instead");
  64.    }
  65.  
  66.    protected void dialogInit() {
  67.       ((Component)this).enableEvents(64L);
  68.       this.setRootPane(this.createRootPane());
  69.       this.setRootPaneCheckingEnabled(true);
  70.    }
  71.  
  72.    public AccessibleContext getAccessibleContext() {
  73.       if (this.accessibleContext == null) {
  74.          this.accessibleContext = new AccessibleJDialog(this);
  75.       }
  76.  
  77.       return this.accessibleContext;
  78.    }
  79.  
  80.    public Container getContentPane() {
  81.       return this.getRootPane().getContentPane();
  82.    }
  83.  
  84.    public int getDefaultCloseOperation() {
  85.       return this.defaultCloseOperation;
  86.    }
  87.  
  88.    public Component getGlassPane() {
  89.       return this.getRootPane().getGlassPane();
  90.    }
  91.  
  92.    public JMenuBar getJMenuBar() {
  93.       return this.getRootPane().getMenuBar();
  94.    }
  95.  
  96.    public JLayeredPane getLayeredPane() {
  97.       return this.getRootPane().getLayeredPane();
  98.    }
  99.  
  100.    public JRootPane getRootPane() {
  101.       return this.rootPane;
  102.    }
  103.  
  104.    protected boolean isRootPaneCheckingEnabled() {
  105.       return this.rootPaneCheckingEnabled;
  106.    }
  107.  
  108.    protected String paramString() {
  109.       String var1;
  110.       if (this.defaultCloseOperation == 1) {
  111.          var1 = "HIDE_ON_CLOSE";
  112.       } else if (this.defaultCloseOperation == 2) {
  113.          var1 = "DISPOSE_ON_CLOSE";
  114.       } else if (this.defaultCloseOperation == 0) {
  115.          var1 = "DO_NOTHING_ON_CLOSE";
  116.       } else {
  117.          var1 = "";
  118.       }
  119.  
  120.       String var2 = this.rootPane != null ? this.rootPane.toString() : "";
  121.       String var3 = this.rootPaneCheckingEnabled ? "true" : "false";
  122.       return super.paramString() + ",defaultCloseOperation=" + var1 + ",rootPane=" + var2 + ",rootPaneCheckingEnabled=" + var3;
  123.    }
  124.  
  125.    protected void processWindowEvent(WindowEvent var1) {
  126.       super.processWindowEvent(var1);
  127.       if (((AWTEvent)var1).getID() == 201) {
  128.          switch (this.defaultCloseOperation) {
  129.             case 0:
  130.             default:
  131.                break;
  132.             case 1:
  133.                ((Component)this).setVisible(false);
  134.                break;
  135.             case 2:
  136.                ((Component)this).setVisible(false);
  137.                ((Window)this).dispose();
  138.          }
  139.       }
  140.  
  141.    }
  142.  
  143.    public void setContentPane(Container var1) {
  144.       this.getRootPane().setContentPane(var1);
  145.    }
  146.  
  147.    public void setDefaultCloseOperation(int var1) {
  148.       this.defaultCloseOperation = var1;
  149.    }
  150.  
  151.    public void setGlassPane(Component var1) {
  152.       this.getRootPane().setGlassPane(var1);
  153.    }
  154.  
  155.    public void setJMenuBar(JMenuBar var1) {
  156.       this.getRootPane().setMenuBar(var1);
  157.    }
  158.  
  159.    public void setLayeredPane(JLayeredPane var1) {
  160.       this.getRootPane().setLayeredPane(var1);
  161.    }
  162.  
  163.    public void setLayout(LayoutManager var1) {
  164.       if (this.isRootPaneCheckingEnabled()) {
  165.          throw this.createRootPaneException("setLayout");
  166.       } else {
  167.          super.setLayout(var1);
  168.       }
  169.    }
  170.  
  171.    public void setLocationRelativeTo(Component var1) {
  172.       Container var2 = null;
  173.       if (var1 != null) {
  174.          if (!(var1 instanceof Window) && !(var1 instanceof Applet)) {
  175.             for(Container var3 = var1.getParent(); var3 != null; var3 = ((Component)var3).getParent()) {
  176.                if (var3 instanceof Window || var3 instanceof Applet) {
  177.                   var2 = var3;
  178.                   break;
  179.                }
  180.             }
  181.          } else {
  182.             var2 = (Container)var1;
  183.          }
  184.       }
  185.  
  186.       if ((var1 == null || var1.isShowing()) && var2 != null && ((Component)var2).isShowing()) {
  187.          Dimension var10 = var1.getSize();
  188.          Point var11 = var1.getLocationOnScreen();
  189.          Rectangle var5 = ((Component)this).getBounds();
  190.          int var6 = var11.x + (var10.width - var5.width >> 1);
  191.          int var7 = var11.y + (var10.height - var5.height >> 1);
  192.          Dimension var8 = ((Window)this).getToolkit().getScreenSize();
  193.          if (var7 + var5.height > var8.height) {
  194.             var7 = var8.height - var5.height;
  195.             var6 = var11.x < var8.width >> 1 ? var11.x + var10.width : var11.x - var5.width;
  196.          }
  197.  
  198.          if (var6 + var5.width > var8.width) {
  199.             var6 = var8.width - var5.width;
  200.          }
  201.  
  202.          if (var6 < 0) {
  203.             var6 = 0;
  204.          }
  205.  
  206.          if (var7 < 0) {
  207.             var7 = 0;
  208.          }
  209.  
  210.          ((Component)this).setLocation(var6, var7);
  211.       } else {
  212.          Dimension var9 = ((Component)this).getSize();
  213.          Dimension var4 = ((Window)this).getToolkit().getScreenSize();
  214.          ((Component)this).setLocation((var4.width - var9.width) / 2, (var4.height - var9.height) / 2);
  215.       }
  216.  
  217.    }
  218.  
  219.    protected void setRootPane(JRootPane var1) {
  220.       if (this.rootPane != null) {
  221.          ((Container)this).remove(this.rootPane);
  222.       }
  223.  
  224.       this.rootPane = var1;
  225.       if (this.rootPane != null) {
  226.          boolean var2 = this.isRootPaneCheckingEnabled();
  227.  
  228.          try {
  229.             this.setRootPaneCheckingEnabled(false);
  230.             ((Container)this).add(this.rootPane, "Center");
  231.          } finally {
  232.             this.setRootPaneCheckingEnabled(var2);
  233.          }
  234.       }
  235.  
  236.    }
  237.  
  238.    protected void setRootPaneCheckingEnabled(boolean var1) {
  239.       this.rootPaneCheckingEnabled = var1;
  240.    }
  241.  
  242.    public void update(Graphics var1) {
  243.       ((Container)this).paint(var1);
  244.    }
  245. }
  246.