< prev index next >

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

Print this page




  53  * <li>&quot;TitledBorder.border&quot;
  54  * <li>&quot;TitledBorder.font&quot;
  55  * <li>&quot;TitledBorder.titleColor&quot;
  56  * </ul>
  57  * <p>
  58  * <strong>Warning:</strong>
  59  * Serialized objects of this class will not be compatible with
  60  * future Swing releases. The current serialization support is
  61  * appropriate for short term storage or RMI between applications running
  62  * the same version of Swing.  As of 1.4, support for long term storage
  63  * of all JavaBeans&trade;
  64  * has been added to the <code>java.beans</code> package.
  65  * Please see {@link java.beans.XMLEncoder}.
  66  *
  67  * @author David Kloba
  68  * @author Amy Fowler
  69  */
  70 @SuppressWarnings("serial")
  71 public class TitledBorder extends AbstractBorder
  72 {



  73     protected String title;



  74     protected Border border;



  75     protected int titlePosition;



  76     protected int titleJustification;



  77     protected Font titleFont;



  78     protected Color titleColor;
  79 
  80     private final JLabel label;
  81 
  82     /**
  83      * Use the default vertical orientation for the title text.
  84      */
  85     static public final int     DEFAULT_POSITION        = 0;
  86     /** Position the title above the border's top line. */
  87     static public final int     ABOVE_TOP               = 1;
  88     /** Position the title in the middle of the border's top line. */
  89     static public final int     TOP                     = 2;
  90     /** Position the title below the border's top line. */
  91     static public final int     BELOW_TOP               = 3;
  92     /** Position the title above the border's bottom line. */
  93     static public final int     ABOVE_BOTTOM            = 4;
  94     /** Position the title in the middle of the border's bottom line. */
  95     static public final int     BOTTOM                  = 5;
  96     /** Position the title below the border's bottom line. */
  97     static public final int     BELOW_BOTTOM            = 6;


 100      * Use the default justification for the title text.
 101      */
 102     static public final int     DEFAULT_JUSTIFICATION   = 0;
 103     /** Position title text at the left side of the border line. */
 104     static public final int     LEFT                    = 1;
 105     /** Position title text in the center of the border line. */
 106     static public final int     CENTER                  = 2;
 107     /** Position title text at the right side of the border line. */
 108     static public final int     RIGHT                   = 3;
 109     /** Position title text at the left side of the border line
 110      *  for left to right orientation, at the right side of the
 111      *  border line for right to left orientation.
 112      */
 113     static public final int     LEADING = 4;
 114     /** Position title text at the right side of the border line
 115      *  for left to right orientation, at the left side of the
 116      *  border line for right to left orientation.
 117      */
 118     static public final int     TRAILING = 5;
 119 
 120     // Space between the border and the component's edge


 121     static protected final int EDGE_SPACING = 2;
 122 
 123     // Space between the border and text


 124     static protected final int TEXT_SPACING = 2;
 125 
 126     // Horizontal inset of text that is left or right justified


 127     static protected final int TEXT_INSET_H = 5;
 128 
 129     /**
 130      * Creates a TitledBorder instance.
 131      *
 132      * @param title  the title the border should display
 133      */
 134     public TitledBorder(String title) {
 135         this(null, title, LEADING, DEFAULT_POSITION, null, null);
 136     }
 137 
 138     /**
 139      * Creates a TitledBorder instance with the specified border
 140      * and an empty title.
 141      *
 142      * @param border  the border
 143      */
 144     public TitledBorder(Border border) {
 145         this(border, "", LEADING, DEFAULT_POSITION, null, null);
 146     }


 659                 return BOTTOM;
 660             }
 661             if (s.equalsIgnoreCase("BELOW_BOTTOM")) {
 662                 return BELOW_BOTTOM;
 663             }
 664         }
 665         return TOP;
 666     }
 667 
 668     private int getJustification(Component c) {
 669         int justification = getTitleJustification();
 670         if ((justification == LEADING) || (justification == DEFAULT_JUSTIFICATION)) {
 671             return c.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT;
 672         }
 673         if (justification == TRAILING) {
 674             return c.getComponentOrientation().isLeftToRight() ? RIGHT : LEFT;
 675         }
 676         return justification;
 677     }
 678 





 679     protected Font getFont(Component c) {
 680         Font font = getTitleFont();
 681         if (font != null) {
 682             return font;
 683         }
 684         if (c != null) {
 685             font = c.getFont();
 686             if (font != null) {
 687                 return font;
 688             }
 689         }
 690         return new Font(Font.DIALOG, Font.PLAIN, 12);
 691     }
 692 
 693     private Color getColor(Component c) {
 694         Color color = getTitleColor();
 695         if (color != null) {
 696             return color;
 697         }
 698         return (c != null)




  53  * <li>&quot;TitledBorder.border&quot;
  54  * <li>&quot;TitledBorder.font&quot;
  55  * <li>&quot;TitledBorder.titleColor&quot;
  56  * </ul>
  57  * <p>
  58  * <strong>Warning:</strong>
  59  * Serialized objects of this class will not be compatible with
  60  * future Swing releases. The current serialization support is
  61  * appropriate for short term storage or RMI between applications running
  62  * the same version of Swing.  As of 1.4, support for long term storage
  63  * of all JavaBeans&trade;
  64  * has been added to the <code>java.beans</code> package.
  65  * Please see {@link java.beans.XMLEncoder}.
  66  *
  67  * @author David Kloba
  68  * @author Amy Fowler
  69  */
  70 @SuppressWarnings("serial")
  71 public class TitledBorder extends AbstractBorder
  72 {
  73     /**
  74      * The title the border should display.
  75      */
  76     protected String title;
  77     /**
  78      * The border.
  79      */
  80     protected Border border;
  81     /**
  82      * The position for the title.
  83      */
  84     protected int titlePosition;
  85     /**
  86      * The justification for the title.
  87      */
  88     protected int titleJustification;
  89     /**
  90      * The font for rendering the title.
  91      */
  92     protected Font titleFont;
  93     /**
  94      * The color of the title.
  95      */
  96     protected Color titleColor;
  97 
  98     private final JLabel label;
  99 
 100     /**
 101      * Use the default vertical orientation for the title text.
 102      */
 103     static public final int     DEFAULT_POSITION        = 0;
 104     /** Position the title above the border's top line. */
 105     static public final int     ABOVE_TOP               = 1;
 106     /** Position the title in the middle of the border's top line. */
 107     static public final int     TOP                     = 2;
 108     /** Position the title below the border's top line. */
 109     static public final int     BELOW_TOP               = 3;
 110     /** Position the title above the border's bottom line. */
 111     static public final int     ABOVE_BOTTOM            = 4;
 112     /** Position the title in the middle of the border's bottom line. */
 113     static public final int     BOTTOM                  = 5;
 114     /** Position the title below the border's bottom line. */
 115     static public final int     BELOW_BOTTOM            = 6;


 118      * Use the default justification for the title text.
 119      */
 120     static public final int     DEFAULT_JUSTIFICATION   = 0;
 121     /** Position title text at the left side of the border line. */
 122     static public final int     LEFT                    = 1;
 123     /** Position title text in the center of the border line. */
 124     static public final int     CENTER                  = 2;
 125     /** Position title text at the right side of the border line. */
 126     static public final int     RIGHT                   = 3;
 127     /** Position title text at the left side of the border line
 128      *  for left to right orientation, at the right side of the
 129      *  border line for right to left orientation.
 130      */
 131     static public final int     LEADING = 4;
 132     /** Position title text at the right side of the border line
 133      *  for left to right orientation, at the left side of the
 134      *  border line for right to left orientation.
 135      */
 136     static public final int     TRAILING = 5;
 137 
 138     /**
 139      * Space between the border and the component's edge
 140      */
 141     static protected final int EDGE_SPACING = 2;
 142 
 143     /**
 144      * Space between the border and text
 145      */
 146     static protected final int TEXT_SPACING = 2;
 147 
 148     /**
 149      * Horizontal inset of text that is left or right justified
 150      */
 151     static protected final int TEXT_INSET_H = 5;
 152 
 153     /**
 154      * Creates a TitledBorder instance.
 155      *
 156      * @param title  the title the border should display
 157      */
 158     public TitledBorder(String title) {
 159         this(null, title, LEADING, DEFAULT_POSITION, null, null);
 160     }
 161 
 162     /**
 163      * Creates a TitledBorder instance with the specified border
 164      * and an empty title.
 165      *
 166      * @param border  the border
 167      */
 168     public TitledBorder(Border border) {
 169         this(border, "", LEADING, DEFAULT_POSITION, null, null);
 170     }


 683                 return BOTTOM;
 684             }
 685             if (s.equalsIgnoreCase("BELOW_BOTTOM")) {
 686                 return BELOW_BOTTOM;
 687             }
 688         }
 689         return TOP;
 690     }
 691 
 692     private int getJustification(Component c) {
 693         int justification = getTitleJustification();
 694         if ((justification == LEADING) || (justification == DEFAULT_JUSTIFICATION)) {
 695             return c.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT;
 696         }
 697         if (justification == TRAILING) {
 698             return c.getComponentOrientation().isLeftToRight() ? RIGHT : LEFT;
 699         }
 700         return justification;
 701     }
 702 
 703     /**
 704      * Returns the font of the component.
 705      * @return the font of the component
 706      * @param c the component
 707      */
 708     protected Font getFont(Component c) {
 709         Font font = getTitleFont();
 710         if (font != null) {
 711             return font;
 712         }
 713         if (c != null) {
 714             font = c.getFont();
 715             if (font != null) {
 716                 return font;
 717             }
 718         }
 719         return new Font(Font.DIALOG, Font.PLAIN, 12);
 720     }
 721 
 722     private Color getColor(Component c) {
 723         Color color = getTitleColor();
 724         if (color != null) {
 725             return color;
 726         }
 727         return (c != null)


< prev index next >