/[classpath]/classpath/java/awt/Scrollbar.java
ViewVC logotype

Diff of /classpath/java/awt/Scrollbar.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18.2.5 by gnu_andrew, Fri Jan 21 02:16:35 2005 UTC revision 1.18.2.6 by gnu_andrew, Wed Feb 16 01:11:42 2005 UTC
# Line 52  import javax.accessibility.AccessibleSta Line 52  import javax.accessibility.AccessibleSta
52  import javax.accessibility.AccessibleValue;  import javax.accessibility.AccessibleValue;
53    
54  /**  /**
55    * This class implements a scrollbar widget.   * This class implements a scrollbar widget.
56    *   *
57    * @author Aaron M. Renn (arenn@urbanophile.com)   * @author Aaron M. Renn (arenn@urbanophile.com)
58    * @author Tom Tromey (tromey@cygnus.com)   * @author Tom Tromey (tromey@cygnus.com)
59    * @author Andrew John Hughes (gnu_andrew@member.fsf.org)   * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
   */  
 public class Scrollbar extends Component implements Accessible,  
                                                     Adjustable  
 {  
   
 // FIXME: Serialization readObject/writeObject  
   
 /*  
  * Static Variables  
60   */   */
61    public class Scrollbar extends Component implements Accessible, Adjustable
62    {
63      // FIXME: Serialization readObject/writeObject
64    
65  /**    /**
66    * Constant indicating that a scrollbar is horizontal.     * Constant indicating that a scrollbar is horizontal.
67    */     */
68  public static final int HORIZONTAL = 0;    public static final int HORIZONTAL = 0;
   
 /**  
   * Constant indicating that a scrollbar is vertical.  
   */  
 public static final int VERTICAL = 1;  
69    
70  // Serialization Constant    /**
71  private static final long serialVersionUID = 8451667562882310543L;     * Constant indicating that a scrollbar is vertical.
72       */
73      public static final int VERTICAL = 1;
74    
75  /*************************************************************************/    /**
76       * Serialization Constant.
77       */
78      private static final long serialVersionUID = 8451667562882310543L;
79    
80  /**    /**
81    * @serial The amount by which the value of the scrollbar is changed     * @serial The amount by which the value of the scrollbar is changed
82    * when incrementing in line mode.     * when incrementing in line mode.
83    */     */
84  private int lineIncrement;    private int lineIncrement;
85    
86  /**    /**
87    * @serial The amount by which the value of the scrollbar is changed     * @serial The amount by which the value of the scrollbar is changed
88    * when incrementing in page mode.     * when incrementing in page mode.
89    */     */
90  private int pageIncrement;    private int pageIncrement;
91    
92  /**    /**
93    * @serial The maximum value for this scrollbar     * @serial The maximum value for this scrollbar
94    */     */
95  private int maximum;    private int maximum;
96    
97  /**    /**
98    * @serial The minimum value for this scrollbar     * @serial The minimum value for this scrollbar
99    */     */
100  private int minimum;    private int minimum;
101    
102  /**    /**
103    * @serial The orientation of this scrollbar, which will be either     * @serial The orientation of this scrollbar, which will be either
104    * the <code>HORIZONTAL</code> or <code>VERTICAL</code> constant     * the <code>HORIZONTAL</code> or <code>VERTICAL</code> constant
105    * from this class.     * from this class.
106    */     */
107  private int orientation;    private int orientation;
108    
109  /**    /**
110    * @serial The current value of this scrollbar.     * @serial The current value of this scrollbar.
111    */     */
112  private int value;    private int value;
113    
114  /**    /**
115    * @serial The width of the scrollbar's thumb, which is relative     * @serial The width of the scrollbar's thumb, which is relative
116    * to the minimum and maximum value of the scrollbar.     * to the minimum and maximum value of the scrollbar.
117    */     */
118  private int visibleAmount;    private int visibleAmount;
119    
120  // List of AdjustmentListener's.    /**
121  private AdjustmentListener adjustment_listeners;     * List of AdjustmentListener's.
122       */
123      private AdjustmentListener adjustment_listeners;
124    
125  private transient boolean valueIsAdjusting = false;    /**
126       * true if the scrollbar is adjusting, false otherwise.
127       */
128      private transient boolean valueIsAdjusting = false;
129    
130    /*    /**
131     * The number used to generate the name returned by getName.     * The number used to generate the name returned by getName.
132     */     */
133    private static transient long next_scrollbar_number;    private static transient long next_scrollbar_number;
134    
135  /*************************************************************************/    /**
136       * Initializes a new instance of <code>Scrollbar</code> with a
137  /*     * vertical orientation and default values for all other parameters.
138   * Constructors     *
139   */     * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,
140       */
141  /**    public Scrollbar()
142    * Initializes a new instance of <code>Scrollbar</code> with a    {
143    * vertical orientation and default values for all other parameters.      this(VERTICAL);
144    *    }
   * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,  
   */  
 public  
 Scrollbar()  
 {  
   this(VERTICAL);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Initializes a new instance of <code>Scrollbar</code> with the  
   * specified orientation and default values for all other parameters.  
   * The orientation must be either the constant <code>HORIZONTAL</code> or  
   * <code>VERTICAL</code> from this class.  An incorrect value will throw  
   * an exception.  
   *  
   * @param orientation The orientation of this scrollbar.  
   *  
   * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,  
   * @exception IllegalArgumentException If the orientation value is not valid.  
   */  
 public  
 Scrollbar(int orientation) throws IllegalArgumentException  
 {  
   this(orientation, 0, 10, 0, 100);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Initializes a new instance of <code>Scrollbar</code> with the  
   * specified parameters.  The orientation must be either the constant  
   * <code>HORIZONTAL</code> or <code>VERTICAL</code>.  An incorrect value  
   * will throw an exception.  Inconsistent values for other parameters  
   * are silently corrected to valid values.  
   *  
   * @param orientation The orientation of this scrollbar.  
   * @param value The initial value of the scrollbar.  
   * @param visibleAmount The width of the scrollbar thumb.  
   * @param minimum The minimum value of the scrollbar.  
   * @param maximum The maximum value of the scrollbar.  
   *  
   * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,  
   * @exception IllegalArgumentException If the orientation value is not valid.  
   */  
 public  
 Scrollbar(int orientation, int value, int visibleAmount, int minimum,  
           int maximum) throws IllegalArgumentException  
 {  
   if (GraphicsEnvironment.isHeadless())  
     throw new HeadlessException ();  
   
   if ((orientation != HORIZONTAL) && (orientation != VERTICAL))  
     throw new IllegalArgumentException("Bad orientation value: "  
                                        + orientation);  
   
   this.orientation = orientation;  
   
   setValues(value, visibleAmount, minimum, maximum);  
   
   // Default is 1 according to online docs.  
   lineIncrement = 1;  
   
   // Default is 10 according to javadocs.  
   pageIncrement = 10;  
 }  
   
 /*************************************************************************/  
   
 /*  
  * Instance Methods  
  */  
   
 /**  
   * Returns the orientation constant for this object.  
   *  
   * @return The orientation constant for this object.  
   */  
 public int  
 getOrientation()  
 {  
   return(orientation);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Sets the orientation of this scrollbar to the specified value.  This  
   * value must be either the constant <code>HORIZONTAL</code> or  
   * <code>VERTICAL</code> from this class or an exception will be thrown.  
   *  
   * @param orientation The new orientation value.  
   *  
   * @exception IllegalArgumentException If the orientation value is not valid.  
   */  
 public void  
 setOrientation(int orientation)  
 {  
   if ((orientation != HORIZONTAL) && (orientation != VERTICAL))  
     throw new IllegalArgumentException("Bad orientation value: "  
                                        + orientation);  
   
   // FIXME: Communicate to peer?  Or must this be called before peer creation?  
   this.orientation = orientation;  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the current value for this scrollbar.  
   *  
   * @return The current value for this scrollbar.  
   */  
 public int  
 getValue()  
 {  
   return(value);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Sets the current value for this scrollbar to the specified value.  
   * If this is inconsistent with the minimum and maximum values for this  
   * scrollbar, the value is silently adjusted.  
   *  
   * @param value The new value for this scrollbar.  
   */  
 public void  
 setValue(int value)  
 {  
   setValues(value, visibleAmount, minimum, maximum);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the maximum value for this scrollbar.  
   *  
   * @return The maximum value for this scrollbar.  
   */  
 public int  
 getMaximum()  
 {  
   return(maximum);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Sets the maximum value for this scrollbar to the specified value.  
   * If the value is less than the current minimum value, it is silent  
   * set to equal the minimum value.  
   *  
   * @param maximum The new maximum value for this scrollbar.  
   */  
 public void  
 setMaximum(int maximum)  
 {  
   setValues(value, visibleAmount, minimum, maximum);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the minimum value for this scrollbar.  
   *  
   * @return The minimum value for this scrollbar.  
   */  
 public int  
 getMinimum()  
 {  
   return(minimum);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Sets the minimum value for this scrollbar to the specified value.  If  
   * this is not consistent with the current value and maximum, it is  
   * silently adjusted to be consistent.  
   *  
   * @param minimum The new minimum value for this scrollbar.  
   */  
 public void  
 setMinimum(int minimum)  
 {  
   setValues(value, visibleAmount, minimum, maximum);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the width of the scrollbar's thumb, in units relative to the  
   * maximum and minimum value of the scrollbar.  
   *  
   * @return The width of the scrollbar's thumb.  
   */  
 public int  
 getVisibleAmount()  
 {  
   return getVisible ();  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Returns the width of the scrollbar's thumb, in units relative to the  
   * maximum and minimum value of the scrollbar.  
   *  
   * @return The width of the scrollbar's thumb.  
   *  
   * @deprecated This method is deprecated in favor of  
   * <code>getVisibleAmount()</code>.  
   */  
 public int  
 getVisible()  
 {  
   return visibleAmount;  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Sets the width of the scrollbar's thumb, in units relative to the  
   * maximum and minimum value of the scrollbar.  
   *  
   * @param visibleAmount The new visible amount value of the scrollbar.  
   */  
 public void  
 setVisibleAmount(int visibleAmount)  
 {  
   setValues(value, visibleAmount, minimum, maximum);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Sets the current value, visible amount, minimum, and maximum for this  
   * scrollbar.  These values are adjusted to be internally consistent  
   * if necessary.  
   *  
   * @param value The new value for this scrollbar.  
   * @param visibleAmount The new visible amount for this scrollbar.  
   * @param minimum The new minimum value for this scrollbar.  
   * @param maximum The new maximum value for this scrollbar.  
   */  
 public synchronized void  
 setValues(int value, int visibleAmount, int minimum, int maximum)  
 {  
   if (maximum < minimum)  
     maximum = minimum;  
   
   if (value < minimum)  
     value = minimum;  
   
   if (value > maximum)  
     value = maximum;  
   
   if (visibleAmount > maximum - minimum)  
     visibleAmount = maximum - minimum;  
   
   ScrollbarPeer peer = (ScrollbarPeer) getPeer ();  
   if (peer != null  
       && (this.value != value || this.visibleAmount != visibleAmount  
           || this.minimum != minimum || this.maximum != maximum))  
     peer.setValues(value, visibleAmount, minimum, maximum);  
   
   this.value = value;  
   this.visibleAmount = visibleAmount;  
   this.minimum = minimum;  
   this.maximum = maximum;  
145    
146    int range = maximum - minimum;    /**
147    if (lineIncrement > range)     * Initializes a new instance of <code>Scrollbar</code> with the
148      {     * specified orientation and default values for all other parameters.
149        if (range == 0)     * The orientation must be either the constant <code>HORIZONTAL</code> or
150          lineIncrement = 1;     * <code>VERTICAL</code> from this class.  An incorrect value will throw
151        else     * an exception.
152          lineIncrement = range;     *
153       * @param orientation The orientation of this scrollbar.
154       *
155       * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,
156       * @exception IllegalArgumentException If the orientation value is not valid.
157       */
158      public Scrollbar(int orientation) throws IllegalArgumentException
159      {
160        this(orientation, 0, 10, 0, 100);
161      }
162    
163        if (peer != null)    /**
164          peer.setLineIncrement(lineIncrement);     * Initializes a new instance of <code>Scrollbar</code> with the
165      }     * specified parameters.  The orientation must be either the constant
166       * <code>HORIZONTAL</code> or <code>VERTICAL</code>.  An incorrect value
167       * will throw an exception.  Inconsistent values for other parameters
168       * are silently corrected to valid values.
169       *
170       * @param orientation The orientation of this scrollbar.
171       * @param value The initial value of the scrollbar.
172       * @param visibleAmount The width of the scrollbar thumb.
173       * @param minimum The minimum value of the scrollbar.
174       * @param maximum The maximum value of the scrollbar.
175       *
176       * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,
177       * @exception IllegalArgumentException If the orientation value is not valid.
178       */
179      public Scrollbar(int orientation, int value, int visibleAmount, int minimum,
180                       int maximum) throws IllegalArgumentException
181      {
182        if (GraphicsEnvironment.isHeadless())
183          throw new HeadlessException();
184    
185    if (pageIncrement > range)      if ((orientation != HORIZONTAL) && (orientation != VERTICAL))
186      {        throw new IllegalArgumentException("Bad orientation value: "
187        if (range == 0)                                           + orientation);
         pageIncrement = 1;  
       else  
         pageIncrement = range;  
188    
189        if (peer != null)      this.orientation = orientation;
         peer.setPageIncrement(pageIncrement);  
     }  
 }  
190    
191  /*************************************************************************/      setValues(value, visibleAmount, minimum, maximum);
192    
193  /**      // Default is 1 according to online docs.
194    * Returns the value added or subtracted when the user activates the scrollbar      lineIncrement = 1;
   * scroll by a "unit" amount.  
   *  
   * @return The unit increment value.  
   */  
 public int  
 getUnitIncrement()  
 {  
   return getLineIncrement ();  
 }  
195    
196  /*************************************************************************/      // Default is 10 according to javadocs.
197        pageIncrement = 10;
198      }
199    
200  /**    /**
201    * Returns the value added or subtracted when the user selects the scrollbar     * Returns the orientation constant for this object.
202    * scroll by a "unit" amount control.     *
203    *     * @return The orientation constant for this object.
204    * @return The unit increment value.     */
205    *    public int getOrientation()
206    * @deprecated This method is deprecated in favor of    {
207    * <code>getUnitIncrement()</code>.      return orientation;
208    */    }
 public int  
 getLineIncrement()  
 {  
   return lineIncrement;  
 }  
209    
210  /*************************************************************************/    /**
211       * Sets the orientation of this scrollbar to the specified value.  This
212       * value must be either the constant <code>HORIZONTAL</code> or
213       * <code>VERTICAL</code> from this class or an exception will be thrown.
214       *
215       * @param orientation The new orientation value.
216       *
217       * @exception IllegalArgumentException If the orientation value is not valid.
218       */
219      public void setOrientation(int orientation)
220      {
221        if ((orientation != HORIZONTAL) && (orientation != VERTICAL))
222          throw new IllegalArgumentException("Bad orientation value: "
223                                             + orientation);
224    
225  /**      // FIXME: Communicate to peer?  Or must this be called before peer creation?
226    * Sets the value added or subtracted to the scrollbar value when the      this.orientation = orientation;
227    * user selects the scroll by a "unit" amount control.    }
   *  
   * @param unitIncrement The new unit increment amount.  
   */  
 public synchronized void  
 setUnitIncrement(int unitIncrement)  
 {  
   setLineIncrement (unitIncrement);  
 }  
228    
229  /*************************************************************************/    /**
230       * Returns the current value for this scrollbar.
231       *
232       * @return The current value for this scrollbar.
233       */
234      public int getValue()
235      {
236        return value;
237      }
238    
239  /**    /**
240    * Sets the value added or subtracted to the scrollbar value when the     * Sets the current value for this scrollbar to the specified value.
241    * user selects the scroll by a "unit" amount control.     * If this is inconsistent with the minimum and maximum values for this
242    *     * scrollbar, the value is silently adjusted.
243    * @param lineIncrement The new unit increment amount.     *
244    *     * @param value The new value for this scrollbar.
245    * @deprecated This method is deprecated in favor of     */
246    * <code>setUnitIncrement()</code>.    public void setValue(int value)
247    */    {
248  public void      setValues(value, visibleAmount, minimum, maximum);
249  setLineIncrement(int lineIncrement)    }
 {  
   if (lineIncrement < 0)  
     throw new IllegalArgumentException ("Unit increment less than zero.");  
250    
251    int range = maximum - minimum;    /**
252    if (lineIncrement > range)     * Returns the maximum value for this scrollbar.
253      {     *
254        if (range == 0)     * @return The maximum value for this scrollbar.
255          lineIncrement = 1;     */
256        else    public int getMaximum()
257          lineIncrement = range;    {
258      }      return maximum;
259      }
260    
261    if (lineIncrement == this.lineIncrement)    /**
262      return;     * Sets the maximum value for this scrollbar to the specified value.
263       * If the value is less than the current minimum value, it is silent
264       * set to equal the minimum value.
265       *
266       * @param maximum The new maximum value for this scrollbar.
267       */
268      public void setMaximum(int maximum)
269      {
270        setValues(value, visibleAmount, minimum, maximum);
271      }
272    
273    this.lineIncrement = lineIncrement;    /**
274       * Returns the minimum value for this scrollbar.
275       *
276       * @return The minimum value for this scrollbar.
277       */
278      public int getMinimum()
279      {
280        return minimum;
281      }
282    
283    ScrollbarPeer peer = (ScrollbarPeer) getPeer ();    /**
284    if (peer != null)     * Sets the minimum value for this scrollbar to the specified value.  If
285      peer.setLineIncrement (this.lineIncrement);     * this is not consistent with the current value and maximum, it is
286  }     * silently adjusted to be consistent.
287       *
288       * @param minimum The new minimum value for this scrollbar.
289       */
290      public void setMinimum(int minimum)
291      {
292        setValues(value, visibleAmount, minimum, maximum);
293      }
294    
295  /*************************************************************************/    /**
296       * Returns the width of the scrollbar's thumb, in units relative to the
297       * maximum and minimum value of the scrollbar.
298       *
299       * @return The width of the scrollbar's thumb.
300       */
301      public int getVisibleAmount()
302      {
303        return getVisible();
304      }
305    
306  /**    /**
307    * Returns the value added or subtracted when the user activates the scrollbar     * Returns the width of the scrollbar's thumb, in units relative to the
308    * scroll by a "block" amount.     * maximum and minimum value of the scrollbar.
309    *     *
310    * @return The block increment value.     * @return The width of the scrollbar's thumb.
311    */     *
312  public int     * @deprecated This method is deprecated in favor of
313  getBlockIncrement()     * <code>getVisibleAmount()</code>.
314  {     */
315    return getPageIncrement ();    public int getVisible()
316  }    {
317        return visibleAmount;
318      }
319    
320  /*************************************************************************/    /**
321       * Sets the width of the scrollbar's thumb, in units relative to the
322       * maximum and minimum value of the scrollbar.
323       *
324       * @param visibleAmount The new visible amount value of the scrollbar.
325       */
326      public void setVisibleAmount(int visibleAmount)
327      {
328        setValues(value, visibleAmount, minimum, maximum);
329      }
330    
331  /**    /**
332    * Returns the value added or subtracted when the user selects the scrollbar     * Sets the current value, visible amount, minimum, and maximum for this
333    * scroll by a "block" amount control.     * scrollbar.  These values are adjusted to be internally consistent
334    *     * if necessary.
335    * @return The block increment value.     *
336    *     * @param value The new value for this scrollbar.
337    * @deprecated This method is deprecated in favor of     * @param visibleAmount The new visible amount for this scrollbar.
338    * <code>getBlockIncrement()</code>.     * @param minimum The new minimum value for this scrollbar.
339    */     * @param maximum The new maximum value for this scrollbar.
340  public int     */
341  getPageIncrement()    public synchronized void setValues(int value, int visibleAmount,
342  {                                       int minimum, int maximum)
343    return pageIncrement;    {
344  }      if (maximum < minimum)
345          maximum = minimum;
346    
347  /*************************************************************************/      if (value < minimum)
348          value = minimum;
349    
350  /**      if (value > maximum)
351    * Sets the value added or subtracted to the scrollbar value when the        value = maximum;
   * user selects the scroll by a "block" amount control.  
   *  
   * @param blockIncrement The new block increment amount.  
   */  
 public synchronized void  
 setBlockIncrement(int blockIncrement)  
 {  
   setPageIncrement (blockIncrement);  
 }  
352    
353  /*************************************************************************/      if (visibleAmount > maximum - minimum)
354          visibleAmount = maximum - minimum;
355    
356        ScrollbarPeer peer = (ScrollbarPeer) getPeer();
357        if (peer != null
358            && (this.value != value || this.visibleAmount != visibleAmount
359                || this.minimum != minimum || this.maximum != maximum))
360          peer.setValues(value, visibleAmount, minimum, maximum);
361    
362        this.value = value;
363        this.visibleAmount = visibleAmount;
364        this.minimum = minimum;
365        this.maximum = maximum;
366    
367        int range = maximum - minimum;
368        if (lineIncrement > range)
369          {
370            if (range == 0)
371              lineIncrement = 1;
372            else
373              lineIncrement = range;
374    
375            if (peer != null)
376              peer.setLineIncrement(lineIncrement);
377          }
378    
379        if (pageIncrement > range)
380          {
381            if (range == 0)
382              pageIncrement = 1;
383            else
384              pageIncrement = range;
385    
386            if (peer != null)
387              peer.setPageIncrement(pageIncrement);
388          }
389      }
390    
391  /**    /**
392    * Sets the value added or subtracted to the scrollbar value when the     * Returns the value added or subtracted when the user activates the scrollbar
393    * user selects the scroll by a "block" amount control.     * scroll by a "unit" amount.
394    *     *
395    * @param pageIncrement The new block increment amount.     * @return The unit increment value.
396    *     */
397    * @deprecated This method is deprecated in favor of    public int getUnitIncrement()
398    * <code>setBlockIncrement()</code>.    {
399    */      return getLineIncrement();
400  public void    }
 setPageIncrement(int pageIncrement)  
 {  
   if (pageIncrement < 0)  
     throw new IllegalArgumentException ("Block increment less than zero.");  
401    
402    int range = maximum - minimum;    /**
403    if (pageIncrement > range)     * Returns the value added or subtracted when the user selects the scrollbar
404      {     * scroll by a "unit" amount control.
405        if (range == 0)     *
406          pageIncrement = 1;     * @return The unit increment value.
407        else     *
408          pageIncrement = range;     * @deprecated This method is deprecated in favor of
409      }     * <code>getUnitIncrement()</code>.
410       */
411      public int getLineIncrement()
412      {
413        return lineIncrement;
414      }
415    
416    if (pageIncrement == this.pageIncrement)    /**
417      return;     * Sets the value added or subtracted to the scrollbar value when the
418       * user selects the scroll by a "unit" amount control.
419       *
420       * @param unitIncrement The new unit increment amount.
421       */
422      public synchronized void setUnitIncrement(int unitIncrement)
423      {
424        setLineIncrement(unitIncrement);
425      }
426    
427    this.pageIncrement = pageIncrement;    /**
428       * Sets the value added or subtracted to the scrollbar value when the
429       * user selects the scroll by a "unit" amount control.
430       *
431       * @param lineIncrement The new unit increment amount.
432       *
433       * @deprecated This method is deprecated in favor of
434       * <code>setUnitIncrement()</code>.
435       */
436      public void setLineIncrement(int lineIncrement)
437      {
438        if (lineIncrement < 0)
439          throw new IllegalArgumentException("Unit increment less than zero.");
440    
441    ScrollbarPeer peer = (ScrollbarPeer) getPeer ();      int range = maximum - minimum;
442    if (peer != null)      if (lineIncrement > range)
443      peer.setPageIncrement (this.pageIncrement);        {
444  }          if (range == 0)
445              lineIncrement = 1;
446            else
447              lineIncrement = range;
448          }
449    
450        if (lineIncrement == this.lineIncrement)
451          return;
452    
453        this.lineIncrement = lineIncrement;
454    
455        ScrollbarPeer peer = (ScrollbarPeer) getPeer();
456        if (peer != null)
457          peer.setLineIncrement(this.lineIncrement);
458      }
459    
460  /*************************************************************************/    /**
461       * Returns the value added or subtracted when the user activates the scrollbar
462       * scroll by a "block" amount.
463       *
464       * @return The block increment value.
465       */
466      public int getBlockIncrement()
467      {
468        return getPageIncrement();
469      }
470    
471  /**    /**
472    * Notifies this object to create its native peer.     * Returns the value added or subtracted when the user selects the scrollbar
473    */     * scroll by a "block" amount control.
474  public synchronized void     *
475  addNotify()     * @return The block increment value.
476  {     *
477    if (peer == null)     * @deprecated This method is deprecated in favor of
478      peer = getToolkit ().createScrollbar (this);     * <code>getBlockIncrement()</code>.
479    super.addNotify ();     */
480  }    public int getPageIncrement()
481      {
482        return pageIncrement;
483      }
484    
485  /*************************************************************************/    /**
486       * Sets the value added or subtracted to the scrollbar value when the
487       * user selects the scroll by a "block" amount control.
488       *
489       * @param blockIncrement The new block increment amount.
490       */
491      public synchronized void setBlockIncrement(int blockIncrement)
492      {
493        setPageIncrement(blockIncrement);
494      }
495    
496  /**    /**
497    * Adds a new adjustment listener to the list of registered listeners     * Sets the value added or subtracted to the scrollbar value when the
498    * for this object.     * user selects the scroll by a "block" amount control.
499    *     *
500    * @param listener The listener to add.     * @param pageIncrement The new block increment amount.
501    */     *
502  public synchronized void     * @deprecated This method is deprecated in favor of
503  addAdjustmentListener(AdjustmentListener listener)     * <code>setBlockIncrement()</code>.
504  {     */
505    adjustment_listeners = AWTEventMulticaster.add(adjustment_listeners, listener);    public void setPageIncrement(int pageIncrement)
506    enableEvents(AWTEvent.ADJUSTMENT_EVENT_MASK);    {
507  }      if (pageIncrement < 0)
508          throw new IllegalArgumentException("Block increment less than zero.");
509    
510  /*************************************************************************/      int range = maximum - minimum;
511        if (pageIncrement > range)
512          {
513            if (range == 0)
514              pageIncrement = 1;
515            else
516              pageIncrement = range;
517          }
518    
519        if (pageIncrement == this.pageIncrement)
520          return;
521    
522        this.pageIncrement = pageIncrement;
523    
524        ScrollbarPeer peer = (ScrollbarPeer) getPeer();
525        if (peer != null)
526          peer.setPageIncrement(this.pageIncrement);
527      }
528    
529  /**    /**
530    * Removes the specified listener from the list of registered listeners     * Notifies this object to create its native peer.
531    * for this object.     */
532    *    public synchronized void addNotify()
533    * @param listener The listener to remove.    {
534    */      if (peer == null)
535  public synchronized void        peer = getToolkit().createScrollbar(this);
536  removeAdjustmentListener(AdjustmentListener listener)      super.addNotify();
537  {    }
   adjustment_listeners = AWTEventMulticaster.remove(adjustment_listeners,  
                                                     listener);  
 }  
538    
539  /*************************************************************************/    /**
540       * Adds a new adjustment listener to the list of registered listeners
541       * for this object.
542       *
543       * @param listener The listener to add.
544       */
545      public synchronized void addAdjustmentListener(AdjustmentListener listener)
546      {
547        adjustment_listeners = AWTEventMulticaster.add(adjustment_listeners,
548                                                       listener);
549        enableEvents(AWTEvent.ADJUSTMENT_EVENT_MASK);
550      }
551    
552  /**    /**
553    * Processes events for this scrollbar.  It does this by calling     * Removes the specified listener from the list of registered listeners
554    * <code>processAdjustmentEvent()</code> if the event is an instance of     * for this object.
555    * <code>AdjustmentEvent</code>, otherwise it calls the superclass to     *
556    * process the event.     * @param listener The listener to remove.
557    *     */
558    * @param event The event to process.    public synchronized void removeAdjustmentListener(AdjustmentListener listener)
559    */    {
560  protected void      adjustment_listeners = AWTEventMulticaster.remove(adjustment_listeners,
561  processEvent(AWTEvent event)                                                        listener);
562  {    }
   if (event instanceof AdjustmentEvent)  
     processAdjustmentEvent((AdjustmentEvent)event);  
   else  
     super.processEvent(event);  
 }  
563    
564  /*************************************************************************/    /**
565       * Processes events for this scrollbar.  It does this by calling
566       * <code>processAdjustmentEvent()</code> if the event is an instance of
567       * <code>AdjustmentEvent</code>, otherwise it calls the superclass to
568       * process the event.
569       *
570       * @param event The event to process.
571       */
572      protected void processEvent(AWTEvent event)
573      {
574        if (event instanceof AdjustmentEvent)
575          processAdjustmentEvent((AdjustmentEvent) event);
576        else
577          super.processEvent(event);
578      }
579    
580  /**    /**
581    * Processes adjustment events for this object by dispatching them to     * Processes adjustment events for this object by dispatching them to
582    * any registered listeners.  Note that this method will only be called     * any registered listeners.  Note that this method will only be called
583    * if adjustment events are enabled.  This will happen automatically if     * if adjustment events are enabled.  This will happen automatically if
584    * any listeners are registered.  Otherwise, it can be enabled by a     * any listeners are registered.  Otherwise, it can be enabled by a
585    * call to <code>enableEvents()</code>.     * call to <code>enableEvents()</code>.
586    *     *
587    * @param event The event to process.     * @param event The event to process.
588    */     */
589  protected void    protected void processAdjustmentEvent(AdjustmentEvent event)
590  processAdjustmentEvent(AdjustmentEvent event)    {
591  {      value = event.getValue();
592    value = event.getValue();      if (adjustment_listeners != null)
593    if (adjustment_listeners != null)        adjustment_listeners.adjustmentValueChanged(event);
594      adjustment_listeners.adjustmentValueChanged(event);    }
 }  
595    
596  void    void dispatchEventImpl(AWTEvent e)
597  dispatchEventImpl(AWTEvent e)    {
598  {      if (e.id <= AdjustmentEvent.ADJUSTMENT_LAST
   if (e.id <= AdjustmentEvent.ADJUSTMENT_LAST  
599        && e.id >= AdjustmentEvent.ADJUSTMENT_FIRST        && e.id >= AdjustmentEvent.ADJUSTMENT_FIRST
600        && (adjustment_listeners != null        && (adjustment_listeners != null
601            || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0))            || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0))
602      processEvent(e);        processEvent(e);
603    else      else
604      super.dispatchEventImpl(e);        super.dispatchEventImpl(e);
605  }    }
   
 /*************************************************************************/  
606    
607  /**    /**
608    * Returns a debugging string for this object.     * Returns a debugging string for this object.
609    *     *
610    * @return A debugging string for this object.     * @return A debugging string for this object.
611    */     */
612  protected String    protected String paramString()
613  paramString()    {
614  {      return ("value=" + getValue() + ",visibleAmount=" + getVisibleAmount()
615    return("value=" + getValue() + ",visibleAmount=" +              + ",minimum=" + getMinimum() + ",maximum=" + getMaximum()
616           getVisibleAmount() + ",minimum=" + getMinimum()              + ",pageIncrement=" + pageIncrement + ",lineIncrement="
617           + ",maximum=" + getMaximum()              + lineIncrement + ",orientation="
618           + ",pageIncrement=" + pageIncrement              + (orientation == HORIZONTAL ? "HORIZONTAL" : "VERTICAL")
619           + ",lineIncrement=" + lineIncrement              + super.paramString());
620           + ",orientation=" + (orientation == HORIZONTAL    }
                               ? "HORIZONTAL" : "VERTICAL")  
          + super.paramString());  
 }  
621    
622    /**    /**
623     * Returns an array of all the objects currently registered as FooListeners     * Returns an array of all the objects currently registered as FooListeners
624     * upon this <code>Scrollbar</code>. FooListeners are registered using the     * upon this <code>Scrollbar</code>. FooListeners are registered using the
625     * addFooListener method.     * addFooListener method.
626     *     *
627     * @exception ClassCastException If listenerType doesn't specify a class or     * @exception ClassCastException If listenerType doesn't specify a class or
628     * interface that implements java.util.EventListener.     * interface that implements java.util.EventListener.
629     */     */
630    public EventListener[] getListeners (Class listenerType)    public EventListener[] getListeners(Class listenerType)
631    {    {
632      if (listenerType == AdjustmentListener.class)      if (listenerType == AdjustmentListener.class)
633        return AWTEventMulticaster.getListeners (adjustment_listeners,        return AWTEventMulticaster.getListeners(adjustment_listeners,
634                                                 listenerType);                                                listenerType);
635    
636      return super.getListeners (listenerType);      return super.getListeners(listenerType);
637    }    }
638    
639    /**    /**
640     * Returns an array of all registered adjustment listeners.     * Returns an array of all registered adjustment listeners.
641     */     */
642    public AdjustmentListener[] getAdjustmentListeners ()    public AdjustmentListener[] getAdjustmentListeners()
643    {    {
644      return (AdjustmentListener[]) getListeners (AdjustmentListener.class);      return (AdjustmentListener[]) getListeners(AdjustmentListener.class);
645    }    }
646    
647    /**    /**
# Line 746  paramString() Line 649  paramString()
649     *     *
650     * @since 1.4     * @since 1.4
651     */     */
652    public boolean getValueIsAdjusting ()    public boolean getValueIsAdjusting()
653    {    {
654      return valueIsAdjusting;      return valueIsAdjusting;
655    }    }
# Line 756  paramString() Line 659  paramString()
659     *     *
660     * @since 1.4     * @since 1.4
661     */     */
662    public void setValueIsAdjusting (boolean valueIsAdjusting)    public void setValueIsAdjusting(boolean valueIsAdjusting)
663    {    {
664      this.valueIsAdjusting = valueIsAdjusting;      this.valueIsAdjusting = valueIsAdjusting;
665    }    }
# Line 766  paramString() Line 669  paramString()
669     *     *
670     * @return A unique name for this scroll bar.     * @return A unique name for this scroll bar.
671     */     */
672    String generateName ()    String generateName()
673    {    {
674      return "scrollbar" + getUniqueLong ();      return "scrollbar" + getUniqueLong();
675    }    }
676    
677    private static synchronized long getUniqueLong ()    private static synchronized long getUniqueLong()
678    {    {
679      return next_scrollbar_number++;      return next_scrollbar_number++;
680    }    }
681      
682    /**    /**
683     * This class provides accessibility support for the     * This class provides accessibility support for the
684     * scrollbar.     * scrollbar.
# Line 784  paramString() Line 687  paramString()
687     * @author Andrew John Hughes (gnu_andrew@member.fsf.org)     * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
688     */     */
689    protected class AccessibleAWTScrollBar extends AccessibleAWTComponent    protected class AccessibleAWTScrollBar extends AccessibleAWTComponent
690          implements AccessibleValue      implements AccessibleValue
691    {    {
   
692      /**      /**
693       * Serialization constant to match JDK 1.5       * Serialization constant to match JDK 1.5
694       */       */
# Line 796  paramString() Line 698  paramString()
698       * Returns the role of this accessible object.       * Returns the role of this accessible object.
699       *       *
700       * @return the instance of <code>AccessibleRole</code>,       * @return the instance of <code>AccessibleRole</code>,
701       *         which describes this object.       * which describes this object.
702         *
703       * @see javax.accessibility.AccessibleRole       * @see javax.accessibility.AccessibleRole
704       */       */
705      public AccessibleRole getAccessibleRole()      public AccessibleRole getAccessibleRole()
706      {      {
707        return AccessibleRole.SCROLL_BAR;        return AccessibleRole.SCROLL_BAR;
708      }      }
709        
710      /**      /**
711       * Returns the state set of this accessible object.       * Returns the state set of this accessible object.
712       *       *
713       * @return a set of <code>AccessibleState</code>s       * @return a set of <code>AccessibleState</code>s which
714       *         which represent the current state of the       * represent the current state of the accessible object.
715       *         accessible object.       *
716       * @see javax.accessibility.AccessibleState       * @see javax.accessibility.AccessibleState
717       * @see javax.accessibility.AccessibleStateSet       * @see javax.accessibility.AccessibleStateSet
718       */       */
# Line 817  paramString() Line 720  paramString()
720      {      {
721        AccessibleStateSet states = super.getAccessibleStateSet();        AccessibleStateSet states = super.getAccessibleStateSet();
722        if (getOrientation() == HORIZONTAL)        if (getOrientation() == HORIZONTAL)
723          states.add(AccessibleState.HORIZONTAL);          states.add(AccessibleState.HORIZONTAL);
724        else        else
725          states.add(AccessibleState.VERTICAL);          states.add(AccessibleState.VERTICAL);
726        if (getValueIsAdjusting())        if (getValueIsAdjusting())
727          states.add(AccessibleState.BUSY);          states.add(AccessibleState.BUSY);
728        return states;        return states;
729      }      }
730        
731      /**      /**
732       * Returns an implementation of the <code>AccessibleValue</code>       * Returns an implementation of the <code>AccessibleValue</code>
733       * interface for this accessible object.  In this case, the       * interface for this accessible object.  In this case, the
# Line 833  paramString() Line 736  paramString()
736       * the context.       * the context.
737       *       *
738       * @return the accessible value associated with this context.       * @return the accessible value associated with this context.
739         *
740       * @see javax.accessibility.AccessibleValue       * @see javax.accessibility.AccessibleValue
741       */       */
742      public AccessibleValue getAccessibleValue()      public AccessibleValue getAccessibleValue()
# Line 847  paramString() Line 751  paramString()
751       * object.       * object.
752       *       *
753       * @return the numeric value of this scrollbar.       * @return the numeric value of this scrollbar.
754         *
755       * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()       * @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
756       */       */
757      public Number getCurrentAccessibleValue()      public Number getCurrentAccessibleValue()
# Line 861  paramString() Line 766  paramString()
766       * true.       * true.
767       *       *
768       * @param number the new accessible value.       * @param number the new accessible value.
769         *
770       * @return true if the value was set.       * @return true if the value was set.
771         *
772       * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)       * @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
773       */       */
774      public boolean setCurrentAccessibleValue(Number number)      public boolean setCurrentAccessibleValue(Number number)
# Line 877  paramString() Line 784  paramString()
784       * object.       * object.
785       *       *
786       * @return the minimum value of this scrollbar.       * @return the minimum value of this scrollbar.
787         *
788       * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()       * @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
789       */       */
790      public Number getMinimumAccessibleValue()      public Number getMinimumAccessibleValue()
# Line 891  paramString() Line 799  paramString()
799       * object.       * object.
800       *       *
801       * @return the maximum value of this scrollbar.       * @return the maximum value of this scrollbar.
802         *
803       * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()       * @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
804       */       */
805      public Number getMaximumAccessibleValue()      public Number getMaximumAccessibleValue()
# Line 898  paramString() Line 807  paramString()
807        return new Integer(getMaximum());        return new Integer(getMaximum());
808      }      }
809    }    }
810      
811    /**    /**
812     * Gets the AccessibleContext associated with this <code>Scrollbar</code>.     * Gets the AccessibleContext associated with this <code>Scrollbar</code>.
813     * The context is created, if necessary.     * The context is created, if necessary.
# Line 910  paramString() Line 819  paramString()
819      /* Create the context if this is the first request */      /* Create the context if this is the first request */
820      if (accessibleContext == null)      if (accessibleContext == null)
821        accessibleContext = new AccessibleAWTScrollBar();        accessibleContext = new AccessibleAWTScrollBar();
822        
823      return accessibleContext;      return accessibleContext;
824    }    }
825    }
 } // class Scrollbar  
   

Legend:
Removed from v.1.18.2.5  
changed lines
  Added in v.1.18.2.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26