< prev index next >

src/java.desktop/share/classes/javax/swing/border/BevelBorder.java

Print this page




  35  * <p>
  36  * <strong>Warning:</strong>
  37  * Serialized objects of this class will not be compatible with
  38  * future Swing releases. The current serialization support is
  39  * appropriate for short term storage or RMI between applications running
  40  * the same version of Swing.  As of 1.4, support for long term storage
  41  * of all JavaBeans&trade;
  42  * has been added to the <code>java.beans</code> package.
  43  * Please see {@link java.beans.XMLEncoder}.
  44  *
  45  * @author David Kloba
  46  */
  47 @SuppressWarnings("serial") // Same-version serialization only
  48 public class BevelBorder extends AbstractBorder
  49 {
  50     /** Raised bevel type. */
  51     public static final int RAISED  = 0;
  52     /** Lowered bevel type. */
  53     public static final int LOWERED = 1;
  54 



  55     protected int bevelType;



  56     protected Color highlightOuter;



  57     protected Color highlightInner;



  58     protected Color shadowInner;



  59     protected Color shadowOuter;
  60 
  61     /**
  62      * Creates a bevel border with the specified type and whose
  63      * colors will be derived from the background color of the
  64      * component passed into the paintBorder method.
  65      * @param bevelType the type of bevel for the border
  66      */
  67     public BevelBorder(int bevelType) {
  68         this.bevelType = bevelType;
  69     }
  70 
  71     /**
  72      * Creates a bevel border with the specified type, highlight and
  73      * shadow colors.
  74      * @param bevelType the type of bevel for the border
  75      * @param highlight the color to use for the bevel highlight
  76      * @param shadow the color to use for the bevel shadow
  77      */
  78     public BevelBorder(int bevelType, Color highlight, Color shadow) {


 245         return shadowOuter;
 246     }
 247 
 248     /**
 249      * Returns the type of the bevel border.
 250      *
 251      * @return the bevel border type, either {@code RAISED} or {@code LOWERED}
 252      */
 253     public int getBevelType()       {
 254         return bevelType;
 255     }
 256 
 257     /**
 258      * Returns whether or not the border is opaque. This implementation
 259      * returns {@code true}.
 260      *
 261      * @return true
 262      */
 263     public boolean isBorderOpaque() { return true; }
 264 











 265     protected void paintRaisedBevel(Component c, Graphics g, int x, int y,
 266                                     int width, int height)  {
 267         Color oldColor = g.getColor();
 268         int h = height;
 269         int w = width;
 270 
 271         g.translate(x, y);
 272 
 273         g.setColor(getHighlightOuterColor(c));
 274         g.drawLine(0, 0, 0, h-2);
 275         g.drawLine(1, 0, w-2, 0);
 276 
 277         g.setColor(getHighlightInnerColor(c));
 278         g.drawLine(1, 1, 1, h-3);
 279         g.drawLine(2, 1, w-3, 1);
 280 
 281         g.setColor(getShadowOuterColor(c));
 282         g.drawLine(0, h-1, w-1, h-1);
 283         g.drawLine(w-1, 0, w-1, h-2);
 284 
 285         g.setColor(getShadowInnerColor(c));
 286         g.drawLine(1, h-2, w-2, h-2);
 287         g.drawLine(w-2, 1, w-2, h-3);
 288 
 289         g.translate(-x, -y);
 290         g.setColor(oldColor);
 291 
 292     }
 293 











 294     protected void paintLoweredBevel(Component c, Graphics g, int x, int y,
 295                                         int width, int height)  {
 296         Color oldColor = g.getColor();
 297         int h = height;
 298         int w = width;
 299 
 300         g.translate(x, y);
 301 
 302         g.setColor(getShadowInnerColor(c));
 303         g.drawLine(0, 0, 0, h-1);
 304         g.drawLine(1, 0, w-1, 0);
 305 
 306         g.setColor(getShadowOuterColor(c));
 307         g.drawLine(1, 1, 1, h-2);
 308         g.drawLine(2, 1, w-2, 1);
 309 
 310         g.setColor(getHighlightOuterColor(c));
 311         g.drawLine(1, h-1, w-1, h-1);
 312         g.drawLine(w-1, 1, w-1, h-2);
 313 


  35  * <p>
  36  * <strong>Warning:</strong>
  37  * Serialized objects of this class will not be compatible with
  38  * future Swing releases. The current serialization support is
  39  * appropriate for short term storage or RMI between applications running
  40  * the same version of Swing.  As of 1.4, support for long term storage
  41  * of all JavaBeans&trade;
  42  * has been added to the <code>java.beans</code> package.
  43  * Please see {@link java.beans.XMLEncoder}.
  44  *
  45  * @author David Kloba
  46  */
  47 @SuppressWarnings("serial") // Same-version serialization only
  48 public class BevelBorder extends AbstractBorder
  49 {
  50     /** Raised bevel type. */
  51     public static final int RAISED  = 0;
  52     /** Lowered bevel type. */
  53     public static final int LOWERED = 1;
  54 
  55     /**
  56      * The bevel type.
  57      */
  58     protected int bevelType;
  59     /**
  60      * The color to use for the bevel outer highlight.
  61      */
  62     protected Color highlightOuter;
  63     /**
  64      * The color to use for the bevel inner highlight.
  65      */
  66     protected Color highlightInner;
  67     /**
  68      * The color to use for the bevel inner shadow.
  69      */
  70     protected Color shadowInner;
  71     /**
  72      * the color to use for the bevel outer shadow
  73      */
  74     protected Color shadowOuter;
  75 
  76     /**
  77      * Creates a bevel border with the specified type and whose
  78      * colors will be derived from the background color of the
  79      * component passed into the paintBorder method.
  80      * @param bevelType the type of bevel for the border
  81      */
  82     public BevelBorder(int bevelType) {
  83         this.bevelType = bevelType;
  84     }
  85 
  86     /**
  87      * Creates a bevel border with the specified type, highlight and
  88      * shadow colors.
  89      * @param bevelType the type of bevel for the border
  90      * @param highlight the color to use for the bevel highlight
  91      * @param shadow the color to use for the bevel shadow
  92      */
  93     public BevelBorder(int bevelType, Color highlight, Color shadow) {


 260         return shadowOuter;
 261     }
 262 
 263     /**
 264      * Returns the type of the bevel border.
 265      *
 266      * @return the bevel border type, either {@code RAISED} or {@code LOWERED}
 267      */
 268     public int getBevelType()       {
 269         return bevelType;
 270     }
 271 
 272     /**
 273      * Returns whether or not the border is opaque. This implementation
 274      * returns {@code true}.
 275      *
 276      * @return true
 277      */
 278     public boolean isBorderOpaque() { return true; }
 279 
 280     /**
 281      * Paints a raised bevel for the specified component with the specified
 282      * position and size.
 283      *
 284      * @param c the component for which the raised bevel is being painted
 285      * @param g the paint graphics
 286      * @param x the x position of the raised bevel
 287      * @param y the y position of the raised bevel
 288      * @param width the width of the raised bevel
 289      * @param height the height of the raised bevel
 290      */
 291     protected void paintRaisedBevel(Component c, Graphics g, int x, int y,
 292                                     int width, int height)  {
 293         Color oldColor = g.getColor();
 294         int h = height;
 295         int w = width;
 296 
 297         g.translate(x, y);
 298 
 299         g.setColor(getHighlightOuterColor(c));
 300         g.drawLine(0, 0, 0, h-2);
 301         g.drawLine(1, 0, w-2, 0);
 302 
 303         g.setColor(getHighlightInnerColor(c));
 304         g.drawLine(1, 1, 1, h-3);
 305         g.drawLine(2, 1, w-3, 1);
 306 
 307         g.setColor(getShadowOuterColor(c));
 308         g.drawLine(0, h-1, w-1, h-1);
 309         g.drawLine(w-1, 0, w-1, h-2);
 310 
 311         g.setColor(getShadowInnerColor(c));
 312         g.drawLine(1, h-2, w-2, h-2);
 313         g.drawLine(w-2, 1, w-2, h-3);
 314 
 315         g.translate(-x, -y);
 316         g.setColor(oldColor);
 317 
 318     }
 319 
 320     /**
 321      * Paints a lowered bevel for the specified component with the specified
 322      * position and size.
 323      *
 324      * @param c the component for which the lowered bevel is being painted
 325      * @param g the paint graphics
 326      * @param x the x position of the lowered bevel
 327      * @param y the y position of the lowered bevel
 328      * @param width the width of the lowered bevel
 329      * @param height the height of the lowered bevel
 330      */
 331     protected void paintLoweredBevel(Component c, Graphics g, int x, int y,
 332                                         int width, int height)  {
 333         Color oldColor = g.getColor();
 334         int h = height;
 335         int w = width;
 336 
 337         g.translate(x, y);
 338 
 339         g.setColor(getShadowInnerColor(c));
 340         g.drawLine(0, 0, 0, h-1);
 341         g.drawLine(1, 0, w-1, 0);
 342 
 343         g.setColor(getShadowOuterColor(c));
 344         g.drawLine(1, 1, 1, h-2);
 345         g.drawLine(2, 1, w-2, 1);
 346 
 347         g.setColor(getHighlightOuterColor(c));
 348         g.drawLine(1, h-1, w-1, h-1);
 349         g.drawLine(w-1, 1, w-1, h-2);
 350 
< prev index next >