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 / DirectionButton.java < prev    next >
Encoding:
Java Source  |  1998-09-14  |  23.8 KB  |  772 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Rectangle;
  4. import java.awt.Dimension;
  5. import java.awt.Color;
  6. import java.awt.Graphics;
  7. import java.beans.PropertyVetoException;
  8. import java.beans.PropertyChangeListener;
  9. import java.beans.VetoableChangeListener;
  10. import java.beans.PropertyChangeEvent;
  11. import java.lang.IllegalArgumentException;
  12. import symantec.itools.awt.util.ColorUtils;
  13. import java.util.ResourceBundle;
  14.  
  15. //    01/29/97    TWB    Integrated changes from Windows
  16. //    05/23/97    LAB    Updated to support Java 1.1
  17. //    06/27/97    LAB    Changed the way the button is drawn.  Now it uses the offscreen
  18. //                    Image.  Cleaned up the drawing code to be more universal.
  19. //                    Added the ArrowColor property to allow the arrow to have a
  20. //                    user definable color.  The disabled color is derived from this color.
  21. //    07/02/97    LAB    Constrained the Arrow Indent Property, so the arrow wouldn't draw strangely
  22. //                    if the inset was set to a large value.
  23. //    07/08/97    LAB    Changed the preferedSize() method to return a button whose arrow is 20 by 20.
  24. //    07/13/97    RKM    Fixed misspelling of prefered
  25. //    07/19/97    LAB    Replaced updatePolygon with fillTriangle and changed the drawing method from
  26. //                    using a polygon to using lines because polygons were problematic.  Changed
  27. //                    getPreferredSize to return the smallest size which the button looks good and
  28. //                    changed getMinimumSize to return the smallest possible size for the button and
  29. //                    still be recognized as a DirectionButton.
  30. //  07/25/97    CAR marked fields transient as needed
  31. //                  innerclasses implement java.io.Serializable
  32. //    10/05/97    LAB    Changed names of strings in PropertyChangeEvent handling to follow Bean Spec
  33. //                    naming conventions.  Added mechanism for internally constrained properties
  34. //                    to be validated after the component is added to the form to avoid code-gen
  35. //                    order specific dependencies.
  36. //    10/06/97    LAB    Initialized tempIndent to indent which resolves shrinkTriangle
  37. //                    and setArrowIndent conflicts (Addresses Mac Bug #9014).  Changed
  38. //                    addNotify to call it's super after listeners are hooked up so
  39. //                    verifyContstrainedPropertyValues will be called after the listeners
  40. //                    are hooked up.  Changed setArrowIndent to set the temp value to the
  41. //                    current value when changing the current value.  Changed
  42. //                    getBevelHeight to return the temp value if the component is not
  43. //                    added.  This fixes a problem at design time where the component would
  44. //                    revert to it's default state after a back run
  45.  
  46. /**
  47.  * The DirectionButton is a button component that has an arrow drawn in it that
  48.  * points one of four ways (left, up, right, or down). At runtime, the button has
  49.  * a raised look and a pressed look.
  50.  * <p>
  51.  * This component is usually used in conjunction with a combo or list box to
  52.  * indicate a list that the user can view by clicking the arrow, or with spinners
  53.  * to let the user scroll through available values.
  54.  * <p>
  55.  * @version 1.1, June 27, 1997
  56.  * @author  Symantec
  57.  */
  58. public class DirectionButton extends ButtonBase implements java.io.Serializable
  59. {
  60.     /**
  61.      * The point LEFT style constant.
  62.      */
  63.     public static final int LEFT = 0;
  64.  
  65.     /**
  66.      * The point RIGHT style constant.
  67.      */
  68.     public static final int RIGHT = 1;
  69.  
  70.     /**
  71.      * The point UP style constant.
  72.      */
  73.     public static final int UP = 2;
  74.  
  75.     /**
  76.      * The point DOWN style constant.
  77.      */
  78.     public static final int DOWN = 3;
  79.  
  80.     /**
  81.      * Constructs a default DirectionButton, which will point left.
  82.      */
  83.     public DirectionButton()
  84.     {
  85.         this(LEFT);
  86.     }
  87.  
  88.     /**
  89.      * Constructs a DirectionButton pointing the specified direction.
  90.      * @param d a style constant indicating which direction to point the button
  91.      * @see #LEFT
  92.      * @see #UP
  93.      * @see #RIGHT
  94.      * @see #DOWN
  95.      */
  96.     public DirectionButton(int d)
  97.     {
  98.         direction     = d;
  99.         left         = 0;
  100.         right        = 0;
  101.         bottom        = 0;
  102.         indent        = 0;
  103.         tempIndent    = indent;
  104.         try { setArrowColor(Color.black); } catch (PropertyVetoException exc) {}
  105.  
  106.     }
  107.  
  108.     /**
  109.      * Sets the direction of the arrow after construction.
  110.      * @param d constant indicating direction to point button
  111.      * @exception PropertyVetoException
  112.      * if the specified property value is unacceptable
  113.      * @see #getDirection
  114.      * @see #LEFT
  115.      * @see #UP
  116.      * @see #RIGHT
  117.      * @see #DOWN
  118.      */
  119.     public void setDirection(int d) throws PropertyVetoException
  120.     {
  121.         if(direction != d)
  122.         {
  123.             Integer oldValue = new Integer(direction);
  124.             Integer newValue = new Integer(d);
  125.  
  126.             vetos.fireVetoableChange("direction", oldValue, newValue);
  127.  
  128.             direction = d;
  129.             repaint();
  130.  
  131.             changes.firePropertyChange("direction", oldValue, newValue);
  132.         }
  133.     }
  134.  
  135.     /**
  136.      * Returns the direction the button is currently pointing.
  137.      * @see #setDirection
  138.      * @see #LEFT
  139.      * @see #UP
  140.      * @see #RIGHT
  141.      * @see #DOWN
  142.      */
  143.     public int getDirection()
  144.     {
  145.         return direction;
  146.     }
  147.  
  148.     /**
  149.      * Sets the amount of blank space between the arrow and the button
  150.      * border in pixels.
  151.      * @param ai the margin around the arrow in pixels. 0=arrow takes up entire button
  152.      * @exception PropertyVetoException
  153.      * if the specified property value is unacceptable
  154.      * @see #getArrowIndent
  155.      */
  156.     public void setArrowIndent(int ai) throws PropertyVetoException
  157.     {
  158.         if(isAdded)
  159.         {
  160.             if(indent != ai)
  161.             {
  162.                 Integer oldValue = new Integer(indent);
  163.                 Integer newValue = new Integer(ai);
  164.  
  165.                 vetos.fireVetoableChange("arrowIndent", oldValue, newValue);
  166.  
  167.                 indent = ai;
  168.                 tempIndent = ai;
  169.                 //Make sure that changes to indent don't make changes to shrinkTriangle
  170.                 //give us a bad triangle.
  171.                 shrinkTriangle(left, right, top, bottom);
  172.                 repaint();
  173.  
  174.                 changes.firePropertyChange("arrowIndent", oldValue, newValue);
  175.             }
  176.         }
  177.         //We store the value until we are added then set the value to avoid code-gen order dependencies.
  178.         else
  179.         {
  180.             tempIndent = ai;
  181.         }
  182.     }
  183.  
  184.     /**
  185.      * Sets the color of the direction arrow.
  186.      * @param newValue the new arrow color.
  187.      * @exception PropertyVetoException
  188.      * if the specified property value is unacceptable
  189.      * @see #getArrowColor
  190.      */
  191.     public void setArrowColor(Color newValue) throws PropertyVetoException
  192.     {
  193.         if (!symantec.itools.util.GeneralUtils.objectsEqual(arrowColor, newValue))
  194.         {
  195.             Color oldValue = arrowColor;
  196.  
  197.             vetos.fireVetoableChange("arrowColor", oldValue, newValue);
  198.  
  199.             arrowColor = newValue;
  200.             try
  201.             {
  202.                 disabledArrowColor = ColorUtils.fade(arrowColor, Color.lightGray, 0.50);
  203.             }
  204.             catch (IllegalArgumentException exc) {}
  205.  
  206.             repaint();
  207.  
  208.             changes.firePropertyChange("arrowColor", oldValue, newValue);
  209.         }
  210.     }
  211.  
  212.     /**
  213.      * Gets the current color of the direction arrow.
  214.      * @return the current arrow color
  215.      * @see #setArrowColor
  216.      */
  217.     public Color getArrowColor()
  218.     {
  219.         return arrowColor;
  220.     }
  221.  
  222.     /**
  223.      * Returns the amount of blank space between the arrow and the button
  224.      * border in pixels.
  225.      * @see #setArrowIndent
  226.      */
  227.     public int getArrowIndent()
  228.     {
  229.         return isAdded ? indent : tempIndent;
  230.     }
  231.  
  232.     /**
  233.      * Sets the extra amount, in pixels, to shrink the arrow triangle.
  234.      * Constrains the values such that the arrow will never be less than
  235.      * three pixels.  If a value is entered that would exceed this limit,
  236.      * the limit will be used instead.
  237.      * @param left pixels to shrink from left side
  238.      * @param right pixels to shrink from right side
  239.      * @param top pixels to shrink from top
  240.      * @param bottom pixels to shrink from bottom
  241.      */
  242.     public void shrinkTriangle(int l, int r, int t, int b)
  243.     {
  244.         if(isAdded)
  245.         {
  246.             Dimension s = getSize();
  247.             int maxWidth    = s.width - bevel - bevel - 2;
  248.             int maxHeight    = s.height - bevel - bevel - 2;
  249.  
  250.             if(maxWidth - (l + r + indent + indent) >= 3)
  251.             {
  252.                 left    = l;
  253.                 right    = r;
  254.             }
  255.             else
  256.             {
  257.                 left    = (maxWidth - indent - indent - 3) / 2;
  258.                 right    = left;
  259.             }
  260.  
  261.             if(maxHeight - (t + b + indent + indent) >= 3)
  262.             {
  263.                 top        = t;
  264.                 bottom    = b;
  265.             }
  266.             else
  267.             {
  268.                 top    = (maxHeight - indent - indent - 3) / 2;
  269.                 bottom    = top;
  270.             }
  271.         }
  272.     }
  273.  
  274.     /**
  275.      * Returns the recommended dimensions to properly display this component.
  276.      * This is a standard Java AWT method which gets called to determine
  277.      * the recommended size of this component.
  278.      *
  279.      * @return a button that has a content area of 7 by 7 pixels.
  280.      * @see java.awt.Component#getMinimumSize
  281.      */
  282.     public Dimension getPreferredSize()
  283.     {
  284.         Dimension defaultSize = super.getPreferredSize();
  285.  
  286.         return new Dimension(defaultSize.width + 7, defaultSize.height + 7);
  287.     }
  288.  
  289.     /**
  290.      * Returns the minimum dimensions to properly display this component.
  291.      * This is a standard Java AWT method which gets called to determine
  292.      * the minimum size of this component.
  293.      *
  294.      * @return a button that has a content area of 3 by 3 pixels.
  295.      * @see java.awt.Component#getMinimumSize
  296.      */
  297.     public Dimension getMinimumSize()
  298.     {
  299.         Dimension defaultSize = super.getPreferredSize();
  300.  
  301.         return new Dimension(defaultSize.width + 3, defaultSize.height + 3);
  302.     }
  303.  
  304.     /**
  305.      * Tells this component that it has been added to a container.
  306.      * This is a standard Java AWT method which gets called by the AWT when
  307.      * this component is added to a container. Typically, it is used to
  308.      * create this component's peer.
  309.      *
  310.      * It has been overridden here to hook-up event listeners.
  311.      *
  312.      * @see #removeNotify
  313.      */
  314.     public synchronized void addNotify()
  315.     {        
  316.         try
  317.         {
  318.             errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
  319.         }
  320.         catch(Throwable ex)
  321.         {
  322.             errors = new symantec.itools.resources.ErrorsBundle();
  323.         }
  324.  
  325.         //Hook up listeners
  326.         if (sizeVeto == null)
  327.         {
  328.             sizeVeto = new SizeVeto();
  329.             addDirectionListener(sizeVeto);
  330.         }
  331.         if (indentVeto == null)
  332.         {
  333.             indentVeto = new IndntVeto();
  334.             addArrowIndentListener(indentVeto);
  335.         }
  336.  
  337.         //Add after the listeners are hooked up
  338.         super.addNotify();
  339.     }
  340.  
  341.     /**
  342.      * Tells this component that it is being removed from a container.
  343.      * This is a standard Java AWT method which gets called by the AWT when
  344.      * this component is removed from a container. Typically, it is used to
  345.      * destroy the peers of this component and all its subcomponents.
  346.      *
  347.      * It has been overridden here to unhook event listeners.
  348.      *
  349.      * @see #addNotify
  350.      */
  351.     public synchronized void removeNotify()
  352.     {
  353.         //Unhook listeners
  354.         if (sizeVeto != null)
  355.         {
  356.             removeDirectionListener(sizeVeto);
  357.             sizeVeto = null;
  358.         }
  359.         if (indentVeto != null)
  360.         {
  361.             removeArrowIndentListener(indentVeto);
  362.             indentVeto = null;
  363.         }
  364.  
  365.         super.removeNotify();
  366.     }
  367.  
  368.     /**
  369.      * Adds a listener for all event changes.
  370.      * @param listener the listener to add.
  371.      * @see #removePropertyChangeListener
  372.      */
  373.     public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
  374.     {
  375.         super.addPropertyChangeListener(listener);
  376.         changes.addPropertyChangeListener(listener);
  377.     }
  378.  
  379.     /**
  380.      * Removes a listener for all event changes.
  381.      * @param listener the listener to remove.
  382.      * @see #addPropertyChangeListener
  383.      */
  384.     public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
  385.     {
  386.         super.removePropertyChangeListener(listener);
  387.         changes.removePropertyChangeListener(listener);
  388.     }
  389.  
  390.     /**
  391.      * Adds a vetoable listener for all event changes.
  392.      * @param listener the listener to add.
  393.      * @see #removeVetoableChangeListener
  394.      */
  395.     public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
  396.     {
  397.          super.addVetoableChangeListener(listener);
  398.         vetos.addVetoableChangeListener(listener);
  399.     }
  400.  
  401.     /**
  402.      * Removes a vetoable listener for all event changes.
  403.      * @param listener the listener to remove.
  404.      * @see #addVetoableChangeListener
  405.      */
  406.     public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
  407.     {
  408.         super.removeVetoableChangeListener(listener);
  409.         vetos.removeVetoableChangeListener(listener);
  410.     }
  411.  
  412.     /**
  413.      * Adds a listener for the Direction property changes.
  414.      * @param listener the listener to add.
  415.      * @see #removeDirectionChangeListener
  416.      */
  417.     public synchronized void addDirectionListener(PropertyChangeListener listener)
  418.     {
  419.         changes.addPropertyChangeListener("direction", listener);
  420.     }
  421.  
  422.     /**
  423.      * Removes a listener for the Direction property changes.
  424.      * @param listener the listener to remove.
  425.      * @see #addDirectionChangeListener
  426.      */
  427.     public synchronized void removeDirectionListener(PropertyChangeListener listener)
  428.     {
  429.         changes.removePropertyChangeListener("direction", listener);
  430.     }
  431.  
  432.     /**
  433.      * Adds a vetoable listener for the Direction property changes.
  434.      * @param listener the listener to add.
  435.      * @see #removeVetoableDirectionChangeListener
  436.      */
  437.     public synchronized void addDirectionListener(VetoableChangeListener listener)
  438.     {
  439.         vetos.addVetoableChangeListener("direction", listener);
  440.     }
  441.  
  442.     /**
  443.      * Removes a vetoable listener for the Direction property changes.
  444.      * @param listener the listener to remove.
  445.      * @see #addVetoableDirectionChangeListener
  446.      */
  447.     public synchronized void removeDirectionListener(VetoableChangeListener listener)
  448.     {
  449.         vetos.removeVetoableChangeListener("direction", listener);
  450.     }
  451.  
  452.     /**
  453.      * Adds a listener for the ArrowIndent property changes.
  454.      * @param listener the listener to add.
  455.      * @see #removeDirectionChangeListener
  456.      */
  457.     public synchronized void addArrowIndentListener(PropertyChangeListener listener)
  458.     {
  459.         changes.addPropertyChangeListener("arrowIndent", listener);
  460.     }
  461.  
  462.     /**
  463.      * Removes a listener for the ArrowIndent property changes.
  464.      * @param listener the listener to remove.
  465.      * @see #addDirectionChangeListener
  466.      */
  467.     public synchronized void removeArrowIndentListener(PropertyChangeListener listener)
  468.     {
  469.         changes.removePropertyChangeListener("arrowIndent", listener);
  470.     }
  471.  
  472.     /**
  473.      * Adds a vetoable listener for the ArrowIndent property changes.
  474.      * @param listener the listener to add.
  475.      * @see #removeVetoableDirectionChangeListener
  476.      */
  477.     public synchronized void addArrowIndentListener(VetoableChangeListener listener)
  478.     {
  479.         vetos.addVetoableChangeListener("arrowIndent", listener);
  480.     }
  481.  
  482.     /**
  483.      * Removes a vetoable listener for the ArrowIndent property changes.
  484.      * @param listener the listener to remove.
  485.      * @see #addVetoableDirectionChangeListener
  486.      */
  487.     public synchronized void removeArrowIndentListener(VetoableChangeListener listener)
  488.     {
  489.         vetos.removeVetoableChangeListener("arrowIndent", listener);
  490.     }
  491.  
  492.     /**
  493.      * This is the PropertyChangeEvent handling inner class for the constrained Direction property.
  494.      * Handles vetoing Directions that are not valid.
  495.      */
  496.     class SizeVeto implements java.beans.VetoableChangeListener, java.io.Serializable
  497.     {
  498.         /**
  499.          * This method gets called when an attempt to change the constrained Direction property is made.
  500.          * Ensures the given direction size is valid for this button.
  501.          *
  502.          * @param     e a <code>PropertyChangeEvent</code> object describing the
  503.          *             event source and the property that has changed.
  504.          * @exception PropertyVetoException if the recipient wishes the property
  505.          *              change to be rolled back.
  506.          */
  507.         public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
  508.         {
  509.             int i = ((Integer)e.getNewValue()).intValue();
  510.             if (!isValidDirection(i))
  511.             {
  512.                 throw new PropertyVetoException(errors.getString("InvalidDirection") + i, e);
  513.             }
  514.         }
  515.     }
  516.  
  517.     /**
  518.      * This is the PropertyChangeEvent handling inner class for the constrained ArrowIndent property.
  519.      * Handles vetoing ArrowIndents that are not valid.
  520.      */
  521.     class IndntVeto implements java.beans.VetoableChangeListener, java.io.Serializable
  522.     {
  523.         /**
  524.          * This method gets called when an attempt to change the constrained ArrowIndent property is made.
  525.          * Ensures the given arrow indent size is valid for this button.
  526.          *
  527.          * @param     e a <code>PropertyChangeEvent</code> object describing the
  528.          *             event source and the property that has changed.
  529.          * @exception PropertyVetoException if the recipient wishes the property
  530.          *              change to be rolled back.
  531.          */
  532.         public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
  533.         {
  534.             int i = ((Integer)e.getNewValue()).intValue();
  535.             if (!isValidArrowIndent(i))
  536.             {
  537.                 throw new PropertyVetoException(errors.getString("InvalidArrowIndent") + i, e);
  538.             }
  539.         }
  540.     }
  541.  
  542.  
  543.     /**
  544.      * Maintains the buttonImage size and draws the
  545.      * button in the buttonImage offscreen image.
  546.      * @see symantec.itools.awt.ButtonBase#updateButtonImage
  547.      */
  548.     protected void updateButtonImage()
  549.     {
  550.         super.updateButtonImage();
  551.         Graphics g        = buttonImage.getGraphics();
  552.         Dimension s        = size();;
  553.         int trueBevel    = bevel + 1;
  554.         int centerHorizontal;
  555.         int centerVertical;
  556.         int topSide;
  557.         int bottomSide;
  558.         int leftSide;
  559.         int rightSide;
  560.  
  561.         if(isEnabled())
  562.         {
  563.             g.setColor(arrowColor);
  564.         }
  565.         else
  566.         {
  567.             g.setColor(disabledArrowColor);
  568.         }
  569.  
  570.         centerHorizontal    = ((s.width - 1) / 2)                    + pressedAdjustment;
  571.         centerVertical        = ((s.height - 1) / 2)                    + pressedAdjustment;
  572.         topSide                = (top + trueBevel - 1)                    + pressedAdjustment  + indent;
  573.         bottomSide            = (s.height - 1 - bottom - trueBevel)    + pressedAdjustment  - indent;
  574.         leftSide            = (left + trueBevel - 1)                + pressedAdjustment  + indent;
  575.         rightSide            = (s.width - 1 - right - trueBevel)        + pressedAdjustment  - indent;
  576.  
  577.         if (symantec.itools.lang.OS.isMacintosh())
  578.         {
  579.             leftSide    += 1;
  580.             topSide        += 1;
  581.         }
  582.  
  583.         switch (direction)
  584.         {
  585.             case UP:
  586.             {
  587.                 fillTriangle(g, centerHorizontal, topSide, leftSide, bottomSide, rightSide, bottomSide, direction);
  588.                 break;
  589.             }
  590.             case DOWN:
  591.             {
  592.                 fillTriangle(g, centerHorizontal, bottomSide, leftSide, topSide, rightSide, topSide, direction);
  593.                 break;
  594.             }
  595.  
  596.             case LEFT:
  597.             {
  598.                 fillTriangle(g, leftSide, centerVertical, rightSide, bottomSide, rightSide, topSide, direction);
  599.                 break;
  600.             }
  601.  
  602.             case RIGHT:
  603.             {
  604.                 fillTriangle(g, rightSide, centerVertical, leftSide, bottomSide, leftSide, topSide, direction);
  605.                 break;
  606.             }
  607.         }
  608.         if (g != null)
  609.             g.dispose();
  610.     }
  611.  
  612.     /**
  613.      * Fills a triangle which has at least one side that is straight up and down or left and right.
  614.      * @param g the Graphics to use to draw with.
  615.      * @param tipX the horizontal coordinate of the point opposite a straight side.
  616.      * @param tipY the vertical coordinate of the point opposite a straight side.
  617.      * @param aX the horizontal coordinate of one of the two points defining the straight side.
  618.      * @param aY the vertical coordinate of one of the two points defining the straight side.
  619.      * @param bX the horizontal coordinate of one of the two points defining the straight side.
  620.      * @param bY the vertical coordinate of one of the two points defining the straight side.
  621.      * @param direction the direction of the straight line UP, DOWN, or LEFT, RIGHT.
  622.      *
  623.      * aX and bX should be the same for UP or Down.  aY and bY should be the same for LEFT or RIGHT.
  624.      * If not, then the a coordinates are used.
  625.      *
  626.      * @see #UP
  627.      * @see #DOWN
  628.      * @see #LEFT
  629.      * @see #RIGHT
  630.      */
  631.     protected void fillTriangle(Graphics g, int tipX, int tipY, int aX, int aY, int bX, int bY, int direction)
  632.     {
  633.         int dist, max, min;
  634.  
  635.         switch(direction)
  636.         {
  637.             case UP:
  638.             case DOWN:
  639.                 dist = Math.abs(aX - bX);
  640.                 max = Math.max(aX, bX);
  641.                 min = Math.min(aX, bX);
  642.                 for(int i = min; i <= max; ++i)
  643.                 {
  644.                     g.drawLine(tipX, tipY, i, aY);
  645.                 }
  646.                 break;
  647.             case RIGHT:
  648.             case LEFT:
  649.                 dist = Math.abs(aY - bY);
  650.                 max = Math.max(aY, bY);
  651.                 min = Math.min(aY, bY);
  652.                 for(int i = min; i <= max; ++i)
  653.                 {
  654.                     g.drawLine(tipX, tipY, aX, i);
  655.                 }
  656.                 break;
  657.         }
  658.     }
  659.  
  660.     /**
  661.      * Is the given bevel size valid for this button.
  662.      * @param i the given bevel size
  663.      * @return true if the given bevel size is acceptable, false if not.
  664.      */
  665.     protected boolean isValidBevelSize(int i)
  666.     {
  667.         Dimension s = size();
  668.  
  669.         int temp = i * 2 + 4;
  670.  
  671.         if (i < 0 || s.width < temp || s.height < temp)
  672.             return false;
  673.         else
  674.             return true;
  675.     }
  676.  
  677.     /**
  678.      * Is the given direction valid for this button.
  679.      * @param i the given bevel size
  680.      * @return true if the given direction is acceptable, false if not.
  681.      */
  682.     protected boolean isValidDirection(int i)
  683.     {
  684.         switch(i)
  685.         {
  686.             case LEFT:
  687.             case RIGHT:
  688.             case UP:
  689.             case DOWN:
  690.                 return true;
  691.             default:
  692.                 return false;
  693.         }
  694.     }
  695.  
  696.     /**
  697.      * Is the given arrow indent is valid for this button.
  698.      * @param i the given bevel size
  699.      * @return true if the given indent size is acceptable, false if not.
  700.      */
  701.     protected boolean isValidArrowIndent(int i)
  702.     {
  703.         Dimension s = size();
  704.  
  705.         int temp = (i * 2) + (bevel + 1) * 2 + 4;
  706.  
  707.         if(i < 0 || s.width < temp || s.height < temp)
  708.             return false;
  709.         else
  710.             return true;
  711.     }
  712.  
  713.     /**
  714.      * Called after addNotify to set the internally constrined properties to their
  715.      * temporary values to validate them now that the component has been added to the form.
  716.      * This is used to avoid code-gen order dependencies, since VC generates all property
  717.      * manipulating code before adding the component to its container.
  718.      * Subclasses should override this function for any internally constrained properties,
  719.      * and call the super version in the overridden version.
  720.      */
  721.     protected void verifyContstrainedPropertyValues()
  722.     {
  723.         super.verifyContstrainedPropertyValues();
  724.         try { setArrowIndent(tempIndent); } catch (PropertyVetoException exc) { /*Silently verify.*/ }
  725.     }
  726.  
  727.     /**
  728.      * The color of the arrow in the button.
  729.      */
  730.     protected Color    arrowColor            = null;
  731.     /**
  732.      * The color of the arrow when the button is disabled.
  733.      */
  734.     protected Color    disabledArrowColor    = null;
  735.     /**
  736.      * The direction the arrow points.
  737.      * One of: LEFT, UP, RIGHT, or DOWN.
  738.      * @see #LEFT
  739.      * @see #UP
  740.      * @see #RIGHT
  741.      * @see #DOWN
  742.      */
  743.     protected int        direction;
  744.     /**
  745.      * The number of pixels to shrink the arrow from the left side of the button.
  746.      */
  747.     protected int        left;
  748.     /**
  749.      * The number of pixels to shrink the arrow from the right side of the button.
  750.      */
  751.     protected int        right;
  752.     /**
  753.      * The number of pixels to shrink the arrow from the top side of the button.
  754.      */
  755.     protected int        top;
  756.     /**
  757.      * The number of pixels to shrink the arrow from the bottom side of the button.
  758.      */
  759.     protected int        bottom;
  760.     /**
  761.      * The margin around the arrow in pixels. 0 = arrow takes up entire button.
  762.      */
  763.     protected int        indent;
  764.     protected int        tempIndent;
  765.     transient protected ResourceBundle errors;
  766.  
  767.     private SizeVeto    sizeVeto    = null;
  768.     private IndntVeto    indentVeto    = null;
  769.     private symantec.itools.beans.VetoableChangeSupport vetos = new symantec.itools.beans.VetoableChangeSupport(this);
  770.     private symantec.itools.beans.PropertyChangeSupport changes = new symantec.itools.beans.PropertyChangeSupport(this);
  771. }
  772.