Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package org.litesoft.GWT.client.widgets;

import java.util.*;

import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;

public class SizeableScrollPanel extends AbstractSizeableComposite implements SourcesScrollEvents,
                                                                              ScrollListener,
                                                                              SizeableSingleWidgetContainer
{
    private ScrollListenerCollection scrollListeners;

    private ScrollPanel mScrollPanel = new ScrollPanel();

    /**
     * Creates an empty SizeableScrollPanel.
     */
    public SizeableScrollPanel()
    {
        mScrollPanel.setWidth( "200" );
        mScrollPanel.setHeight( "160" );
        initWidget( new ConstrainingSizeableOuterLayers( mScrollPanel, "LayoutSizeableScrollPanel" ) );

        DOM.setStyleAttribute( mScrollPanel.getElement(), "overflow", "" ); // remove their overlow
        mScrollPanel.addStyleName( AbstractSizeableHelper.LAYOUT_OVERFLOW_AUTO ); // add our overflow!

        LLstretchable();
    }

    /**
     * Creates a new SizeableScrollPanel with the given child widget.
     *
     * @param child the widget to be wrapped by the scroll panel
     */
    public SizeableScrollPanel( Widget child )
    {
        this();
        mScrollPanel.setWidget( child );
    }

    public SizeableScrollPanel style( String pStyleName )
    {
        addStyleName( pStyleName );
        return this;
    }

    public void onScroll( Widget widget, int scrollLeft, int scrollTop )
    {
        if ( scrollListeners != null )
        {
            scrollListeners.fireScroll( this, scrollLeft, scrollTop );
        }
    }

    public void addScrollListener( ScrollListener listener )
    {
        if ( scrollListeners == null )
        {
            scrollListeners = new ScrollListenerCollection();
            mScrollPanel.addScrollListener( this );
        }
        //noinspection unchecked
        scrollListeners.add( listener );
    }

    /**
     * Ensures that the specified item is visible, by adjusting the panel's scroll position.
     *
     * @param item the item whose visibility is to be ensured
     */
    public void ensureVisible( UIObject item )
    {
        mScrollPanel.ensureVisible( item );
    }

    /**
     * Gets the horizontal scroll position.
     *
     * @return the horizontal scroll position, in pixels
     */
    public int getHorizontalScrollPosition()
    {
        return mScrollPanel.getHorizontalScrollPosition();
    }

    /**
     * Gets the vertical scroll position.
     *
     * @return the vertical scroll position, in pixels
     */
    public int getScrollPosition()
    {
        return mScrollPanel.getScrollPosition();
    }

    public void removeScrollListener( ScrollListener listener )
    {
        if ( scrollListeners != null )
        {
            scrollListeners.remove( listener );
            if ( scrollListeners.isEmpty() )
            {
                scrollListeners = null;
                mScrollPanel.removeScrollListener( this );
            }
        }
    }

    /**
     * Sets the horizontal scroll position.
     *
     * @param position the new horizontal scroll position, in pixels
     */
    public void setHorizontalScrollPosition( int position )
    {
        mScrollPanel.setHorizontalScrollPosition( position );
    }

    /**
     * Sets the vertical scroll position.
     *
     * @param position the new vertical scroll position, in pixels
     */
    public void setScrollPosition( int position )
    {
        mScrollPanel.setScrollPosition( position );
    }

    /**
     * Adds a widget to this panel.
     *
     * @param w the child widget to be added
     */
    public void add( Widget w )
    {
        mScrollPanel.add( w );
    }

    /**
     * Gets the panel's child widget.
     *
     * @return the child widget, or <code>null</code> if none is present
     */
    public Widget getWidget()
    {
        return mScrollPanel.getWidget();
    }

    public Iterator<Widget> iterator()
    {
        return mScrollPanel.iterator();
    }

    public boolean remove( Widget w )
    {
        return mScrollPanel.remove( w );
    }

    /**
     * Sets this panel's widget. Any existing child widget will be removed.
     *
     * @param pWidget
     */
    public void setWidget( Widget pWidget )
    {
        mScrollPanel.setWidget( pWidget );
    }
    
    public void clear()
    {
    	mScrollPanel.clear();
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/SizeableScrollPanel.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000