jdk/src/share/classes/javax/swing/border/SoftBevelBorder.java
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 package javax.swing.border;
       
    26 
       
    27 import java.awt.Graphics;
       
    28 import java.awt.Insets;
       
    29 import java.awt.Rectangle;
       
    30 import java.awt.Color;
       
    31 import java.awt.Component;
       
    32 import java.beans.ConstructorProperties;
       
    33 
       
    34 /**
       
    35  * A class which implements a raised or lowered bevel with
       
    36  * softened corners.
       
    37  * <p>
       
    38  * <strong>Warning:</strong>
       
    39  * Serialized objects of this class will not be compatible with
       
    40  * future Swing releases. The current serialization support is
       
    41  * appropriate for short term storage or RMI between applications running
       
    42  * the same version of Swing.  As of 1.4, support for long term storage
       
    43  * of all JavaBeans<sup><font size="-2">TM</font></sup>
       
    44  * has been added to the <code>java.beans</code> package.
       
    45  * Please see {@link java.beans.XMLEncoder}.
       
    46  *
       
    47  * @author Amy Fowler
       
    48  * @author Chester Rose
       
    49  */
       
    50 public class SoftBevelBorder extends BevelBorder
       
    51 {
       
    52 
       
    53     /**
       
    54      * Creates a bevel border with the specified type and whose
       
    55      * colors will be derived from the background color of the
       
    56      * component passed into the paintBorder method.
       
    57      * @param bevelType the type of bevel for the border
       
    58      */
       
    59     public SoftBevelBorder(int bevelType) {
       
    60         super(bevelType);
       
    61     }
       
    62 
       
    63     /**
       
    64      * Creates a bevel border with the specified type, highlight and
       
    65      * shadow colors.
       
    66      * @param bevelType the type of bevel for the border
       
    67      * @param highlight the color to use for the bevel highlight
       
    68      * @param shadow the color to use for the bevel shadow
       
    69      */
       
    70     public SoftBevelBorder(int bevelType, Color highlight, Color shadow) {
       
    71         super(bevelType, highlight, shadow);
       
    72     }
       
    73 
       
    74     /**
       
    75      * Creates a bevel border with the specified type, highlight
       
    76      * shadow colors.
       
    77      * @param bevelType the type of bevel for the border
       
    78      * @param highlightOuterColor the color to use for the bevel outer highlight
       
    79      * @param highlightInnerColor the color to use for the bevel inner highlight
       
    80      * @param shadowOuterColor the color to use for the bevel outer shadow
       
    81      * @param shadowInnerColor the color to use for the bevel inner shadow
       
    82      */
       
    83     @ConstructorProperties({"bevelType", "highlightOuterColor", "highlightInnerColor", "shadowOuterColor", "shadowInnerColor"})
       
    84     public SoftBevelBorder(int bevelType, Color highlightOuterColor,
       
    85                         Color highlightInnerColor, Color shadowOuterColor,
       
    86                         Color shadowInnerColor) {
       
    87         super(bevelType, highlightOuterColor, highlightInnerColor,
       
    88               shadowOuterColor, shadowInnerColor);
       
    89     }
       
    90 
       
    91     /**
       
    92      * Paints the border for the specified component with the specified
       
    93      * position and size.
       
    94      * @param c the component for which this border is being painted
       
    95      * @param g the paint graphics
       
    96      * @param x the x position of the painted border
       
    97      * @param y the y position of the painted border
       
    98      * @param width the width of the painted border
       
    99      * @param height the height of the painted border
       
   100      */
       
   101     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
       
   102         Color oldColor = g.getColor();
       
   103         g.translate(x, y);
       
   104 
       
   105         if (bevelType == RAISED) {
       
   106             g.setColor(getHighlightOuterColor(c));
       
   107             g.drawLine(0, 0, width-2, 0);
       
   108             g.drawLine(0, 0, 0, height-2);
       
   109             g.drawLine(1, 1, 1, 1);
       
   110 
       
   111             g.setColor(getHighlightInnerColor(c));
       
   112             g.drawLine(2, 1, width-2, 1);
       
   113             g.drawLine(1, 2, 1, height-2);
       
   114             g.drawLine(2, 2, 2, 2);
       
   115             g.drawLine(0, height-1, 0, height-2);
       
   116             g.drawLine(width-1, 0, width-1, 0);
       
   117 
       
   118             g.setColor(getShadowOuterColor(c));
       
   119             g.drawLine(2, height-1, width-1, height-1);
       
   120             g.drawLine(width-1, 2, width-1, height-1);
       
   121 
       
   122             g.setColor(getShadowInnerColor(c));
       
   123             g.drawLine(width-2, height-2, width-2, height-2);
       
   124 
       
   125 
       
   126         } else if (bevelType == LOWERED) {
       
   127             g.setColor(getShadowOuterColor(c));
       
   128             g.drawLine(0, 0, width-2, 0);
       
   129             g.drawLine(0, 0, 0, height-2);
       
   130             g.drawLine(1, 1, 1, 1);
       
   131 
       
   132             g.setColor(getShadowInnerColor(c));
       
   133             g.drawLine(2, 1, width-2, 1);
       
   134             g.drawLine(1, 2, 1, height-2);
       
   135             g.drawLine(2, 2, 2, 2);
       
   136             g.drawLine(0, height-1, 0, height-2);
       
   137             g.drawLine(width-1, 0, width-1, 0);
       
   138 
       
   139             g.setColor(getHighlightOuterColor(c));
       
   140             g.drawLine(2, height-1, width-1, height-1);
       
   141             g.drawLine(width-1, 2, width-1, height-1);
       
   142 
       
   143             g.setColor(getHighlightInnerColor(c));
       
   144             g.drawLine(width-2, height-2, width-2, height-2);
       
   145         }
       
   146         g.translate(-x, -y);
       
   147         g.setColor(oldColor);
       
   148     }
       
   149 
       
   150     /**
       
   151      * Reinitialize the insets parameter with this Border's current Insets.
       
   152      * @param c the component for which this border insets value applies
       
   153      * @param insets the object to be reinitialized
       
   154      */
       
   155     public Insets getBorderInsets(Component c, Insets insets)       {
       
   156         insets.set(3, 3, 3, 3);
       
   157         return insets;
       
   158     }
       
   159 
       
   160     /**
       
   161      * Returns whether or not the border is opaque.
       
   162      */
       
   163     public boolean isBorderOpaque() { return false; }
       
   164 
       
   165 }