home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / SpinButtonPanel.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  5.4 KB  |  204 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Event;
  4. import java.awt.LayoutManager;
  5. import java.awt.Panel;
  6.  
  7. /**
  8.  * This component provides the up/down or right/left buttons used in
  9.  * spinners. It is used by abstract class Spinner and in the HorizontalSpinButton
  10.  * and VerticalSpinButton components.
  11.  *
  12.  * @see symantec.itools.awt.Spinner
  13.  * @see symantec.itools.awt.HorizontalSpinButton
  14.  * @see symantec.itools.awt.VerticalSpinButton
  15.  * @version 1.0, Nov 26, 1996
  16.  * @author Symantec
  17.  */
  18.  
  19. public class SpinButtonPanel
  20.     extends Panel
  21. {
  22.     /**
  23.      * The button used to increment the spinner value.
  24.      */
  25.     protected DirectionButton incButton;
  26.     /**
  27.      * The button used to decrement the spinner value.
  28.      */
  29.     protected DirectionButton decButton;
  30.  
  31.     /**
  32.      * Constructs a spinner with up/down buttons.
  33.      */
  34.     public SpinButtonPanel()
  35.     {
  36.         add(incButton = new DirectionButton(DirectionButton.UP));
  37.         add(decButton = new DirectionButton(DirectionButton.DOWN));
  38.  
  39.         //setDelay(250);
  40.         //setNotifyWhilePressed(true);
  41.     }
  42.  
  43.     /**
  44.      * Sets whether the spinner buttons will continually send notify messages 
  45.      * while pressed.
  46.      * @param f true = send messages; false = do not send messages
  47.      * @see #getNotifyWhilePressed
  48.      * @see #setDelay
  49.      * @see #getDelay
  50.      */
  51.     public void setNotifyWhilePressed(boolean f)
  52.     {
  53.         incButton.setNotifyWhilePressed(f);
  54.         decButton.setNotifyWhilePressed(f);
  55.     }
  56.  
  57.     /**
  58.      * Returns the current notifyWhilePressed status.
  59.      * @see #setNotifyWhilePressed
  60.      * @see #setDelay
  61.      * @see #getDelay
  62.      */
  63.     public boolean getNotifyWhilePressed()
  64.     {
  65.         return incButton.getNotifyWhilePressed();
  66.     }
  67.  
  68.     /**
  69.      * Sets the notification message delay of the spinner buttons in milliseconds.
  70.      * @param d the delay between notification messages in milliseconds
  71.      * @see #setNotifyWhilePressed
  72.      * @see #getDelay
  73.      */
  74.     public void setDelay(int d)
  75.     {
  76.         incButton.setNotifyDelay(d);
  77.         decButton.setNotifyDelay(d);
  78.     }
  79.  
  80.     /**
  81.      * Returns the current delay between notification messages of the spinner
  82.      * buttons in milliseconds 
  83.      * @see #setNotifyWhilePressed
  84.      * @see #setDelay
  85.      */
  86.     public int getDelay()
  87.     {
  88.         return incButton.getNotifyDelay();
  89.     }
  90.  
  91.     /**
  92.      * Handles internal actions for this component.
  93.      * This is a standard Java AWT method which usually gets called by the AWT
  94.      * method handleEvent() in response to receiving an ACTION_EVENT event. In those 
  95.      * cases the o parameter contains the value in the event's arg field.
  96.      * 
  97.      * @param e the event that caused this action
  98.      * @param o the action
  99.      * @return true if the action was handled
  100.      * @see java.awt.Component#handleEvent
  101.      */
  102.     public boolean action(Event e, Object o)
  103.     {
  104.         if (e.target == incButton)
  105.         {
  106.             postEvent(new Event(this, Event.SCROLL_PAGE_UP, null));
  107.  
  108.             return true;
  109.         }
  110.         else if (e.target == decButton)
  111.         {
  112.             postEvent(new Event(this, Event.SCROLL_PAGE_DOWN, null));
  113.  
  114.             return true;
  115.         }
  116.  
  117.         return false;
  118.     }
  119.  
  120.     /**
  121.      * Enables this component so that it will respond to user input.
  122.      * This is a standard Java AWT method which gets called to enable 
  123.      * this component. Once enabled this component will respond to user input.
  124.      * 
  125.      * @see #disable
  126.      */
  127.     public synchronized void enable()
  128.     {
  129.         incButton.enable();
  130.         decButton.enable();
  131.     }
  132.  
  133.     /**
  134.      * Disables this component so that it doesn't respond to user input.
  135.      * This is a standard Java AWT method which gets called to disable
  136.      * this component. Once disabled this component will not respond to user 
  137.      * input.
  138.      *
  139.      * @see #enable
  140.      */
  141.     public synchronized void disable()
  142.     {
  143.         incButton.disable();
  144.         decButton.disable();
  145.     }
  146.  
  147.     /**
  148.      * This enables the incrementing button only.
  149.      * @see #disableUpButton
  150.      * @see #enableDownButton
  151.      */
  152.     public synchronized void enableUpButton()
  153.     {
  154.         incButton.enable();
  155.     }
  156.  
  157.     /**
  158.      * This enables the decrementing button only.
  159.      * @see #disableDownButton
  160.      * @see #enableUpButton
  161.      */
  162.     public synchronized void enableDownButton()
  163.     {
  164.         decButton.enable();
  165.     }
  166.  
  167.     /**
  168.      * This disables the incrementing button only.
  169.      * @see #enableUpButton
  170.      * @see #disableDownButton
  171.      */
  172.     public synchronized void disableUpButton()
  173.     {
  174.         incButton.disable();
  175.     }
  176.  
  177.     /**
  178.      * This disables the decrementing button only.
  179.      * @see #enableDownButton
  180.      * @see #disableUpButton
  181.      */
  182.     public synchronized void disableDownButton()
  183.     {
  184.         decButton.disable();
  185.     }
  186.  
  187.     /**
  188.      * Takes no action. 
  189.      * This is a standard Java AWT method which gets called to specify
  190.      * which layout manager should be used to layout the components in
  191.      * standard containers.
  192.      *
  193.      * Since layout managers CANNOT BE USED with this container the standard
  194.      * setLayout has been OVERRIDDEN for this container and does nothing.
  195.      *
  196.      * @param l the layout manager to use to layout this container's components
  197.      * (IGNORED)
  198.      * @see java.awt.Container#getLayout
  199.      **/
  200.     public void setLayout(LayoutManager l)
  201.     {
  202.     }
  203. }
  204.