home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1CC1UCM (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  5.1 KB  |  146 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.BorderLayout;
  8. import java.awt.Component;
  9. import java.awt.Container;
  10. import java.awt.Graphics;
  11. import java.awt.LayoutManager;
  12. import java.awt.event.InputEvent;
  13. import java.awt.event.KeyEvent;
  14. import java.util.Vector;
  15.  
  16. public class JApplet extends Applet implements Accessible, RootPaneContainer {
  17.    protected JRootPane rootPane;
  18.    protected boolean rootPaneCheckingEnabled = false;
  19.    protected AccessibleContext accessibleContext = null;
  20.  
  21.    public JApplet() {
  22.       this.setLayout(new BorderLayout());
  23.       this.setRootPane(this.createRootPane());
  24.       this.setRootPaneCheckingEnabled(true);
  25.    }
  26.  
  27.    protected void addImpl(Component comp, Object constraints, int index) {
  28.       if (this.isRootPaneCheckingEnabled()) {
  29.          throw this.createRootPaneException("add");
  30.       } else {
  31.          super.addImpl(comp, constraints, index);
  32.       }
  33.    }
  34.  
  35.    public void addNotify() {
  36.       SystemEventQueueUtilities.addRunnableCanvas(this);
  37.       super.addNotify();
  38.       ((Component)this).enableEvents(8L);
  39.    }
  40.  
  41.    protected JRootPane createRootPane() {
  42.       return new JRootPane();
  43.    }
  44.  
  45.    private Error createRootPaneException(String op) {
  46.       String type = this.getClass().getName();
  47.       return new Error("Do not use " + type + "." + op + "() use " + type + ".getContentPane()." + op + "() instead");
  48.    }
  49.  
  50.    public AccessibleContext getAccessibleContext() {
  51.       if (this.accessibleContext == null) {
  52.          this.accessibleContext = new AccessibleJApplet(this);
  53.       }
  54.  
  55.       return this.accessibleContext;
  56.    }
  57.  
  58.    public Container getContentPane() {
  59.       return this.getRootPane().getContentPane();
  60.    }
  61.  
  62.    public Component getGlassPane() {
  63.       return this.getRootPane().getGlassPane();
  64.    }
  65.  
  66.    public JMenuBar getJMenuBar() {
  67.       return this.getRootPane().getMenuBar();
  68.    }
  69.  
  70.    public JLayeredPane getLayeredPane() {
  71.       return this.getRootPane().getLayeredPane();
  72.    }
  73.  
  74.    public JRootPane getRootPane() {
  75.       return this.rootPane;
  76.    }
  77.  
  78.    protected boolean isRootPaneCheckingEnabled() {
  79.       return this.rootPaneCheckingEnabled;
  80.    }
  81.  
  82.    protected void processKeyEvent(KeyEvent e) {
  83.       super.processKeyEvent(e);
  84.       if (!((InputEvent)e).isConsumed()) {
  85.          JComponent.processKeyBindingsForAllComponents(e, this, new Vector(), ((AWTEvent)e).getID() == 401);
  86.       }
  87.  
  88.    }
  89.  
  90.    public void removeNotify() {
  91.       super.removeNotify();
  92.       SystemEventQueueUtilities.removeRunnableCanvas(this);
  93.    }
  94.  
  95.    public void setContentPane(Container contentPane) {
  96.       this.getRootPane().setContentPane(contentPane);
  97.    }
  98.  
  99.    public void setGlassPane(Component glassPane) {
  100.       this.getRootPane().setGlassPane(glassPane);
  101.    }
  102.  
  103.    public void setJMenuBar(JMenuBar menuBar) {
  104.       this.getRootPane().setMenuBar(menuBar);
  105.    }
  106.  
  107.    public void setLayeredPane(JLayeredPane layeredPane) {
  108.       this.getRootPane().setLayeredPane(layeredPane);
  109.    }
  110.  
  111.    public void setLayout(LayoutManager manager) {
  112.       if (this.isRootPaneCheckingEnabled()) {
  113.          throw this.createRootPaneException("setLayout");
  114.       } else {
  115.          super.setLayout(manager);
  116.       }
  117.    }
  118.  
  119.    protected void setRootPane(JRootPane root) {
  120.       if (this.rootPane != null) {
  121.          ((Container)this).remove(this.rootPane);
  122.       }
  123.  
  124.       this.rootPane = root;
  125.       if (this.rootPane != null) {
  126.          boolean checkingEnabled = this.isRootPaneCheckingEnabled();
  127.  
  128.          try {
  129.             this.setRootPaneCheckingEnabled(false);
  130.             ((Container)this).add(this.rootPane, "Center");
  131.          } finally {
  132.             this.setRootPaneCheckingEnabled(checkingEnabled);
  133.          }
  134.       }
  135.  
  136.    }
  137.  
  138.    protected void setRootPaneCheckingEnabled(boolean enabled) {
  139.       this.rootPaneCheckingEnabled = enabled;
  140.    }
  141.  
  142.    public void update(Graphics g) {
  143.       ((Container)this).paint(g);
  144.    }
  145. }
  146.