home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / Source.bin / BorderPanel.java < prev    next >
Encoding:
Java Source  |  1998-09-14  |  47.2 KB  |  1,605 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.beans.PropertyVetoException;
  6. import java.beans.PropertyChangeListener;
  7. import java.beans.VetoableChangeListener;
  8. import java.beans.PropertyChangeEvent;
  9. import symantec.itools.awt.util.ColorUtils;
  10. import java.awt.event.ContainerListener;
  11. import java.awt.event.ContainerEvent;
  12. import java.util.Vector;
  13. import java.util.ResourceBundle;
  14.  
  15. import java.lang.IllegalArgumentException;
  16.  
  17. //    01/29/97    TWB    Integrated changes from Macintosh
  18. //  05/31/97    RKM    Updated to support Java 1.1
  19. //                    Made properties bound & constrained
  20. //  07/19/97    LAB    Reorganized code to follow the GoodBeanSpec.  Updated deprecated
  21. //                    preferredSize and minimumSize calls. Made default protection
  22. //                    methods protected. Updated version to 1.1.
  23. //  07/20/97    RKM    Changed to new addImpl override, removed the five add variant overrides
  24. //  07/23/97    LAB    Constrained the BevelStyle property to only known styles.  Changed
  25. //                    setBorderColor(Color clr, boolean useForLabel) to throw a PropertyVetoException
  26. //                    as it should.  Updated to calculate the bevel raised and bevel lowered colors
  27. //                    from the background color.  Updated calls to reshape to setBounds.  Deprecated
  28. //                    reshape in favor of setBounds.
  29. //  07/25/97    CAR marked fields transient as needed
  30. //                  innerclasses implement java.io.Serialize
  31. //                  added back in null layout check in setLayout, without this check the bean throws an NullPointer
  32. //                  exception at instantiation time
  33. //  08/04/97    LAB    Now uses ColorUtils.calculateHilightColor and ColorUtils.calculateShadowColor
  34. //                    to calculate the bevel colors more intelligently.
  35. //    08/15/97    LAB    Reworked the way colors were calculated to avoid NullPointerExceptions,
  36. //                    and potential redraw problems.  Now colors are recalculated in paint,
  37. //                    if needed.
  38. //  08/29/97    CAR modified getPreferredSize and getMinimumSize
  39. //  09/01/97    CAR calls to add/removeContainerListener use the inner panel (which is considered the main container)
  40. //                  container events must appear to be generated by the outermost panel
  41. //    09/11/97    LAB    Added repaint call to setPaddingLeft, Right, Top, and Bottom, and added
  42. //                    a fillRect to draw() to fix some drawing artifacts (Addresses Mac Bug #7617).
  43. //                    Changed names of strings in PropertyChangeEvent handling to follow Bean Spec
  44. //                    naming conventions.
  45. //  10/20/97    CAR moved error messages into ResourceBundle
  46.  
  47. /**
  48.  * BorderPanel is a panel component that has an optional border
  49.  * and optional text title.
  50.  * @version 1.1, July 19, 1997
  51.  * @author Symantec
  52.  */
  53. public class BorderPanel extends Panel implements AlignStyle, BevelStyle, ContainerListener
  54. {
  55.     /**
  56.      * Constructs a new default BorderPanel.
  57.      * Its label will be ALIGN_CENTERED and it will have a BEVEL_LINE style border.
  58.      */
  59.     public BorderPanel()
  60.     {
  61.         this(null, ALIGN_CENTERED, BEVEL_LINE);
  62.     }
  63.  
  64.     /**
  65.      * Constructs a new BorderPanel with the specified beveled border style.
  66.      * It will have the ALIGN_CENTERED label alignment style.
  67.      * @param style the desired beveled border style
  68.      * @see BevelStyle#BEVEL_RAISED
  69.      * @see BevelStyle#BEVEL_LOWERED
  70.      * @see BevelStyle#BEVEL_LINE
  71.      * @see BevelStyle#BEVEL_NONE
  72.      */
  73.     public BorderPanel(int style)
  74.     {
  75.         this(null, ALIGN_CENTERED, style);
  76.     }
  77.  
  78.     /**
  79.      * Constructs a new BorderPanel with the specified border label.
  80.      * Its label will be ALIGN_CENTERED and it will have a BEVEL_LINE style border.
  81.      * @param s the label for the panel's border
  82.      */
  83.     public BorderPanel(String s)
  84.     {
  85.         this(s, ALIGN_CENTERED, BEVEL_LINE);
  86.     }
  87.  
  88.     /**
  89.      * Constructs a new BorderPanel with the specified border label
  90.      * and given alignment.
  91.      * @param s the label for the panel's border
  92.      * @param alignment the label alignment
  93.      * @see AlignStyle#ALIGN_LEFT
  94.      * @see AlignStyle#ALIGN_CENTERED
  95.      * @see AlignStyle#ALIGN_RIGHT
  96.      */
  97.     public BorderPanel(String s, int alignment)
  98.     {
  99.         this(s, alignment, BEVEL_LINE);
  100.     }
  101.  
  102.     /**
  103.      * Constructs a new BorderPanel with the specified border label
  104.      * and given alignment and border styles.
  105.      * @param s the label for the panel's border
  106.      * @param alignment the label alignment
  107.      * @param style the border bevel style
  108.      * @see AlignStyle#ALIGN_LEFT
  109.      * @see AlignStyle#ALIGN_CENTERED
  110.      * @see AlignStyle#ALIGN_RIGHT
  111.      * @see BevelStyle#BEVEL_RAISED
  112.      * @see BevelStyle#BEVEL_LOWERED
  113.      * @see BevelStyle#BEVEL_LINE
  114.      * @see BevelStyle#BEVEL_NONE
  115.      */
  116.     public BorderPanel(String s, int alignment, int style)
  117.     {
  118.         borderColor    = Color.black;
  119.         labelColor  = Color.black;
  120.         padleft     = 6;
  121.         padright    = 6;
  122.         padtop      = 10;
  123.         padbottom   = 6;
  124.         ixPad       = 4;
  125.         iyPadTop    = 2;
  126.         iyPadBottom = 7;
  127.  
  128.         cachedBackground = getBackground();
  129.  
  130.         label = (s != null && s.length() == 0) ? null : s;
  131.         labelAlignment = alignment;
  132.         internalInsets = new Insets(10, 10, 10, 10);
  133.         this.style     = style;
  134.         super.setLayout(null);
  135.         super.add(panel = new Panel());
  136.         if (panel != null)
  137.             panel.setLayout(null);
  138.         sizepanel(true);
  139.         cListeners = new Vector();
  140.     }
  141.  
  142.     /**
  143.      * Sets the top border outside padding amount, in pixels.
  144.      * This is the distance between the drawn border and the actual
  145.      * bounds of the component.
  146.      * @param newPadTop the top border outside padding amount, in pixels
  147.      * @exception PropertyVetoException
  148.      * if the specified property value is unacceptable
  149.      * @see #getPaddingTop
  150.      */
  151.     public void setPaddingTop(int newPadTop) throws PropertyVetoException
  152.     {
  153.         if (padtop != newPadTop)
  154.         {
  155.             Integer oldPadTopInt = new Integer(padtop);
  156.             Integer newPadTopInt = new Integer(newPadTop);
  157.  
  158.             vetos.fireVetoableChange("paddingTop", oldPadTopInt, newPadTopInt);
  159.  
  160.             padtop = newPadTop;
  161.             sizepanel(true);
  162.             invalidate();
  163.                repaint();
  164.  
  165.             changes.firePropertyChange("paddingTop", oldPadTopInt, newPadTopInt);
  166.         }
  167.     }
  168.  
  169.     /**
  170.      * Gets the current top border outside padding amount, in pixels.
  171.      * This is the distance between the drawn border and the actual
  172.      * bounds of the component.
  173.      * @return the top border outside padding amount, in pixels
  174.      * @see #setPaddingTop
  175.      */
  176.     public int getPaddingTop()
  177.     {
  178.         return padtop;
  179.     }
  180.  
  181.     /**
  182.      * Sets the bottom border outside padding amount, in pixels.
  183.      * This is the distance between the drawn border and the actual
  184.      * bounds of the component.
  185.      * @param newPadBottom the bottom border outside padding amount, in pixels
  186.      * @exception PropertyVetoException
  187.      * if the specified property value is unacceptable
  188.      * @see #getPaddingBottom
  189.      */
  190.     public void setPaddingBottom(int newPadBottom) throws PropertyVetoException
  191.     {
  192.         if (padbottom != newPadBottom)
  193.         {
  194.             Integer oldPadBottomInt = new Integer(padbottom);
  195.             Integer newPadBottomInt = new Integer(newPadBottom);
  196.  
  197.             vetos.fireVetoableChange("paddingBottom", oldPadBottomInt, newPadBottomInt);
  198.  
  199.             padbottom = newPadBottom;
  200.             sizepanel(true);
  201.             invalidate();
  202.             repaint();
  203.  
  204.             changes.firePropertyChange("paddingBottom", oldPadBottomInt, newPadBottomInt);
  205.         }
  206.     }
  207.  
  208.     /**
  209.      * Gets the current bottom border outside padding amount, in pixels.
  210.      * This is the distance between the drawn border and the actual
  211.      * bounds of the component.
  212.      * @return the bottom border outside padding amount, in pixels
  213.      * @see #setPaddingBottom
  214.      */
  215.     public int getPaddingBottom()
  216.     {
  217.         return padbottom;
  218.     }
  219.  
  220.     /**
  221.      * Sets the left border outside padding amount, in pixels.
  222.      * This is the distance between the drawn border and the actual
  223.      * bounds of the component.
  224.      * @param newPadLeft the left border outside padding amount, in pixels
  225.      * @exception PropertyVetoException
  226.      * if the specified property value is unacceptable
  227.      * @see #getPaddingLeft
  228.      */
  229.     public void setPaddingLeft(int newPadLeft) throws PropertyVetoException
  230.     {
  231.         if (padleft != newPadLeft)
  232.         {
  233.             Integer oldPadLeftInt = new Integer(padleft);
  234.             Integer newPadLeftInt = new Integer(newPadLeft);
  235.  
  236.             vetos.fireVetoableChange("paddingLeft", oldPadLeftInt, newPadLeftInt);
  237.  
  238.             padleft = newPadLeft;
  239.             sizepanel(true);
  240.             invalidate();
  241.             repaint();
  242.  
  243.             changes.firePropertyChange("paddingLeft", oldPadLeftInt, newPadLeftInt);
  244.         }
  245.     }
  246.  
  247.     /**
  248.      * Gets the current left border outside padding amount, in pixels.
  249.      * This is the distance between the drawn border and the actual
  250.      * bounds of the component.
  251.      * @return the left border outside padding amount, in pixels
  252.      * @see #setPaddingLeft
  253.      */
  254.     public int getPaddingLeft()
  255.     {
  256.         return padleft;
  257.     }
  258.  
  259.     /**
  260.      * Sets the right border outside padding amount, in pixels.
  261.      * This is the distance between the drawn border and the actual
  262.      * bounds of the component.
  263.      * @param newPadRight the right border outside padding amount, in pixels
  264.      * @exception PropertyVetoException
  265.      * if the specified property value is unacceptable
  266.      * @see #getPaddingRight
  267.      */
  268.     public void setPaddingRight(int newPadRight) throws PropertyVetoException
  269.     {
  270.         if (padright != newPadRight)
  271.         {
  272.             Integer oldPadRightInt = new Integer(padright);
  273.             Integer newPadRightInt = new Integer(newPadRight);
  274.  
  275.             vetos.fireVetoableChange("paddingRight", oldPadRightInt, newPadRightInt);
  276.  
  277.             padright = newPadRight;
  278.             sizepanel(true);
  279.             invalidate();
  280.             repaint();
  281.  
  282.             changes.firePropertyChange("paddingRight", oldPadRightInt, newPadRightInt);
  283.         }
  284.     }
  285.  
  286.     /**
  287.      * Gets the current right border outside padding amount, in pixels.
  288.      * This is the distance between the drawn border and the actual
  289.      * bounds of the component.
  290.      * @return the right border outside padding amount, in pixels
  291.      * @see #setPaddingRight
  292.      */
  293.     public int getPaddingRight()
  294.     {
  295.         return padright;
  296.     }
  297.  
  298.     /**
  299.      * Sets the top border inset padding amount, in pixels.
  300.      * This is the distance between the drawn border and the usable
  301.      * area within the border. It is used to determine the size of the
  302.      * panel contained within this component's borders.
  303.      * @param t top border inset padding amount
  304.      * @exception PropertyVetoException
  305.      * if the specified property value is unacceptable
  306.      * @see #getIPadTop
  307.      * @see #panel
  308.      */
  309.     public void setIPadTop(int t) throws PropertyVetoException
  310.     {
  311.         if (iyPadTop != t)
  312.         {
  313.             Integer oldPadTopInt = new Integer(iyPadTop);
  314.             Integer newPadTopInt = new Integer(t);
  315.  
  316.             vetos.fireVetoableChange("iPadTop", oldPadTopInt, newPadTopInt);
  317.  
  318.             iyPadTop = t;
  319.  
  320.             changes.firePropertyChange("iPadTop", oldPadTopInt, newPadTopInt);
  321.  
  322.             sizepanel(true);
  323.             invalidate();
  324.         }
  325.     }
  326.  
  327.     /**
  328.      * Gets the current top border inset padding amount, in pixels.
  329.      * This is the distance between the drawn border and the usable
  330.      * area within the border. It is used to determine the size of the
  331.      * panel contained within this component's borders.
  332.      * @return top border inset padding amount
  333.      * @see #setIPadTop
  334.      * @see #panel
  335.      */
  336.     public int getIPadTop()
  337.     {
  338.         return iyPadTop;
  339.     }
  340.  
  341.     /**
  342.      * Sets the bottom border inset padding amount, in pixels.
  343.      * This is the distance between the drawn border and the usable
  344.      * area within the border. It is used to determine the size of the
  345.      * panel contained within this component's borders.
  346.      * @param b bottom border inset padding amount
  347.      * @exception PropertyVetoException
  348.      * if the specified property value is unacceptable
  349.      * @see #getIPadBottom
  350.      * @see #panel
  351.      */
  352.     public void setIPadBottom(int b) throws PropertyVetoException
  353.     {
  354.         if (iyPadBottom != b)
  355.         {
  356.             Integer oldPadBottomInt = new Integer(iyPadBottom);
  357.             Integer newPadBottomInt = new Integer(b);
  358.  
  359.             vetos.fireVetoableChange("iPadBottom", oldPadBottomInt, newPadBottomInt);
  360.  
  361.             iyPadBottom = b;
  362.  
  363.             changes.firePropertyChange("iPadBottom", oldPadBottomInt, newPadBottomInt);
  364.  
  365.             sizepanel(true);
  366.             invalidate();
  367.         }
  368.     }
  369.  
  370.     /**
  371.      * Gets the current bottom border inset padding amount, in pixels.
  372.      * This is the distance between the drawn border and the usable
  373.      * area within the border. It is used to determine the size of the
  374.      * panel contained within this component's borders.
  375.      * @return bottom border inset padding amount
  376.      * @see #setIPadBottom
  377.      * @see #panel
  378.      */
  379.     public int getIPadBottom()
  380.     {
  381.         return iyPadBottom;
  382.     }
  383.  
  384.     /**
  385.      * Sets the side border inset padding amount, in pixels.
  386.      * This is the distance between the drawn border and the usable
  387.      * area within the border. It is used to determine the size of the
  388.      * panel contained within this component's borders.
  389.      * @param s side border inset padding amount
  390.      * @exception PropertyVetoException
  391.      * if the specified property value is unacceptable
  392.      * @see #getIPadSides
  393.      * @see #panel
  394.      */
  395.     public void setIPadSides(int s) throws PropertyVetoException
  396.     {
  397.         if (ixPad != s)
  398.         {
  399.             Integer oldIPadSidesInt = new Integer(ixPad);
  400.             Integer newIPadSidesInt = new Integer(s);
  401.  
  402.             vetos.fireVetoableChange("iPadSides", oldIPadSidesInt, newIPadSidesInt);
  403.  
  404.             ixPad = s;
  405.  
  406.             changes.firePropertyChange("iPadSides", oldIPadSidesInt, newIPadSidesInt);
  407.  
  408.             sizepanel(true);
  409.             invalidate();
  410.         }
  411.     }
  412.  
  413.     /**
  414.      * Gets the current side border inset padding amount, in pixels.
  415.      * This is the distance between the drawn border and the usable
  416.      * area within the border. It is used to determine the size of the
  417.      * panel contained within this component's borders.
  418.      * @return side border inset padding amount
  419.      * @see #setIPadSides
  420.      * @see #panel
  421.      */
  422.     public int getIPadSides()
  423.     {
  424.         return ixPad;
  425.     }
  426.  
  427.     /**
  428.      * Sets the text label to display in the border.
  429.      * @param newLabel the new border label.  If null, label is removed
  430.      * @exception PropertyVetoException
  431.      * if the specified property value is unacceptable
  432.      * @see #getLabel
  433.      */
  434.     public void setLabel(String newLabel) throws PropertyVetoException
  435.     {
  436.         //Preprocess s, since null is what instead of an empty string
  437.         if (newLabel != null && newLabel.length() == 0)
  438.             newLabel = null;
  439.  
  440.         if (!symantec.itools.util.GeneralUtils.objectsEqual(label,newLabel))
  441.         {
  442.             String oldLabel = label;
  443.  
  444.             vetos.fireVetoableChange("label", oldLabel, newLabel);
  445.  
  446.             label = newLabel;
  447.  
  448.             changes.firePropertyChange("label", oldLabel, newLabel);
  449.  
  450.             sizepanel(true);
  451.             //invalidate();
  452.             repaint();
  453.         }
  454.     }
  455.  
  456.     /**
  457.      * Returns the text label displayed in the border.
  458.      * @see #setLabel
  459.      */
  460.     public String getLabel()
  461.     {
  462.         return label;
  463.     }
  464.  
  465.     /**
  466.      * Sets the current border color.
  467.      * @param newBorderColor the new border color
  468.      * @exception PropertyVetoException
  469.      * if the specified property value is unacceptable
  470.      * @see #getBorderColor
  471.      */
  472.     public void setBorderColor(Color newBorderColor) throws PropertyVetoException
  473.     {
  474.         if (!symantec.itools.util.GeneralUtils.objectsEqual(borderColor,newBorderColor))
  475.         {
  476.             Color oldBorderColor = borderColor;
  477.  
  478.             vetos.fireVetoableChange("borderColor",oldBorderColor,newBorderColor);
  479.  
  480.             borderColor            = newBorderColor;
  481.  
  482.             changes.firePropertyChange("borderColor",oldBorderColor,newBorderColor);
  483.  
  484.             repaint();
  485.         }
  486.     }
  487.  
  488.     /**
  489.      * Gets the current border color.
  490.      * @return the current border color
  491.      * @see #setBorderColor
  492.      */
  493.     public Color getBorderColor()
  494.     {
  495.         return borderColor;
  496.     }
  497.  
  498.     /**
  499.      * Sets the border label color.
  500.      * @param newLabelBorderColor new border label color
  501.      * @exception PropertyVetoException
  502.      * if the specified property value is unacceptable
  503.      * @see #getLabelColor
  504.      */
  505.     public void setLabelColor(Color newLabelBorderColor) throws PropertyVetoException
  506.     {
  507.         if (!symantec.itools.util.GeneralUtils.objectsEqual(labelColor,newLabelBorderColor))
  508.         {
  509.             Color oldLabelColor = labelColor;
  510.  
  511.             vetos.fireVetoableChange("labelColor",oldLabelColor,newLabelBorderColor);
  512.  
  513.             labelColor = newLabelBorderColor;
  514.  
  515.             changes.firePropertyChange("labelColor",oldLabelColor,newLabelBorderColor);
  516.  
  517.             repaint();
  518.         }
  519.     }
  520.  
  521.     /**
  522.      * Gets the current border label color.
  523.      * @return current border label color
  524.      */
  525.     public Color getLabelColor()
  526.     {
  527.         return labelColor;
  528.     }
  529.  
  530.     /**
  531.      * Sets the border label alignment.
  532.      * @param alignment the new border label alignment.
  533.      * One of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT
  534.      * @exception PropertyVetoException
  535.      * if the specified property value is unacceptable
  536.      * @see #getAlignStyle
  537.      * @see AlignStyle#ALIGN_LEFT
  538.      * @see AlignStyle#ALIGN_CENTERED
  539.      * @see AlignStyle#ALIGN_RIGHT
  540.      */
  541.     public void setAlignStyle(int newLabelAlignment) throws PropertyVetoException
  542.     {
  543.         if (labelAlignment != newLabelAlignment)
  544.         {
  545.             Integer oldLabelAlignmentInteger = new Integer(labelAlignment);
  546.             Integer newLabelAlignmentInteger = new Integer(newLabelAlignment);
  547.  
  548.             vetos.fireVetoableChange("alignStyle",oldLabelAlignmentInteger,newLabelAlignmentInteger);
  549.  
  550.             labelAlignment = newLabelAlignment;
  551.  
  552.             changes.firePropertyChange("alignStyle",oldLabelAlignmentInteger,newLabelAlignmentInteger);
  553.  
  554.             sizepanel(true);
  555.             //invalidate();
  556.             repaint();
  557.         }
  558.     }
  559.  
  560.     /**
  561.      * Gets the current border label alignment.
  562.      * @return the current border label alignment.
  563.      * One of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT
  564.      * @see AlignStyle#ALIGN_LEFT
  565.      * @see AlignStyle#ALIGN_CENTERED
  566.      * @see AlignStyle#ALIGN_RIGHT
  567.      * @see #setAlignStyle
  568.      */
  569.     public int getAlignStyle()
  570.     {
  571.         return labelAlignment;
  572.     }
  573.  
  574.     /**
  575.      * Sets the border style.
  576.      * @param s the new border style.
  577.      * One of BEVEL_RAISED, BEVEL_LOWERED, BEVEL_LINE, or BEVEL_NONE
  578.      * @exception PropertyVetoException
  579.      * if the specified property value is unacceptable
  580.      * @see BevelStyle#BEVEL_RAISED
  581.      * @see BevelStyle#BEVEL_LOWERED
  582.      * @see BevelStyle#BEVEL_LINE
  583.      * @see BevelStyle#BEVEL_NONE
  584.      * @see #getBevelStyle
  585.      */
  586.     public void setBevelStyle(int newBevelStyle) throws PropertyVetoException
  587.     {
  588.         if (style != newBevelStyle)
  589.         {
  590.             Integer oldBevelStyleInteger = new Integer(style);
  591.             Integer newBevelStyleInteger = new Integer(newBevelStyle);
  592.  
  593.             vetos.fireVetoableChange("bevelStyle",oldBevelStyleInteger,newBevelStyleInteger);
  594.  
  595.             style = newBevelStyle;
  596.  
  597.             changes.firePropertyChange("bevelStyle",oldBevelStyleInteger,newBevelStyleInteger);
  598.  
  599.             repaint();
  600.         }
  601.     }
  602.  
  603.     /**
  604.      * Gets the current border style.
  605.      * @return current border style.
  606.      * One of BEVEL_RAISED, BEVEL_LOWERED, BEVEL_LINE, or BEVEL_NONE
  607.      * @see BevelStyle#BEVEL_RAISED
  608.      * @see BevelStyle#BEVEL_LOWERED
  609.      * @see BevelStyle#BEVEL_LINE
  610.      * @see BevelStyle#BEVEL_NONE
  611.      * @see #setBevelStyle
  612.      */
  613.     public int getBevelStyle()
  614.     {
  615.         return style;
  616.     }
  617.  
  618.     //???RKM??? Need JavaDoc here BUG: Was dup of getInternalInsets
  619.     /**
  620.      * Sets the internal border insets.
  621.      * The left and right fields of the internal insets are used while
  622.      * determining the preferred width of this component.
  623.      * @param newInsets the new internal border insets
  624.      * @exception PropertyVetoException
  625.      * if the specified property value is unacceptable
  626.      * @see #getInternalInsets
  627.      */
  628.     public void setInternalInsets(Insets newInsets) throws PropertyVetoException
  629.     {
  630.         if (!symantec.itools.util.GeneralUtils.objectsEqual(internalInsets,newInsets))
  631.         {
  632.             Insets oldInsets = internalInsets;
  633.  
  634.             vetos.fireVetoableChange("internalInsets",oldInsets,newInsets);
  635.  
  636.             internalInsets = newInsets;
  637.  
  638.             changes.firePropertyChange("internalInsets",oldInsets,newInsets);
  639.  
  640.             sizepanel(true);
  641.             invalidate();
  642.         }
  643.     }
  644.  
  645.     /**
  646.      * Gets the current internal border insets.
  647.      * The left and right fields of the internal insets are used while
  648.      * determining the preferred width of this component.
  649.      * @return the current internal border insets
  650.      * @see #setInternalInsets
  651.      */
  652.     public Insets getInternalInsets()
  653.     {
  654.         return internalInsets;
  655.     }
  656.  
  657.     /**
  658.      * Sets the border padding amounts.
  659.      * This are the distances between the drawn border and the actual
  660.      * bounds of the component.
  661.      * @param t the top padding amount
  662.      * @param b the bottom padding amount
  663.      * @param l the left padding amount
  664.      * @param r the right padding amount
  665.      * @exception PropertyVetoException
  666.      * if the specified property value is unacceptable
  667.      */
  668.     public void setPadding(int t, int b, int l, int r) throws PropertyVetoException
  669.     {
  670.         setPaddingTop(t);
  671.         setPaddingBottom(b);
  672.         setPaddingLeft(l);
  673.         setPaddingRight(r);
  674.     }
  675.  
  676.     /**
  677.      * @deprecated As of JDK version 1.1,
  678.      * replaced by setBorderColor & setLabelColor.
  679.      * @exception PropertyVetoException
  680.      * if the specified property value is unacceptable
  681.      * @see #setBorderColor(java.awt.Color)
  682.      * @see #setLabelColor(java.awt.Color)
  683.      */
  684.     public void setBorderColor(Color clr, boolean useForLabel) throws PropertyVetoException
  685.     {
  686.         setBorderColor(clr);
  687.  
  688.         if (useForLabel)
  689.         {
  690.             setLabelColor(clr);
  691.         }
  692.     }
  693.  
  694.     /**
  695.      * Returns the recommended dimensions to properly display this component.
  696.      * This is a standard Java AWT method which gets called to determine
  697.      * the recommended size of this component. The size returned is large
  698.      * enough to display the entire border label and the panel within the
  699.      * border.
  700.      *
  701.      * @see #minimumSize
  702.      */
  703.     public Dimension getPreferredSize()
  704.     {
  705.         Dimension p = size();
  706.         Dimension m = getMinimumSize();
  707.         return new Dimension(Math.max(p.width, m.width), Math.max(p.height, m.height));
  708.     }
  709.  
  710.     /**
  711.      * @deprecated
  712.      * @see #getPreferredSize
  713.      */
  714.     public Dimension preferredSize()
  715.     {
  716.         return getPreferredSize();
  717.     }
  718.  
  719.     /**
  720.      * Returns the minimum dimensions to properly display this component.
  721.      * This is a standard Java AWT method which gets called to determine
  722.      * the minimum size of this component.
  723.      *
  724.      * @see #getPreferredSize
  725.      */
  726.     public Dimension getMinimumSize()
  727.     {
  728.         return new Dimension(20, 40);
  729.     }
  730.  
  731.     /**
  732.      * @deprecated
  733.      * @see #getMinimumSize
  734.      */
  735.     public Dimension minimumSize()
  736.     {
  737.         return getMinimumSize();
  738.     }
  739.  
  740.     /**
  741.      * Sets the layout manager to be used to layout this container.
  742.      * This is a standard Java AWT method which gets called to specify
  743.      * which layout manager should be used to layout the components in
  744.      * standard containers.
  745.      *
  746.      * @param l the layout manager to use to layout this container's components
  747.      * @see #getLayout
  748.      **/
  749.     public void setLayout(LayoutManager l)
  750.     {
  751.         if (panel != null)
  752.         {
  753.             panel.setLayout(l);
  754.         }
  755.     }
  756.  
  757.     /**
  758.      * Gets the current border panel layout manager.
  759.      * @return current LayoutManager of border panel
  760.      * @see #setLayout
  761.      */
  762.     public LayoutManager getLayout()
  763.     {
  764.         return panel.getLayout();
  765.     }
  766.  
  767.     /**
  768.      * Gets the component at the specified zero-relative component index.
  769.      * This is a standard Java AWT method which gets called to return
  770.      * the component at a specific position.
  771.      *
  772.      * @param i the zero-relative index of the component to retrieve
  773.      * @return the component at the given index
  774.      * @exception java.lang.ArrayIndexOutOfBoundsException if the given
  775.      * component index does not exist
  776.      * @see #getComponents
  777.      */
  778.     public Component getComponent(int i)
  779.     {
  780.         return panel.getComponent(i);
  781.     }
  782.  
  783.     /**
  784.      * Returns all of the components in this container.
  785.      * This is a standard Java AWT method which gets called to return
  786.      * an array of all of the components in this container.
  787.      *
  788.      * @return an array of components in this container
  789.      * @see #getComponent
  790.      */
  791.     public Component[] getComponents()
  792.     {
  793.         return panel.getComponents();
  794.     }
  795.  
  796.     /**
  797.      * Returns the number of components in this container.
  798.      *
  799.      * @return the number of components in this container
  800.      * @see #getComponent
  801.      */
  802.     public int getComponentCount()
  803.     {
  804.         return panel.getComponentCount();
  805.     }
  806.  
  807.     /**
  808.      * Is the specified bevelStyle valid?
  809.      * @param bevelStyle the style to test
  810.      * @return if true then the parameter was equal to one of the following:
  811.      * @see BevelStyle#BEVEL_RAISED
  812.      * @see BevelStyle#BEVEL_LOWERED
  813.      * @see BevelStyle#BEVEL_LINE
  814.      * @see BevelStyle#BEVEL_NONE
  815.      */
  816.     public boolean isValidBevelStyle(int bevelStyle)
  817.     {
  818.         switch(bevelStyle)
  819.         {
  820.             case BEVEL_RAISED:
  821.             case BEVEL_LOWERED:
  822.             case BEVEL_LINE:
  823.             case BEVEL_NONE:
  824.                 return true;
  825.             default:
  826.                 return false;
  827.         }
  828.     }
  829.  
  830.     /**
  831.      * Tells this component that it has been added to a container.
  832.      * This is a standard Java AWT method which gets called by the AWT when
  833.      * this component is added to a container. Typically, it is used to
  834.      * create this component's peer.
  835.      *
  836.      * It has been overridden here to hook-up event listeners, and
  837.      * to resize self after peer created.
  838.      *
  839.      * @see #removeNotify
  840.      */
  841.     public synchronized void addNotify()
  842.     {
  843.         super.addNotify();
  844.         
  845.         try
  846.         {
  847.             errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
  848.         }
  849.         catch(Throwable ex)
  850.         {
  851.             errors = new symantec.itools.resources.ErrorsBundle();
  852.         }
  853.  
  854.         sizepanel(true);
  855.  
  856.         //Hook up listeners
  857.         if (veto == null)
  858.         {
  859.             veto = new Veto();
  860.             addBevelStyleListener(veto);
  861.         }
  862.  
  863.         if (panel != null)
  864.             panel.addContainerListener(this);
  865.     }
  866.  
  867.     /**
  868.      * Tells this component that it is being removed from a container.
  869.      * This is a standard Java AWT method which gets called by the AWT when
  870.      * this component is removed from a container. Typically, it is used to
  871.      * destroy the peers of this component and all its subcomponents.
  872.      *
  873.      * It has been overridden here to unhook event listeners.
  874.      *
  875.      * @see #addNotify
  876.      */
  877.     public synchronized void removeNotify()
  878.     {
  879.         //Unhook listeners
  880.         if (veto != null)
  881.         {
  882.             removeBevelStyleListener(veto);
  883.             veto = null;
  884.         }
  885.  
  886.         if (panel != null)
  887.             panel.removeContainerListener(this);
  888.  
  889.         super.removeNotify();
  890.     }
  891.  
  892.     /**
  893.      * Handles the laying out of components within this component.
  894.      * This is a standard Java AWT method which gets called by the AWT
  895.      * when this component is validated with the validate() method.
  896.      *
  897.      * @see java.awt.Container#validate
  898.      */
  899.     public void layout()
  900.     {
  901.         sizepanel(false);
  902.         panel.layout();
  903.     }
  904.  
  905.     /**
  906.      * Adds the specified component to this container at the specified
  907.      * index.  Also notifies the layout manager to add the component to
  908.      * the this container's layout using the specified constraints object.
  909.      * <p>
  910.      * This is the method to override if you want to track every add
  911.      * request to a container.  An overriding method should usually
  912.      * include a call to super.addImpl(comp, constraints, index).
  913.      *
  914.      * BorderPanel overrides this method to send all additions to it to\
  915.      * its internal panel
  916.      *
  917.      * @param comp the component to be added
  918.      * @param constraints an object expressing layout contraints for this
  919.      * component
  920.      * @param index the position in the container's list at which to
  921.      * insert the component.  -1 means insert at the end.
  922.      * @see #remove
  923.      * @see LayoutManager
  924.      */
  925.     protected void addImpl(Component comp, Object constraints, int index)
  926.     {
  927.         if (comp == panel)
  928.             super.addImpl(comp,constraints,index);
  929.         else
  930.             panel.add(comp,constraints,index);
  931.     }
  932.  
  933.     /**
  934.      * Removes the component at the specified index from this container.
  935.      * @param index the index of the component to be removed
  936.      * @see java.awt.Container#add
  937.      */
  938.     public void remove(int index)
  939.     {
  940.         panel.remove(index);
  941.     }
  942.  
  943.     public void remove(Component comp)
  944.     {
  945.         panel.remove(comp);
  946.     }
  947.  
  948.     /**
  949.      * Removes all the components from this container.
  950.      * This is a standard Java AWT method which gets called to remove all
  951.      * the components from a container. When this happens each component's
  952.      * removeNotify() will also get called to indicate component removal.
  953.      *
  954.      * @see #remove
  955.      * @see java.awt.Container#add
  956.      */
  957.     public void removeAll()
  958.     {
  959.         panel.removeAll();
  960.     }
  961.  
  962.     /**
  963.      * Moves and/or resizes this component.
  964.      * This is a standard Java AWT method which gets called to move and/or
  965.      * resize this component. Components that are in containers with layout
  966.      * managers should not call this method, but rely on the layout manager
  967.      * instead.
  968.      *
  969.      * @param x horizontal position in the parent's coordinate space
  970.      * @param y vertical position in the parent's coordinate space
  971.      * @param width the new width
  972.      * @param height the new height
  973.      */
  974.     public void setBounds(int x, int y, int width, int height)
  975.     {
  976.         super.setBounds(x, y, width, height);
  977.         sizepanel(false);
  978.     }
  979.  
  980.     /**
  981.      * @deprecated
  982.      * @see #setBounds
  983.      */
  984.     public void reshape(int x, int y, int width, int height)
  985.     {
  986.         //Can not call setBounds here, or we would be in an endless loop because of the AWT.
  987.         super.reshape(x, y, width, height);
  988.         sizepanel(false);
  989.     }
  990.  
  991.     /**
  992.      * Handles redrawing of this component on the screen.
  993.      * This is a standard Java AWT method which gets called by the Java
  994.      * AWT (repaint()) to handle repainting this component on the screen.
  995.      * The graphics context clipping region is set to the bounding rectangle
  996.      * of this component and its [0,0] coordinate is this component's
  997.      * top-left corner.
  998.      * Typically this method paints the background color to clear the
  999.      * component's drawing space, sets graphics context to be the foreground
  1000.      * color, and then calls paint() to draw the component.
  1001.      *
  1002.      * @param g the graphics context
  1003.      * @see java.awt.Component#repaint
  1004.      * @see #paint
  1005.      */
  1006.     public void update(Graphics g)
  1007.     {
  1008.         Dimension s;
  1009.         Insets insets;
  1010.  
  1011.         s      = size();
  1012.         insets = insets();
  1013.  
  1014.         //??? LAB ??? What is all this doing?  Doesn't seem to apply.
  1015.         g.setColor(getBackground());
  1016.  
  1017.         if (insets.left > 0)
  1018.         {
  1019.             g.fillRect(0, 0, insets.left, s.height);
  1020.         }
  1021.  
  1022.         if (insets.top > 0)
  1023.         {
  1024.             g.fillRect(0, 0, s.width, insets.top);
  1025.         }
  1026.  
  1027.         if (insets.bottom > 0)
  1028.         {
  1029.             g.fillRect(0, s.height-insets.bottom, s.width, insets.bottom);
  1030.         }
  1031.  
  1032.         if (insets.right > 0)
  1033.         {
  1034.             g.fillRect(s.width-insets.right, 0, insets.right, s.height);
  1035.         }
  1036.  
  1037.         paint(g);
  1038.         panel.repaint();
  1039.     }
  1040.  
  1041.     /**
  1042.      * Returns the number of components in this container.
  1043.      * This is a standard Java AWT method which gets called to return a count
  1044.      * of the components within this container.
  1045.      *
  1046.      */
  1047.     public int countComponents()
  1048.     {
  1049.         return panel.countComponents();
  1050.     }
  1051.  
  1052.     /**
  1053.      * Returns the amount of space used by the current border.
  1054.      * This is a standard Java AWT method which gets called to determine
  1055.      * the size of the current border. The returned value is the width
  1056.      * of each border side in pixels.
  1057.      *
  1058.      * @return the current border insets
  1059.      */
  1060.     public Insets insets()
  1061.     {
  1062.         int h = getLabelTopMargin();
  1063.         Insets insets = getInternalInsets();
  1064.  
  1065.         return new Insets(h + insets.top, insets.left, insets.bottom, insets.right);
  1066.     }
  1067.  
  1068.     /**
  1069.      * Paints this component using the given graphics context.
  1070.      * This is a standard Java AWT method which typically gets called
  1071.      * by the AWT to handle painting this component. It paints this component
  1072.      * using the given graphics context. The graphics context clipping region
  1073.      * is set to the bounding rectangle of this component and its [0,0]
  1074.      * coordinate is this component's top-left corner.
  1075.      *
  1076.      * @param g the graphics context used for painting
  1077.      * @see java.awt.Component#repaint
  1078.      * @see #update
  1079.      */
  1080.     public void paint(Graphics g)
  1081.     {
  1082.         sizepanel(false);
  1083.         Color curBackground = getBackground();
  1084.         if (!symantec.itools.util.GeneralUtils.objectsEqual(curBackground, cachedBackground))
  1085.         {
  1086.             cachedBackground = curBackground;
  1087.             calculateHilightColors(curBackground);
  1088.         }
  1089.         g.setColor(curBackground);
  1090.         draw(g);
  1091.     }
  1092.  
  1093.     /**
  1094.      * Sets this component's background color.
  1095.      * This is a standard Java AWT method which gets called to change
  1096.      * the background color of this component.
  1097.      *
  1098.      * @param c the new background color
  1099.      * @see java.awt.Component#getBackground
  1100.      */
  1101.     public void setBackground(Color c)
  1102.     {
  1103.         super.setBackground(c);
  1104.         panel.setBackground(c);
  1105.     }
  1106.  
  1107.     public void componentAdded(ContainerEvent e) {
  1108.         if (e.getSource() == panel) {
  1109.             for (int i = 0; i < cListeners.size(); ++i) {
  1110.                 ((ContainerListener) cListeners.elementAt(i)).componentAdded(
  1111.                     new ContainerEvent(this, ContainerEvent.COMPONENT_ADDED, e.getChild()));
  1112.             }
  1113.         }
  1114.     }
  1115.  
  1116.     public void componentRemoved(ContainerEvent e) {
  1117.         if (e.getSource() == panel) {
  1118.             for (int i = 0; i < cListeners.size(); ++i) {
  1119.                 ((ContainerListener) cListeners.elementAt(i)).componentRemoved(
  1120.                     new ContainerEvent(this, ContainerEvent.COMPONENT_REMOVED, e.getChild()));
  1121.             }
  1122.         }
  1123.     }
  1124.  
  1125.     public synchronized void addContainerListener(ContainerListener l) {
  1126.         if (panel != null) {
  1127.             panel.addContainerListener(l);
  1128.             cListeners.addElement(l);
  1129.         }
  1130.     }
  1131.  
  1132.     public synchronized void removeContainerListener(ContainerListener l) {
  1133.         if (panel != null) {
  1134.             panel.removeContainerListener(l);
  1135.             cListeners.removeElement(l);
  1136.         }
  1137.     }
  1138.  
  1139.     /**
  1140.      * Adds a listener for all event changes.
  1141.      * @param listener the listener to add.
  1142.      * @see #removePropertyChangeListener
  1143.      */
  1144.     public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
  1145.     {
  1146.         //super.addPropertyChangeListener(listener);
  1147.         changes.addPropertyChangeListener(listener);
  1148.     }
  1149.  
  1150.     /**
  1151.      * Removes a listener for all event changes.
  1152.      * @param listener the listener to remove.
  1153.      * @see #addPropertyChangeListener
  1154.      */
  1155.     public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
  1156.     {
  1157.         //super.removePropertyChangeListener(listener);
  1158.         changes.removePropertyChangeListener(listener);
  1159.     }
  1160.  
  1161.     /**
  1162.      * Adds a vetoable listener for all event changes.
  1163.      * @param listener the listener to add.
  1164.      * @see #removeVetoableChangeListener
  1165.      */
  1166.     public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
  1167.     {
  1168.          //super.addVetoableChangeListener(listener);
  1169.         vetos.addVetoableChangeListener(listener);
  1170.     }
  1171.  
  1172.     /**
  1173.      * Removes a vetoable listener for all event changes.
  1174.      * @param listener the listener to remove.
  1175.      * @see #addVetoableChangeListener
  1176.      */
  1177.     public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
  1178.     {
  1179.         //super.removeVetoableChangeListener(listener);
  1180.         vetos.removeVetoableChangeListener(listener);
  1181.     }
  1182.  
  1183.     /**
  1184.      * Adds a listener for Orienation changes.
  1185.      * @param listener the listener to add.
  1186.      * @see #removeBevelStyleListener
  1187.      */
  1188.     public synchronized void addBevelStyleListener(PropertyChangeListener listener)
  1189.     {
  1190.         changes.addPropertyChangeListener("bevelStyle", listener);
  1191.     }
  1192.  
  1193.     /**
  1194.      * Removes a listener for Orienation changes.
  1195.      * @param listener the listener to remove.
  1196.      * @see #addBevelStyleListener
  1197.      */
  1198.     public synchronized void removeBevelStyleListener(PropertyChangeListener listener)
  1199.     {
  1200.         changes.removePropertyChangeListener("bevelStyle", listener);
  1201.     }
  1202.  
  1203.     /**
  1204.      * Adds a vetoable listener for BevelStyle changes.
  1205.      * @param listener the listener to add.
  1206.      * @see #removeBevelStyleListener
  1207.      */
  1208.     public synchronized void addBevelStyleListener(VetoableChangeListener listener)
  1209.     {
  1210.         vetos.addVetoableChangeListener("bevelStyle", listener);
  1211.     }
  1212.  
  1213.     /**
  1214.      * Removes a vetoable listener for BevelStyle changes.
  1215.      * @param listener the listener to remove.
  1216.      * @see #addBevelStyleListener
  1217.      */
  1218.     public synchronized void removeBevelStyleListener(VetoableChangeListener listener)
  1219.     {
  1220.         vetos.removeVetoableChangeListener("bevelStyle", listener);
  1221.     }
  1222.  
  1223.     /**
  1224.      * This is the PropertyChangeEvent handling inner class for the constrained BevelStyle property.
  1225.      * Handles vetoing BevelStyles that are not valid.
  1226.      */
  1227.     class Veto implements java.beans.VetoableChangeListener, java.io.Serializable
  1228.     {
  1229.         /**
  1230.          * This method gets called when an attempt to change the constrained BevelStyle property is made.
  1231.          * Ensures the given Orientation is valid.
  1232.          *
  1233.          * @param     e a <code>PropertyChangeEvent</code> object describing the
  1234.          *             event source and the property that has changed.
  1235.          * @exception PropertyVetoException if the recipient wishes the property
  1236.          *              change to be rolled back.
  1237.          */
  1238.         public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
  1239.         {
  1240.             int i = ((Integer)e.getNewValue()).intValue();
  1241.             if (!isValidBevelStyle(i))
  1242.             {
  1243.                 throw new PropertyVetoException(errors.getString("InvalidBevelStyle") + i, e);
  1244.             }
  1245.         }
  1246.     }
  1247.  
  1248.     /**
  1249.      * Sizes the border panel from the padding, inset, and label margin information.
  1250.      * @param force force setBounds even if the overall size hasn't changed
  1251.      */
  1252.     protected void sizepanel(boolean force)
  1253.     {
  1254.         Dimension s;
  1255.  
  1256.         s = size();
  1257.  
  1258.         if (force || oldSize.width != s.width || oldSize.height != s.height)
  1259.         {
  1260.             oldSize = s;
  1261.             panel.setBounds(padleft + ixPad,
  1262.                   getLabelTopMargin() + iyPadTop,
  1263.                   s.width - padright - padleft - ixPad * 2 - 1,
  1264.                   s.height - padbottom - getLabelTopMargin() - iyPadBottom - iyPadTop - 1);
  1265.         }
  1266.     }
  1267.  
  1268.     /**
  1269.      * Draws the border panel.
  1270.      * @param g current graphics object
  1271.      */
  1272.     protected void draw(Graphics g)
  1273.     {
  1274.         Dimension s;
  1275.         int delta;
  1276.         FontMetrics fm;
  1277.         int x;
  1278.         int y;
  1279.         int w;
  1280.         int h;
  1281.  
  1282.         s = size();
  1283.         delta = padtop;
  1284.         fm = getFontMetrics(getFont());
  1285.  
  1286.         g.clipRect(0, 0, s.width, s.height);
  1287.         //Erase our background.
  1288.         g.fillRect(0, 0, s.width, s.height);
  1289.  
  1290.         if (label != null && fm != null)
  1291.         {
  1292.             delta = (fm.getAscent()  + fm.getDescent() + padtop) / 2;
  1293.         }
  1294.  
  1295.         x = padleft;
  1296.         y = delta;
  1297.         w = s.width - padleft - padright - 1;
  1298.         h = s.height - 1 - delta - padbottom;
  1299.  
  1300.         drawBorder(g, x, y, w, h);
  1301.  
  1302.         drawLabel(g, fm);
  1303.     }
  1304.  
  1305.     /**
  1306.      * Draws the border panel border.
  1307.      * @param g current graphics object
  1308.      * @param x x coordinate of panel object
  1309.      * @param y y coordinate of panel object
  1310.      * @param w w width of panel object
  1311.      * @param h h height of panel object
  1312.      */
  1313.     protected void drawBorder(Graphics g, int x, int y, int w, int h)
  1314.     {
  1315.         switch(style)
  1316.         {
  1317.             case BEVEL_RAISED :
  1318.             {
  1319.                 g.setColor(bevelLighterColor);
  1320.                 g.drawLine(x, y, x + w, y);
  1321.                 g.drawLine(x, y, x, y + h);
  1322.                 g.setColor(bevelDarkerColor);
  1323.                 g.drawLine(x, y + h, x + w, y + h);
  1324.                 g.drawLine(x + w, y, x + w, y + h);
  1325.                 break;
  1326.             }
  1327.             case BEVEL_LOWERED :
  1328.             {
  1329.                 g.setColor(bevelDarkerColor);
  1330.                 g.drawLine(x, y, x + w, y);
  1331.                 g.drawLine(x, y, x, y + h);
  1332.                 g.setColor(bevelLighterColor);
  1333.                 g.drawLine(x, y + h, x + w, y + h);
  1334.                 g.drawLine(x + w, y, x + w, y + h);
  1335.                 break;
  1336.             }
  1337.             case BEVEL_NONE :
  1338.             {
  1339.                 break;
  1340.             }
  1341.             case BEVEL_LINE :
  1342.             {
  1343.                 g.setColor(borderColor);
  1344.                 g.drawRect(x, y, w, h);
  1345.                 break;
  1346.             }
  1347.             default:
  1348.             {
  1349.                 g.setColor(borderColor);
  1350.                 g.drawRect(x, y, w, h);
  1351.                 break;
  1352.             }
  1353.         }
  1354.     }
  1355.  
  1356.     /**
  1357.      * Draws the border panel label.
  1358.      * @param g current graphics object
  1359.      * @param fm FontMetrics of border panel label
  1360.      */
  1361.     protected void drawLabel(Graphics g, FontMetrics fm)
  1362.     {
  1363.         if (label != null && (fm != null))
  1364.         {
  1365.             int fWidth;
  1366.             Dimension s;
  1367.             int stringWidth;
  1368.             int ascent;
  1369.             int descent;
  1370.             int x;
  1371.             int y;
  1372.             int h;
  1373.  
  1374.             fWidth = 10;
  1375.             s = size();
  1376.  
  1377.             if (getFont().getSize() > fWidth)
  1378.             {
  1379.                 fWidth = fWidth + getFont().getSize() / 2;
  1380.             }
  1381.  
  1382.             stringWidth = fm.stringWidth(label);
  1383.             ascent      = fm.getAscent();
  1384.             descent     = fm.getDescent();
  1385.  
  1386.             switch(labelAlignment)
  1387.             {
  1388.                 case Label.CENTER:
  1389.                 {
  1390.                     x = (s.width - stringWidth) / 2;
  1391.                     break;
  1392.                 }
  1393.                 case Label.RIGHT:
  1394.                 {
  1395.                     x = s.width - fWidth - (stringWidth + (labelpadx + labelipadx) / 2);
  1396.                     break;
  1397.                 }
  1398.                 case Label.LEFT:
  1399.                 {
  1400.                 }
  1401.                 default:
  1402.                 {
  1403.                     x = fWidth + (labelpadx + labelipadx) / 2;
  1404.                 }
  1405.             }
  1406.  
  1407.             //y = ascent + padtop;            //This line is useless. 12/17/96 Levi Brown
  1408.             h = ascent + descent+padtop;
  1409.  
  1410.             y = (fWidth - h) / 2 + (padtop + ascent);
  1411.             //h = fWidth;                    //I like h better before... 12/17/96 Levi Brown
  1412.  
  1413.             g.setColor(getBackground());
  1414.             //Commented out the line below, to add my own below it.  12/17/96 Levi Brown
  1415.             //g.fillRect(x - labelipadx / 2, 0, stringWidth + labelipadx, h);
  1416.             g.fillRect(x - labelipadx / 2, y - 1 - ascent - padtop/2, stringWidth + labelipadx, h);
  1417.             g.setColor(labelColor);
  1418.             g.drawString(label, x, y - 1);
  1419.         }
  1420.     }
  1421.  
  1422.     /**
  1423.      * Returns the current margin above the label.
  1424.      */
  1425.     protected int getLabelTopMargin()
  1426.     {
  1427.         int  top;
  1428.         Font font;
  1429.  
  1430.         if (label == null)
  1431.         {
  1432.             return padtop;
  1433.         }
  1434.  
  1435.         top  = padtop;
  1436.         font = getFont();
  1437.  
  1438.         if (font != null)
  1439.         {
  1440.             FontMetrics fm;
  1441.  
  1442.             fm  = getFontMetrics(font);
  1443.             top = fm.getAscent() + fm.getDescent() + padtop + 0;
  1444.         }
  1445.  
  1446.         return top;
  1447.     }
  1448.  
  1449.     /**
  1450.      * Returns the current label width margin.
  1451.      */
  1452.     protected int getLabelWidthMargin()
  1453.     {
  1454.         if (label == null)
  1455.         {
  1456.             return 0;
  1457.         }
  1458.  
  1459.         int w;
  1460.         Font font;
  1461.  
  1462.         w = 2 + internalInsets.left + internalInsets.right;
  1463.         font = getFont();
  1464.  
  1465.         if (font != null)
  1466.         {
  1467.             FontMetrics fm;
  1468.  
  1469.             fm = getFontMetrics(font);
  1470.             w  = Math.max(w, 2 + fm.stringWidth(label) + labelpadx + labelipadx);
  1471.         }
  1472.  
  1473.         return w;
  1474.     }
  1475.  
  1476.     /**
  1477.      * Used to calculate the hilight colors from the background color.
  1478.      * @see #paint
  1479.      */
  1480.     protected void calculateHilightColors(Color c)
  1481.     {
  1482.         bevelLighterColor    = ColorUtils.calculateHilightColor(c);
  1483.         bevelDarkerColor    = ColorUtils.calculateShadowColor(c);
  1484.     }
  1485.  
  1486.     /**
  1487.      * The overall size before sizepanel().
  1488.      */
  1489.     Dimension oldSize = new Dimension();
  1490.  
  1491.     /**
  1492.      * Label horizontal coordinate padding constant, in pixels.
  1493.      */
  1494.     protected static final int labelpadx = 10;
  1495.     /**
  1496.      * Label horizontal coordinate inset constant, in pixels.
  1497.      */
  1498.     protected static final int labelipadx = 4;
  1499.  
  1500.     /**
  1501.      * Cached value of the background color.  Used to determine if calculated colors need to be updated.
  1502.      */
  1503.     protected Color cachedBackground    = null;
  1504.     /**
  1505.      * The border color.
  1506.      */
  1507.     protected Color borderColor;
  1508.     /**
  1509.      * The color to use as a hilight when BevelStyle is BEVEL_RAISED or BEVEL_LOWERED.
  1510.      */
  1511.     protected Color bevelLighterColor;
  1512.     /**
  1513.      * The color to use as a hilight when BevelStyle is BEVEL_RAISED or BEVEL_LOWERED.
  1514.      */
  1515.     protected Color bevelDarkerColor;
  1516.     /**
  1517.      * The border label color.
  1518.      */
  1519.     protected Color labelColor;
  1520.     /**
  1521.      * The top border outside padding amount, in pixels.
  1522.      * This is the distance between the drawn border and the actual
  1523.      * bounds of the component.
  1524.      */
  1525.     protected int padtop;
  1526.     /**
  1527.      * The bottom border outside padding amount, in pixels.
  1528.      * This is the distance between the drawn border and the actual
  1529.      * bounds of the component.
  1530.      */
  1531.     protected int padbottom;
  1532.     /**
  1533.      * The left border outside padding amount, in pixels.
  1534.      * This is the distance between the drawn border and the actual
  1535.      * bounds of the component.
  1536.      */
  1537.     protected int padleft;
  1538.     /**
  1539.      * The right border outside padding amount, in pixels.
  1540.      * This is the distance between the drawn border and the actual
  1541.      * bounds of the component.
  1542.      */
  1543.     protected int padright;
  1544.     /**
  1545.      * The side border inset padding amount, in pixels.
  1546.      * This is the distance between the drawn border and the usable
  1547.      * area within the border. It is used to determine the size of the
  1548.      * panel contained within this component's borders.
  1549.      * @see #panel
  1550.      */
  1551.     protected int ixPad;
  1552.     /**
  1553.      * The top border inset padding amount, in pixels.
  1554.      * This is the distance between the drawn border and the usable
  1555.      * area within the border. It is used to determine the size of the
  1556.      * panel contained within this component's borders.
  1557.      * @see #panel
  1558.      */
  1559.     protected int iyPadTop;
  1560.     /**
  1561.      * The bottom border inset padding amount, in pixels.
  1562.      * This is the distance between the drawn border and the usable
  1563.      * area within the border. It is used to determine the size of the
  1564.      * panel contained within this component's borders.
  1565.      * @see #panel
  1566.      */
  1567.     protected int iyPadBottom;
  1568.     /**
  1569.      * The border style: BEVEL_RAISED, BEVEL_LOWERED, BEVEL_LINE, or BEVEL_NONE.
  1570.      * @see BevelStyle#BEVEL_RAISED
  1571.      * @see BevelStyle#BEVEL_LOWERED
  1572.      * @see BevelStyle#BEVEL_LINE
  1573.      * @see BevelStyle#BEVEL_NONE
  1574.      */
  1575.     protected int style;
  1576.     /**
  1577.      * The text label to display in the border.
  1578.      */
  1579.     protected String label;
  1580.     /**
  1581.      * The border label alignment: ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT.
  1582.      * @see AlignStyle#ALIGN_LEFT
  1583.      * @see AlignStyle#ALIGN_CENTERED
  1584.      * @see AlignStyle#ALIGN_RIGHT
  1585.      */
  1586.     protected int labelAlignment;
  1587.     /**
  1588.      * The internal border insets.
  1589.      * The left and right fields are used while determining the preferred
  1590.      * width of this component.
  1591.      */
  1592.     protected Insets internalInsets;
  1593.     /**
  1594.      * The panel within the border. This is the panel that contains the
  1595.      * components added to the BorderPanel.
  1596.      */
  1597.     protected Panel panel;
  1598.     transient protected ResourceBundle errors;
  1599.  
  1600.     private Vector cListeners = null;
  1601.     private Veto veto = null;
  1602.     private symantec.itools.beans.VetoableChangeSupport vetos = new symantec.itools.beans.VetoableChangeSupport(this);
  1603.     private symantec.itools.beans.PropertyChangeSupport changes = new symantec.itools.beans.PropertyChangeSupport(this);
  1604. }
  1605.