1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * 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.Component;
  31 import java.io.Serializable;
  32 import java.beans.ConstructorProperties;
  33 
  34 /**
  35  * A class which provides an empty, transparent border which
  36  * takes up space but does no drawing.
  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&trade;
  44  * has been added to the <code>java.beans</code> package.
  45  * Please see {@link java.beans.XMLEncoder}.
  46  *
  47  * @author David Kloba
  48  */
  49 @SuppressWarnings("serial")
  50 public class EmptyBorder extends AbstractBorder implements Serializable
  51 {
  52     /**
  53      * The left inset of the border.
  54      */
  55     protected int left;
  56     /**
  57      * The right inset of the border.
  58      */
  59     protected int right;
  60     /**
  61      * The top inset of the border.
  62      */
  63     protected int top;
  64     /**
  65      * The bottom inset of the border.
  66      */
  67     protected int bottom;
  68 
  69     /**
  70      * Creates an empty border with the specified insets.
  71      * @param top the top inset of the border
  72      * @param left the left inset of the border
  73      * @param bottom the bottom inset of the border
  74      * @param right the right inset of the border
  75      */
  76     public EmptyBorder(int top, int left, int bottom, int right)   {
  77         this.top = top;
  78         this.right = right;
  79         this.bottom = bottom;
  80         this.left = left;
  81     }
  82 
  83     /**
  84      * Creates an empty border with the specified insets.
  85      * @param borderInsets the insets of the border
  86      */
  87     @ConstructorProperties({"borderInsets"})
  88     public EmptyBorder(Insets borderInsets)   {
  89         this.top = borderInsets.top;
  90         this.right = borderInsets.right;
  91         this.bottom = borderInsets.bottom;
  92         this.left = borderInsets.left;
  93     }
  94 
  95     /**
  96      * Does no drawing by default.
  97      */
  98     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  99     }
 100 
 101     /**
 102      * Reinitialize the insets parameter with this Border's current Insets.
 103      * @param c the component for which this border insets value applies
 104      * @param insets the object to be reinitialized
 105      */
 106     public Insets getBorderInsets(Component c, Insets insets) {
 107         insets.left = left;
 108         insets.top = top;
 109         insets.right = right;
 110         insets.bottom = bottom;
 111         return insets;
 112     }
 113 
 114     /**
 115      * Returns the insets of the border.
 116      *
 117      * @return an {@code Insets} object containing the insets from top, left,
 118      *         bottom and right
 119      * @since 1.3
 120      */
 121     public Insets getBorderInsets() {
 122         return new Insets(top, left, bottom, right);
 123     }
 124 
 125     /**
 126      * Returns whether or not the border is opaque.
 127      * Returns false by default.
 128      */
 129     public boolean isBorderOpaque() { return false; }
 130 
 131 }