home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / JRootPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  5.0 KB  |  172 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.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.IllegalComponentStateException;
  8. import java.awt.LayoutManager;
  9.  
  10. public class JRootPane extends JComponent implements Accessible {
  11.    protected JMenuBar menuBar;
  12.    protected Container contentPane;
  13.    protected JLayeredPane layeredPane;
  14.    protected Component glassPane;
  15.    protected JButton defaultButton;
  16.    protected DefaultAction defaultPressAction;
  17.    protected DefaultAction defaultReleaseAction;
  18.  
  19.    public JRootPane() {
  20.       this.setGlassPane(this.createGlassPane());
  21.       this.setLayeredPane(this.createLayeredPane());
  22.       this.setContentPane(this.createContentPane());
  23.       ((Container)this).setLayout(this.createRootLayout());
  24.       ((JComponent)this).setDoubleBuffered(true);
  25.       ((Component)this).setBackground(UIManager.getColor("control"));
  26.    }
  27.  
  28.    protected JLayeredPane createLayeredPane() {
  29.       JLayeredPane var1 = new JLayeredPane();
  30.       ((Component)var1).setName(((Component)this).getName() + ".layeredPane");
  31.       return var1;
  32.    }
  33.  
  34.    protected Container createContentPane() {
  35.       JPanel var1 = new JPanel();
  36.       ((Component)var1).setName(((Component)this).getName() + ".contentPane");
  37.       ((Container)var1).setLayout(new 1());
  38.       return var1;
  39.    }
  40.  
  41.    protected Component createGlassPane() {
  42.       JPanel var1 = new JPanel();
  43.       ((Component)var1).setName(((Component)this).getName() + ".glassPane");
  44.       ((JComponent)var1).setVisible(false);
  45.       ((JPanel)var1).setOpaque(false);
  46.       return var1;
  47.    }
  48.  
  49.    protected LayoutManager createRootLayout() {
  50.       return new RootLayout(this);
  51.    }
  52.  
  53.    public void setMenuBar(JMenuBar var1) {
  54.       if (this.menuBar != null && this.menuBar.getParent() == this.layeredPane) {
  55.          this.layeredPane.remove(this.menuBar);
  56.       }
  57.  
  58.       this.menuBar = var1;
  59.       if (this.menuBar != null) {
  60.          this.layeredPane.add(this.menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  61.       }
  62.  
  63.    }
  64.  
  65.    public JMenuBar getMenuBar() {
  66.       return this.menuBar;
  67.    }
  68.  
  69.    public void setContentPane(Container var1) {
  70.       if (var1 == null) {
  71.          throw new IllegalComponentStateException("contentPane cannot be set to null.");
  72.       } else {
  73.          if (this.contentPane != null && this.contentPane.getParent() == this.layeredPane) {
  74.             this.layeredPane.remove(this.contentPane);
  75.          }
  76.  
  77.          this.contentPane = var1;
  78.          this.layeredPane.add(this.contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
  79.       }
  80.    }
  81.  
  82.    public Container getContentPane() {
  83.       return this.contentPane;
  84.    }
  85.  
  86.    public void setLayeredPane(JLayeredPane var1) {
  87.       if (var1 == null) {
  88.          throw new IllegalComponentStateException("layeredPane cannot be set to null.");
  89.       } else {
  90.          if (this.layeredPane != null && this.layeredPane.getParent() == this) {
  91.             ((Container)this).remove(this.layeredPane);
  92.          }
  93.  
  94.          this.layeredPane = var1;
  95.          ((Container)this).add(this.layeredPane, -1);
  96.       }
  97.    }
  98.  
  99.    public JLayeredPane getLayeredPane() {
  100.       return this.layeredPane;
  101.    }
  102.  
  103.    public void setGlassPane(Component var1) {
  104.       if (var1 == null) {
  105.          throw new NullPointerException("glassPane cannot be set to null.");
  106.       } else {
  107.          boolean var2 = false;
  108.          if (this.glassPane != null && this.glassPane.getParent() == this) {
  109.             ((Container)this).remove(this.glassPane);
  110.             var2 = this.glassPane.isVisible();
  111.          }
  112.  
  113.          var1.setVisible(var2);
  114.          this.glassPane = var1;
  115.          ((Container)this).add(this.glassPane, 0);
  116.          if (var2) {
  117.             ((Component)this).repaint();
  118.          }
  119.  
  120.       }
  121.    }
  122.  
  123.    public Component getGlassPane() {
  124.       return this.glassPane;
  125.    }
  126.  
  127.    public void setDefaultButton(JButton var1) {
  128.       JButton var2 = this.defaultButton;
  129.       this.defaultButton = var1;
  130.       if (this.defaultPressAction == null) {
  131.          this.defaultPressAction = new DefaultAction(this, true);
  132.          this.defaultReleaseAction = new DefaultAction(this, false);
  133.          ((JComponent)this).registerKeyboardAction(this.defaultPressAction, KeyStroke.getKeyStroke(10, 0, false), 2);
  134.          ((JComponent)this).registerKeyboardAction(this.defaultReleaseAction, KeyStroke.getKeyStroke(10, 0, true), 2);
  135.       }
  136.  
  137.       if (var2 != var1) {
  138.          this.defaultPressAction.setOwner(var1);
  139.          this.defaultReleaseAction.setOwner(var1);
  140.          if (var2 != null) {
  141.             ((Component)var2).repaint();
  142.          }
  143.  
  144.          if (var1 != null) {
  145.             ((Component)var1).repaint();
  146.          }
  147.       }
  148.  
  149.       ((JComponent)this).firePropertyChange("defaultButton", var2, var1);
  150.    }
  151.  
  152.    public JButton getDefaultButton() {
  153.       return this.defaultButton;
  154.    }
  155.  
  156.    protected void addImpl(Component var1, Object var2, int var3) {
  157.       super.addImpl(var1, var2, var3);
  158.       if (this.glassPane != null && this.glassPane.getParent() == this && ((Container)this).getComponent(0) != this.glassPane) {
  159.          ((Container)this).add(this.glassPane, 0);
  160.       }
  161.  
  162.    }
  163.  
  164.    public AccessibleContext getAccessibleContext() {
  165.       if (super.accessibleContext == null) {
  166.          super.accessibleContext = new AccessibleJRootPane(this);
  167.       }
  168.  
  169.       return super.accessibleContext;
  170.    }
  171. }
  172.