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

  1. /*
  2.  * @(#)BorderUIResource.java    1.6 98/02/02
  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.  
  21. package com.sun.java.swing.plaf;
  22.  
  23. import java.awt.Component;
  24. import java.awt.Insets;
  25. import java.awt.Graphics;
  26. import java.io.Serializable;
  27.  
  28. import com.sun.java.swing.BorderFactory;
  29. import com.sun.java.swing.border.*;
  30. import com.sun.java.swing.plaf.UIResource;
  31.  
  32.  
  33. /*
  34.  * A Border wrapper class which implements UIResource.  UI
  35.  * classes which set border properties should use this class
  36.  * to wrap any borders specified as defaults.
  37.  *
  38.  * This class delegates all method invocations to the
  39.  * Border "delegate" object specified at construction.
  40.  * <p>
  41.  * Warning: serialized objects of this class will not be compatible with
  42.  * future swing releases.  The current serialization support is appropriate
  43.  * for short term storage or RMI between Swing1.0 applications.  It will
  44.  * not be possible to load serialized Swing1.0 objects with future releases
  45.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  46.  * baseline for the serialized form of Swing objects.
  47.  *
  48.  * @see com.sun.java.swing.plaf.UIResource
  49.  * @version 1.6 02/02/98
  50.  * @author Amy Fowler
  51.  * 
  52.  */
  53. public class BorderUIResource implements Border, UIResource, Serializable
  54. {
  55.     static BorderUIResource etched;
  56.     static BorderUIResource loweredBevel;
  57.     static BorderUIResource raisedBevel;
  58.     static BorderUIResource blackLine;
  59.  
  60.     public static BorderUIResource getEtchedBorderUIResource() {
  61.         if (etched == null) {
  62.             etched = new BorderUIResource(BorderFactory.createEtchedBorder());
  63.         }
  64.         return etched;
  65.     }
  66.  
  67.     public static BorderUIResource getLoweredBevelBorderUIResource() {
  68.         if (loweredBevel == null) {
  69.             loweredBevel = new BorderUIResource(
  70.                                    BorderFactory.createLoweredBevelBorder());
  71.         }
  72.         return loweredBevel;
  73.     }
  74.  
  75.     public static BorderUIResource getRaisedBevelBorderUIResource() {
  76.         if (raisedBevel == null) {
  77.             raisedBevel = new BorderUIResource(
  78.                                    BorderFactory.createRaisedBevelBorder());
  79.         }
  80.         return raisedBevel;
  81.     }
  82.  
  83.     public static BorderUIResource getBlackLineBorderUIResource() {
  84.         if (blackLine == null) {
  85.             blackLine = new BorderUIResource(
  86.                                    LineBorder.createBlackLineBorder());
  87.         }
  88.         return blackLine;
  89.     }
  90.  
  91.     private Border delegate;
  92.  
  93.     /**
  94.      * Creates a UIResource border object which wraps
  95.      * an existing Border instance.
  96.      * @param delegate the border being wrapped
  97.      */
  98.     public BorderUIResource(Border delegate) {
  99.         if (delegate == null) {
  100.             throw new IllegalArgumentException("null border delegate argument");
  101.         }
  102.         this.delegate = delegate;
  103.     }
  104.  
  105.     public void paintBorder(Component c, Graphics g, int x, int y,
  106.                             int width, int height) {        
  107.         delegate.paintBorder(c, g, x, y, width, height);
  108.     }
  109.  
  110.     public Insets getBorderInsets(Component c)       {
  111.         return delegate.getBorderInsets(c);
  112.     }
  113.  
  114.     public boolean isBorderOpaque() { 
  115.         return delegate.isBorderOpaque();
  116.     }
  117.  
  118. }
  119.