jdk/src/share/classes/javax/swing/BorderFactory.java
changeset 5765 b9ebe03ab870
parent 5506 202f599c92aa
child 7006 05505fff1342
equal deleted inserted replaced
5764:47146334ce6e 5765:b9ebe03ab870
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 package javax.swing;
    25 package javax.swing;
    26 
    26 
    27 import java.awt.Color;
    27 import java.awt.Color;
    28 import java.awt.Font;
    28 import java.awt.Font;
    29 import javax.swing.JComponent;
       
    30 import javax.swing.border.*;
    29 import javax.swing.border.*;
    31 
    30 
    32 /**
    31 /**
    33  * Factory class for vending standard <code>Border</code> objects.  Wherever
    32  * Factory class for vending standard <code>Border</code> objects.  Wherever
    34  * possible, this factory will hand out references to shared
    33  * possible, this factory will hand out references to shared
    72      */
    71      */
    73     public static Border createLineBorder(Color color, int thickness)  {
    72     public static Border createLineBorder(Color color, int thickness)  {
    74         return new LineBorder(color, thickness);
    73         return new LineBorder(color, thickness);
    75     }
    74     }
    76 
    75 
    77 //    public static Border createLineBorder(Color color, int thickness,
    76     /**
    78 //                                      boolean drawRounded)  {
    77      * Creates a line border with the specified color, thickness, and corner shape.
    79 //        return new JLineBorder(color, thickness, drawRounded);
    78      *
    80 //    }
    79      * @param color      the color of the border
       
    80      * @param thickness  the thickness of the border
       
    81      * @param rounded    whether or not border corners should be round
       
    82      * @return the {@code Border} object
       
    83      *
       
    84      * @see LineBorder#LineBorder(Color, int, boolean)
       
    85      * @since 1.7
       
    86      */
       
    87     public static Border createLineBorder(Color color, int thickness, boolean rounded) {
       
    88         return new LineBorder(color, thickness, rounded);
       
    89     }
    81 
    90 
    82 //// BevelBorder /////////////////////////////////////////////////////////////
    91 //// BevelBorder /////////////////////////////////////////////////////////////
    83 ///////////////////////////////////////////////////////////////////////////////
    92 ///////////////////////////////////////////////////////////////////////////////
    84     static final Border sharedRaisedBevel = new BevelBorder(BevelBorder.RAISED);
    93     static final Border sharedRaisedBevel = new BevelBorder(BevelBorder.RAISED);
    85     static final Border sharedLoweredBevel = new BevelBorder(BevelBorder.LOWERED);
    94     static final Border sharedLoweredBevel = new BevelBorder(BevelBorder.LOWERED);
   178         } else if(type == BevelBorder.LOWERED) {
   187         } else if(type == BevelBorder.LOWERED) {
   179             return sharedLoweredBevel;
   188             return sharedLoweredBevel;
   180         }
   189         }
   181         return null;
   190         return null;
   182     }
   191     }
       
   192 
       
   193 //// SoftBevelBorder ///////////////////////////////////////////////////////////
       
   194 ////////////////////////////////////////////////////////////////////////////////
       
   195 
       
   196     private static Border sharedSoftRaisedBevel;
       
   197     private static Border sharedSoftLoweredBevel;
       
   198 
       
   199     /**
       
   200      * Creates a beveled border with a raised edge and softened corners,
       
   201      * using brighter shades of the component's current background color
       
   202      * for highlighting, and darker shading for shadows.
       
   203      * In a raised border, highlights are on top and shadows are underneath.
       
   204      *
       
   205      * @return the {@code Border} object
       
   206      *
       
   207      * @since 1.7
       
   208      */
       
   209     public static Border createRaisedSoftBevelBorder() {
       
   210         if (sharedSoftRaisedBevel == null) {
       
   211             sharedSoftRaisedBevel = new SoftBevelBorder(BevelBorder.RAISED);
       
   212         }
       
   213         return sharedSoftRaisedBevel;
       
   214     }
       
   215 
       
   216     /**
       
   217      * Creates a beveled border with a lowered edge and softened corners,
       
   218      * using brighter shades of the component's current background color
       
   219      * for highlighting, and darker shading for shadows.
       
   220      * In a lowered border, shadows are on top and highlights are underneath.
       
   221      *
       
   222      * @return the {@code Border} object
       
   223      *
       
   224      * @since 1.7
       
   225      */
       
   226     public static Border createLoweredSoftBevelBorder() {
       
   227         if (sharedSoftLoweredBevel == null) {
       
   228             sharedSoftLoweredBevel = new SoftBevelBorder(BevelBorder.LOWERED);
       
   229         }
       
   230         return sharedSoftLoweredBevel;
       
   231     }
       
   232 
       
   233     /**
       
   234      * Creates a beveled border of the specified type with softened corners,
       
   235      * using brighter shades of the component's current background color
       
   236      * for highlighting, and darker shading for shadows.
       
   237      * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
       
   238      *
       
   239      * @param type  a type of a bevel
       
   240      * @return the {@code Border} object or {@code null}
       
   241      *         if the specified type is not valid
       
   242      *
       
   243      * @see BevelBorder#BevelBorder(int)
       
   244      * @since 1.7
       
   245      */
       
   246     public static Border createSoftBevelBorder(int type) {
       
   247         if (type == BevelBorder.RAISED) {
       
   248             return createRaisedSoftBevelBorder();
       
   249         }
       
   250         if (type == BevelBorder.LOWERED) {
       
   251             return createLoweredSoftBevelBorder();
       
   252         }
       
   253         return null;
       
   254     }
       
   255 
       
   256     /**
       
   257      * Creates a beveled border of the specified type with softened corners,
       
   258      * using the specified highlighting and shadowing.
       
   259      * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
       
   260      * The outer edge of the highlight area uses
       
   261      * a brighter shade of the {@code highlight} color.
       
   262      * The inner edge of the shadow area uses
       
   263      * a brighter shade of the {@code shadow} color.
       
   264      *
       
   265      * @param type       a type of a bevel
       
   266      * @param highlight  a basic color of the highlight area
       
   267      * @param shadow     a basic color of the shadow area
       
   268      * @return the {@code Border} object
       
   269      *
       
   270      * @see BevelBorder#BevelBorder(int, Color, Color)
       
   271      * @since 1.7
       
   272      */
       
   273     public static Border createSoftBevelBorder(int type, Color highlight, Color shadow) {
       
   274         return new BevelBorder(type, highlight, shadow);
       
   275     }
       
   276 
       
   277     /**
       
   278      * Creates a beveled border of the specified type with softened corners,
       
   279      * using the specified colors for the inner and outer edges
       
   280      * of the highlight and the shadow areas.
       
   281      * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
       
   282      * Note: The shadow inner and outer colors are switched
       
   283      * for a lowered bevel border.
       
   284      *
       
   285      * @param type            a type of a bevel
       
   286      * @param highlightOuter  a color of the outer edge of the highlight area
       
   287      * @param highlightInner  a color of the inner edge of the highlight area
       
   288      * @param shadowOuter     a color of the outer edge of the shadow area
       
   289      * @param shadowInner     a color of the inner edge of the shadow area
       
   290      * @return the {@code Border} object
       
   291      *
       
   292      * @see BevelBorder#BevelBorder(int, Color, Color, Color, Color)
       
   293      * @since 1.7
       
   294      */
       
   295     public static Border createSoftBevelBorder(int type, Color highlightOuter, Color highlightInner, Color shadowOuter, Color shadowInner) {
       
   296         return new BevelBorder(type, highlightOuter, highlightInner, shadowOuter, shadowInner);
       
   297     }
       
   298 
   183 //// EtchedBorder ///////////////////////////////////////////////////////////
   299 //// EtchedBorder ///////////////////////////////////////////////////////////
       
   300 
   184     static final Border sharedEtchedBorder = new EtchedBorder();
   301     static final Border sharedEtchedBorder = new EtchedBorder();
   185     private static Border sharedRaisedEtchedBorder;
   302     private static Border sharedRaisedEtchedBorder;
   186 
   303 
   187     /**
   304     /**
   188      * Creates a border with an "etched" look using
   305      * Creates a border with an "etched" look using