home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / jfc.bin / JPanel.java < prev    next >
Text File  |  1998-02-26  |  5KB  |  158 lines

  1. /*
  2.  * @(#)JPanel.java    1.18 98/02/05
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing;
  21.  
  22. import com.sun.java.accessibility.*;
  23. import java.awt.*;
  24. import com.sun.java.swing.plaf.ComponentUI;
  25. import com.sun.java.swing.plaf.UIResource;
  26.  
  27. /**
  28.  * JPanel is a generic lightweight container.
  29.  * <p>
  30.  * Warning: serialized objects of this class will not be compatible with
  31.  * future swing releases.  The current serialization support is appropriate 
  32.  * for short term storage or RMI between Swing1.0 applications.  It will
  33.  * not be possible to load serialized Swing1.0 objects with future releases
  34.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  35.  * baseline for the serialized form of Swing objects.
  36.  *
  37.  * @beaninfo
  38.  * description: A generic lightweight container.
  39.  * 
  40.  * @version 1.18 02/05/98
  41.  * @author Arnaud Weber
  42.  */
  43. public class JPanel extends JComponent implements Accessible
  44. {
  45.     private static final FlowLayout defaultLayout = new FlowLayout();
  46.     
  47.     /**
  48.      * Creates a new JPanel
  49.      */
  50.     public JPanel(LayoutManager layout, boolean isDoubleBuffered) {
  51.         setLayout(layout);
  52.         setDoubleBuffered(isDoubleBuffered);
  53.     setOpaque(true);
  54.     // PENDING(jeff) - this should be done in BasicPanelUI
  55.     // PENDING(steve) - if such a class existed... ;-)
  56.  
  57.         Color bg = this.getBackground();
  58.     if (bg == null || bg instanceof UIResource) {
  59.         this.setBackground(UIManager.getColor("Panel.background"));
  60.     }
  61.  
  62.         Color fg = this.getForeground();
  63.     if (fg == null || fg instanceof UIResource) {
  64.         this.setForeground(UIManager.getColor("Panel.foreground"));
  65.     } 
  66.  
  67.         Font font = this.getFont();
  68.     if (font == null || font instanceof UIResource) {
  69.         this.setFont(UIManager.getFont("Panel.font"));
  70.     } 
  71.     }
  72.  
  73.     /**
  74.      * Create a new buffered JPanel with a specific layout manager
  75.      */
  76.     public JPanel(LayoutManager layout) {
  77.         this(layout, true);
  78.     }
  79.  
  80.     /**
  81.      * Create a new JPanel with a FlowLayout. If <code>isDoubleBuffered</code>
  82.      * is true, the JPanel will use a double buffer.
  83.      */
  84.     public JPanel(boolean isDoubleBuffered) {
  85.         this(defaultLayout, isDoubleBuffered);
  86.     }
  87.  
  88.     /**
  89.      * Create a new JPanel with a double buffer and a flow layout
  90.      **/
  91.     public JPanel() {
  92.         this(defaultLayout, true);
  93.     }
  94.  
  95.     /**
  96.      * PENDING(jeff) - this should be done in BasicPanelUI
  97.      */
  98.     public void updateUI() {
  99.     super.updateUI();
  100.     if(getBackground() == null || getBackground() instanceof UIResource) {
  101.         setBackground(UIManager.getColor("Panel.background"));
  102.     }
  103.     }
  104.  
  105.     
  106.     /**
  107.      * Overriden from JComponent, paint the backgroud if the component is opaque.
  108.      * The color used is the one returned by getBackground()
  109.      * Override this method if you want to change how the JPanel paints its background
  110.      */
  111.     public void paintComponent(Graphics g) {
  112.         if(isOpaque()) {
  113.             g.setColor(getBackground());
  114.             g.fillRect(0,0,getWidth(),getHeight());
  115.         } 
  116.     }
  117.  
  118. /////////////////
  119. // Accessibility support
  120. ////////////////
  121.  
  122.     /**
  123.      * Get the AccessibleContext associated with this JComponent
  124.      *
  125.      * @return the AccessibleContext of this JComponent
  126.      */
  127.     public AccessibleContext getAccessibleContext() {
  128.     if (accessibleContext == null) {
  129.         accessibleContext = new AccessibleJPanel();
  130.     }
  131.     return accessibleContext;
  132.     }
  133.  
  134.     /**
  135.      * The class used to obtain the accessible role for this object.
  136.      * <p>
  137.      * Warning: serialized objects of this class will not be compatible with
  138.      * future swing releases.  The current serialization support is appropriate
  139.      * for short term storage or RMI between Swing1.0 applications.  It will
  140.      * not be possible to load serialized Swing1.0 objects with future releases
  141.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  142.      * baseline for the serialized form of Swing objects.
  143.      */
  144.     protected class AccessibleJPanel extends AccessibleJComponent {
  145.  
  146.     /**
  147.      * Get the role of this object.
  148.      *
  149.      * @return an instance of AccessibleRole describing the role of the 
  150.      * object
  151.      */
  152.     public AccessibleRole getAccessibleRole() {
  153.         return AccessibleRole.PANEL;
  154.     }
  155.     }
  156. }
  157.  
  158.