001    /* ScrollPaneAdjustable.java -- Scrollbars for a ScrollPane
002       Copyright (C) 1999 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package java.awt;
040    
041    import java.awt.event.AdjustmentListener;
042    import java.io.Serializable;
043    
044    /**
045     * Need this class since the serialization spec for ScrollPane
046     * uses it.
047     *
048     * @author Aaron M. Renn (arenn@urbanophile.com)
049     * @since 1.4
050     */
051    public class ScrollPaneAdjustable
052      implements Adjustable, Serializable
053    {
054      private static final long serialVersionUID = -3359745691033257079L;
055    
056      ScrollPane sp;
057      int orientation;
058      int value;
059      int minimum;
060      int maximum;
061      int visibleAmount;
062      int unitIncrement = 1;
063      int blockIncrement = 1;
064      AdjustmentListener adjustmentListener;
065    
066      private transient boolean valueIsAdjusting = false;
067    
068      ScrollPaneAdjustable (ScrollPane sp, int orientation)
069      {
070        this.sp = sp;
071        this.orientation = orientation;
072      }
073    
074      ScrollPaneAdjustable (ScrollPane sp, int orientation, int value, int minimum,
075                            int maximum, int visibleAmount, int unitIncrement,
076                            int blockIncrement)
077      {
078        this.sp = sp;
079        this.orientation = orientation;
080        this.value = value;
081        this.minimum = minimum;
082        this.maximum = maximum;
083        this.visibleAmount = visibleAmount;
084        this.unitIncrement = unitIncrement;
085        this.blockIncrement = blockIncrement;
086      }
087    
088      public void addAdjustmentListener (AdjustmentListener listener)
089      {
090        if (listener == null)
091          return;
092        adjustmentListener = AWTEventMulticaster.add (adjustmentListener, listener);
093      }
094    
095      public void removeAdjustmentListener (AdjustmentListener listener)
096      {
097        if (listener == null)
098          return;
099        adjustmentListener = AWTEventMulticaster.remove (adjustmentListener, listener);
100      }
101    
102      public AdjustmentListener[] getAdjustmentListeners ()
103      {
104        return (AdjustmentListener[]) AWTEventMulticaster.getListeners
105                                   (adjustmentListener, AdjustmentListener.class);
106      }
107    
108      public int getBlockIncrement ()
109      {
110        return blockIncrement;
111      }
112    
113      public int getMaximum ()
114      {
115        return maximum;
116      }
117    
118      public int getMinimum ()
119      {
120        return minimum;
121      }
122    
123      public int getOrientation ()
124      {
125        return orientation;
126      }
127    
128      public int getUnitIncrement ()
129      {
130        return unitIncrement;
131      }
132    
133      public int getValue ()
134      {
135        return value;
136      }
137    
138      public int getVisibleAmount ()
139      {
140        return visibleAmount;
141      }
142    
143      public void setBlockIncrement (int blockIncrement)
144      {
145        this.blockIncrement = blockIncrement;
146      }
147    
148      /**
149       * This method should never be called.
150       *
151       * @param maximum The maximum value to be set.
152       * @throws AWTError Always throws this error when called.
153       */
154      public void setMaximum (int maximum) throws AWTError
155      {
156        throw new AWTError("Can be set by scrollpane only");
157      }
158    
159      /**
160       * This method should never be called.
161       *
162       * @param minimum The minimum value to be set.
163       * @throws AWTError Always throws this error when called.
164       */
165      public void setMinimum (int minimum)
166      {
167        throw new AWTError("Can be set by scrollpane only");
168      }
169    
170      public void setUnitIncrement (int unitIncrement)
171      {
172        this.unitIncrement = unitIncrement;
173      }
174    
175      public void setValue (int value)
176      {
177        this.value = value;
178    
179        if (value < minimum)
180          minimum = value;
181    
182        if (value > maximum)
183          maximum = value;
184      }
185    
186      /**
187       * This method should never be called.
188       *
189       * @param visibleAmount The visible amount to be set.
190       * @throws AWTError Always throws this error when called.
191       */
192      public void setVisibleAmount (int visibleAmount)
193      {
194        throw new AWTError("Can be set by scrollpane only");
195      }
196    
197      public String paramString ()
198      {
199        return paramStringHelper()
200             + ",[" + getMinimum() + ".." + getMaximum()
201             + "],val=" + getValue()
202             + ",vis=" + getVisibleAmount()
203             + ",unit=" + getUnitIncrement()
204             + ",block=" + getBlockIncrement()
205             + ",isAdjusting=" + valueIsAdjusting;
206      }
207    
208      private String paramStringHelper()
209      {
210        if (getOrientation() == HORIZONTAL)
211          return "horizontal";
212        else
213          return "vertical";
214      }
215    
216      public String toString()
217      {
218        return getClass().getName() + "[" + paramString() + "]";
219      }
220    
221      /**
222       * Returns true if the value is in the process of changing.
223       *
224       * @since 1.4
225       */
226      public boolean getValueIsAdjusting ()
227      {
228        return valueIsAdjusting;
229      }
230    
231      /**
232       * Sets the value of valueIsAdjusting.
233       *
234       * @since 1.4
235       */
236      public void setValueIsAdjusting (boolean valueIsAdjusting)
237      {
238        this.valueIsAdjusting = valueIsAdjusting;
239      }
240    
241    } // class ScrollPaneAdjustable