View Javadoc

1   /***
2    * Redistribution  and use  in source  and binary  forms, with  or without
3    * modification, are permitted provided  that the following conditions are
4    * met :
5    *
6    * . Redistributions  of  source  code  must  retain  the  above copyright
7    *   notice, this list of conditions and the following disclaimer.
8    *
9    * . Redistributions in  binary form  must reproduce  the above  copyright
10   *   notice, this list of conditions  and the following disclaimer in  the
11   *   documentation and/or other materials provided with the distribution.
12   *
13   * . The name of the author may not be used to endorse or promote products
14   *   derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS  PROVIDED BY THE  AUTHOR ``AS IS''  AND ANY EXPRESS  OR
17   * IMPLIED  WARRANTIES,  INCLUDING,  BUT   NOT  LIMITED  TO,  THE   IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE ARE
19   * DISCLAIMED.  IN NO  EVENT SHALL  THE AUTHOR  BE LIABLE  FOR ANY  DIRECT,
20   * INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL  DAMAGES
21   * (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT OF  SUBSTITUTE  GOODS OR
22   * SERVICES;  LOSS  OF USE,  DATA,  OR PROFITS;  OR  BUSINESS INTERRUPTION)
23   * HOWEVER CAUSED  AND ON  ANY THEORY  OF LIABILITY,  WHETHER IN  CONTRACT,
24   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE, EVEN  IF  ADVISED OF  THE
26   * POSSIBILITY OF SUCH DAMAGE.
27   *
28   * $Id$
29   */
30  
31  package palmed.edit.scrollbar;
32  
33  import javax.microedition.lcdui.Graphics;
34  import javax.microedition.lcdui.Item;
35  import palmed.edit.util.Coordinate;
36  import palmed.edit.view.IScrollView;
37  import palmed.edit.view.IViewport;
38  import palmed.ui.IComponent;
39  
40  /***
41   * This class provides a vertical scrollbar.
42   *
43   * @author Mathieu Champlon
44   * @version $Revision$ $Date$
45   */
46  public final class VerticalScrollbar implements IScrollbar, IScrollable, IDrawer, IScrollView, IComponent
47  {
48      /***
49       * The scrollbar internals.
50       */
51      private final Scrollbar scrollbar_;
52      /***
53       * The viewport.
54       */
55      private final IViewport viewport_;
56  
57      /***
58       * Create a vertical scrollbar.
59       *
60       * @param viewport the viewport to manage
61       */
62      public VerticalScrollbar( final IViewport viewport )
63      {
64          if( viewport == null )
65              throw new IllegalArgumentException( "parameter 'viewport' is null" );
66          scrollbar_ = new Scrollbar( this, this );
67          viewport_ = viewport;
68          viewport_.register( this );
69      }
70  
71      /***
72       * {@inheritDoc}
73       */
74      public void paint( final Graphics g )
75      {
76          scrollbar_.paint( g );
77      }
78  
79      /***
80       * {@inheritDoc}
81       */
82      public void update( final int visible, final int max )
83      {
84          scrollbar_.update( visible, max );
85      }
86  
87      /***
88       * {@inheritDoc}
89       */
90      public void resize( final int width, final int height )
91      {
92          scrollbar_.resize( height );
93      }
94  
95      /***
96       * {@inheritDoc}
97       */
98      public boolean click( final int x, final int y )
99      {
100         scrollbar_.click( y );
101         return true;
102     }
103 
104     /***
105      * {@inheritDoc}
106      */
107     public void drag( final int x, final int y )
108     {
109         scrollbar_.drag( y );
110     }
111 
112     /***
113      * {@inheritDoc}
114      */
115     public void unclick( final int x, final int y )
116     {
117         scrollbar_.unclick();
118     }
119 
120     /***
121      * {@inheritDoc}
122      */
123     public void scrolled( final Coordinate position )
124     {
125         scrollbar_.scroll( position.y_ );
126     }
127 
128     /***
129      * {@inheritDoc}
130      */
131     public void scroll( final int steps )
132     {
133         viewport_.scroll( 0, steps );
134     }
135 
136     /***
137      * {@inheritDoc}
138      */
139     public void drawArrow( final Graphics g, final int end, final int from, final int to )
140     {
141         g.fillTriangle( 0, from, end / 2, to, end, from );
142     }
143 
144     /***
145      * {@inheritDoc}
146      */
147     public void drawBody( final Graphics g, final int start, final int end, final int from, final int to )
148     {
149         g.setStrokeStyle( Graphics.DOTTED );
150         for( int position = start; position <= end; ++position )
151             g.drawLine( position, from, position, to );
152     }
153 
154     /***
155      * {@inheritDoc}
156      */
157     public void drawCursor( final Graphics g, final int start, final int width, final int from, final int length )
158     {
159         g.fillRect( start, from, width, length );
160     }
161 
162     /***
163      * {@inheritDoc}
164      */
165     public void drawBackground( final Graphics g, final int size, final int width )
166     {
167         g.fillRect( 0, 0, width, size );
168     }
169 
170     /***
171      * {@inheritDoc}
172      */
173     public int getLayout()
174     {
175         return Item.LAYOUT_VEXPAND;
176     }
177 
178     /***
179      * {@inheritDoc}
180      */
181     public int getWidth()
182     {
183         return scrollbar_.getWidth();
184     }
185 
186     /***
187      * {@inheritDoc}
188      */
189     public int getHeight()
190     {
191         return scrollbar_.getSize();
192     }
193 }