|
@@ -1,163 +1,163 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
5 |
|
- |
|
6 |
|
- |
import com.google.gwt.user.client.ui.*; |
7 |
|
- |
|
8 |
|
- |
import java.util.*; |
9 |
|
- |
|
10 |
|
- |
public class SizeableScrollPanel extends AbstractSizeableComposite implements SourcesScrollEvents, |
11 |
|
- |
ScrollListener, |
12 |
|
- |
SizeableSingleWidgetContainer { |
13 |
|
- |
private ScrollListenerCollection scrollListeners; |
14 |
|
- |
|
15 |
|
- |
protected ScrollPanel mScrollPanel = new ScrollPanel(); |
16 |
|
- |
|
17 |
|
- |
/** |
18 |
|
- |
* Creates an empty SizeableScrollPanel. |
19 |
|
- |
*/ |
20 |
|
- |
public SizeableScrollPanel() { |
21 |
|
- |
mScrollPanel.setWidth( "200" ); |
22 |
|
- |
mScrollPanel.setHeight( "160" ); |
23 |
|
- |
initWidget( new ConstrainingSizeableOuterLayers( mScrollPanel, "LayoutSizeableScrollPanel" ) ); |
24 |
|
- |
|
25 |
|
- |
CommonElementHelper.setOverflowAuto( mScrollPanel.getElement() ); // remove their overlow |
26 |
|
- |
mScrollPanel.addStyleName( AbstractSizeableHelper.LAYOUT_OVERFLOW_AUTO ); // add our overflow! |
27 |
|
- |
|
28 |
|
- |
LLstretchable(); |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
/** |
32 |
|
- |
* Creates a new SizeableScrollPanel with the given child widget. |
33 |
|
- |
* |
34 |
|
- |
* @param child the widget to be wrapped by the scroll panel |
35 |
|
- |
*/ |
36 |
|
- |
public SizeableScrollPanel( Widget child ) { |
37 |
|
- |
this(); |
38 |
|
- |
mScrollPanel.setWidget( child ); |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
public SizeableScrollPanel style( String pStyleName ) { |
42 |
|
- |
addStyleName( pStyleName ); |
43 |
|
- |
return this; |
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
@Override |
47 |
|
- |
public void onScroll( Widget widget, int scrollLeft, int scrollTop ) { |
48 |
|
- |
if ( scrollListeners != null ) { |
49 |
|
- |
scrollListeners.fireScroll( this, scrollLeft, scrollTop ); |
50 |
|
- |
} |
51 |
|
- |
} |
52 |
|
- |
|
53 |
|
- |
@Override |
54 |
|
- |
public void addScrollListener( ScrollListener listener ) { |
55 |
|
- |
if ( scrollListeners == null ) { |
56 |
|
- |
scrollListeners = new ScrollListenerCollection(); |
57 |
|
- |
mScrollPanel.addScrollListener( this ); |
58 |
|
- |
} |
59 |
|
- |
//noinspection unchecked |
60 |
|
- |
scrollListeners.add( listener ); |
61 |
|
- |
} |
62 |
|
- |
|
63 |
|
- |
/** |
64 |
|
- |
* Ensures that the specified item is visible, by adjusting the panel's scroll position. |
65 |
|
- |
* |
66 |
|
- |
* @param item the item whose visibility is to be ensured |
67 |
|
- |
*/ |
68 |
|
- |
public void ensureVisible( UIObject item ) { |
69 |
|
- |
mScrollPanel.ensureVisible( item ); |
70 |
|
- |
} |
71 |
|
- |
|
72 |
|
- |
/** |
73 |
|
- |
* Gets the horizontal scroll position. |
74 |
|
- |
* |
75 |
|
- |
* @return the horizontal scroll position, in pixels |
76 |
|
- |
*/ |
77 |
|
- |
public int getHorizontalScrollPosition() { |
78 |
|
- |
return mScrollPanel.getHorizontalScrollPosition(); |
79 |
|
- |
} |
80 |
|
- |
|
81 |
|
- |
/** |
82 |
|
- |
* Gets the vertical scroll position. |
83 |
|
- |
* |
84 |
|
- |
* @return the vertical scroll position, in pixels |
85 |
|
- |
*/ |
86 |
|
- |
public int getScrollPosition() { |
87 |
|
- |
return mScrollPanel.getScrollPosition(); |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
@Override |
91 |
|
- |
public void removeScrollListener( ScrollListener listener ) { |
92 |
|
- |
if ( scrollListeners != null ) { |
93 |
|
- |
scrollListeners.remove( listener ); |
94 |
|
- |
if ( scrollListeners.isEmpty() ) { |
95 |
|
- |
scrollListeners = null; |
96 |
|
- |
mScrollPanel.removeScrollListener( this ); |
97 |
|
- |
} |
98 |
|
- |
} |
99 |
|
- |
} |
100 |
|
- |
|
101 |
|
- |
/** |
102 |
|
- |
* Sets the horizontal scroll position. |
103 |
|
- |
* |
104 |
|
- |
* @param position the new horizontal scroll position, in pixels |
105 |
|
- |
*/ |
106 |
|
- |
public void setHorizontalScrollPosition( int position ) { |
107 |
|
- |
mScrollPanel.setHorizontalScrollPosition( position ); |
108 |
|
- |
} |
109 |
|
- |
|
110 |
|
- |
/** |
111 |
|
- |
* Sets the vertical scroll position. |
112 |
|
- |
* |
113 |
|
- |
* @param position the new vertical scroll position, in pixels |
114 |
|
- |
*/ |
115 |
|
- |
public void setScrollPosition( int position ) { |
116 |
|
- |
mScrollPanel.setScrollPosition( position ); |
117 |
|
- |
} |
118 |
|
- |
|
119 |
|
- |
/** |
120 |
|
- |
* Adds a widget to this panel. |
121 |
|
- |
* |
122 |
|
- |
* @param w the child widget to be added |
123 |
|
- |
*/ |
124 |
|
- |
@Override |
125 |
|
- |
public void add( Widget w ) { |
126 |
|
- |
mScrollPanel.add( w ); |
127 |
|
- |
} |
128 |
|
- |
|
129 |
|
- |
/** |
130 |
|
- |
* Gets the panel's child widget. |
131 |
|
- |
* |
132 |
|
- |
* @return the child widget, or <code>null</code> if none is present |
133 |
|
- |
*/ |
134 |
|
- |
@Override |
135 |
|
- |
public Widget getWidget() { |
136 |
|
- |
return mScrollPanel.getWidget(); |
137 |
|
- |
} |
138 |
|
- |
|
139 |
|
- |
@Override |
140 |
|
- |
public Iterator<Widget> iterator() { |
141 |
|
- |
return mScrollPanel.iterator(); |
142 |
|
- |
} |
143 |
|
- |
|
144 |
|
- |
@Override |
145 |
|
- |
public boolean remove( Widget w ) { |
146 |
|
- |
return mScrollPanel.remove( w ); |
147 |
|
- |
} |
148 |
|
- |
|
149 |
|
- |
/** |
150 |
|
- |
* Sets this panel's widget. Any existing child widget will be removed. |
151 |
|
- |
* |
152 |
|
- |
* @param pWidget |
153 |
|
- |
*/ |
154 |
|
- |
@Override |
155 |
|
- |
public void setWidget( Widget pWidget ) { |
156 |
|
- |
mScrollPanel.setWidget( pWidget ); |
157 |
|
- |
} |
158 |
|
- |
|
159 |
|
- |
@Override |
160 |
|
- |
public void clear() { |
161 |
|
- |
mScrollPanel.clear(); |
162 |
|
- |
} |
163 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
5 |
+ |
|
|
6 |
+ |
import com.google.gwt.user.client.ui.*; |
|
7 |
+ |
|
|
8 |
+ |
import java.util.*; |
|
9 |
+ |
|
|
10 |
+ |
public class SizeableScrollPanel extends AbstractSizeableComposite implements SourcesScrollEvents, |
|
11 |
+ |
ScrollListener, |
|
12 |
+ |
SizeableSingleWidgetContainer { |
|
13 |
+ |
private ScrollListenerCollection scrollListeners; |
|
14 |
+ |
|
|
15 |
+ |
protected ScrollPanel mScrollPanel = new ScrollPanel(); |
|
16 |
+ |
|
|
17 |
+ |
/** |
|
18 |
+ |
* Creates an empty SizeableScrollPanel. |
|
19 |
+ |
*/ |
|
20 |
+ |
public SizeableScrollPanel() { |
|
21 |
+ |
mScrollPanel.setWidth( "200" ); |
|
22 |
+ |
mScrollPanel.setHeight( "160" ); |
|
23 |
+ |
initWidget( new ConstrainingSizeableOuterLayers( mScrollPanel, "LayoutSizeableScrollPanel" ) ); |
|
24 |
+ |
|
|
25 |
+ |
CommonElementHelper.setOverflowAuto( mScrollPanel.getElement() ); // remove their overlow |
|
26 |
+ |
mScrollPanel.addStyleName( AbstractSizeableHelper.LAYOUT_OVERFLOW_AUTO ); // add our overflow! |
|
27 |
+ |
|
|
28 |
+ |
LLstretchable(); |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
/** |
|
32 |
+ |
* Creates a new SizeableScrollPanel with the given child widget. |
|
33 |
+ |
* |
|
34 |
+ |
* @param child the widget to be wrapped by the scroll panel |
|
35 |
+ |
*/ |
|
36 |
+ |
public SizeableScrollPanel( Widget child ) { |
|
37 |
+ |
this(); |
|
38 |
+ |
mScrollPanel.setWidget( child ); |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
public SizeableScrollPanel style( String pStyleName ) { |
|
42 |
+ |
addStyleName( pStyleName ); |
|
43 |
+ |
return this; |
|
44 |
+ |
} |
|
45 |
+ |
|
|
46 |
+ |
@Override |
|
47 |
+ |
public void onScroll( Widget widget, int scrollLeft, int scrollTop ) { |
|
48 |
+ |
if ( scrollListeners != null ) { |
|
49 |
+ |
scrollListeners.fireScroll( this, scrollLeft, scrollTop ); |
|
50 |
+ |
} |
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
@Override |
|
54 |
+ |
public void addScrollListener( ScrollListener listener ) { |
|
55 |
+ |
if ( scrollListeners == null ) { |
|
56 |
+ |
scrollListeners = new ScrollListenerCollection(); |
|
57 |
+ |
mScrollPanel.addScrollListener( this ); |
|
58 |
+ |
} |
|
59 |
+ |
//noinspection unchecked |
|
60 |
+ |
scrollListeners.add( listener ); |
|
61 |
+ |
} |
|
62 |
+ |
|
|
63 |
+ |
/** |
|
64 |
+ |
* Ensures that the specified item is visible, by adjusting the panel's scroll position. |
|
65 |
+ |
* |
|
66 |
+ |
* @param item the item whose visibility is to be ensured |
|
67 |
+ |
*/ |
|
68 |
+ |
public void ensureVisible( UIObject item ) { |
|
69 |
+ |
mScrollPanel.ensureVisible( item ); |
|
70 |
+ |
} |
|
71 |
+ |
|
|
72 |
+ |
/** |
|
73 |
+ |
* Gets the horizontal scroll position. |
|
74 |
+ |
* |
|
75 |
+ |
* @return the horizontal scroll position, in pixels |
|
76 |
+ |
*/ |
|
77 |
+ |
public int getHorizontalScrollPosition() { |
|
78 |
+ |
return mScrollPanel.getHorizontalScrollPosition(); |
|
79 |
+ |
} |
|
80 |
+ |
|
|
81 |
+ |
/** |
|
82 |
+ |
* Gets the vertical scroll position. |
|
83 |
+ |
* |
|
84 |
+ |
* @return the vertical scroll position, in pixels |
|
85 |
+ |
*/ |
|
86 |
+ |
public int getScrollPosition() { |
|
87 |
+ |
return mScrollPanel.getScrollPosition(); |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
@Override |
|
91 |
+ |
public void removeScrollListener( ScrollListener listener ) { |
|
92 |
+ |
if ( scrollListeners != null ) { |
|
93 |
+ |
scrollListeners.remove( listener ); |
|
94 |
+ |
if ( scrollListeners.isEmpty() ) { |
|
95 |
+ |
scrollListeners = null; |
|
96 |
+ |
mScrollPanel.removeScrollListener( this ); |
|
97 |
+ |
} |
|
98 |
+ |
} |
|
99 |
+ |
} |
|
100 |
+ |
|
|
101 |
+ |
/** |
|
102 |
+ |
* Sets the horizontal scroll position. |
|
103 |
+ |
* |
|
104 |
+ |
* @param position the new horizontal scroll position, in pixels |
|
105 |
+ |
*/ |
|
106 |
+ |
public void setHorizontalScrollPosition( int position ) { |
|
107 |
+ |
mScrollPanel.setHorizontalScrollPosition( position ); |
|
108 |
+ |
} |
|
109 |
+ |
|
|
110 |
+ |
/** |
|
111 |
+ |
* Sets the vertical scroll position. |
|
112 |
+ |
* |
|
113 |
+ |
* @param position the new vertical scroll position, in pixels |
|
114 |
+ |
*/ |
|
115 |
+ |
public void setScrollPosition( int position ) { |
|
116 |
+ |
mScrollPanel.setScrollPosition( position ); |
|
117 |
+ |
} |
|
118 |
+ |
|
|
119 |
+ |
/** |
|
120 |
+ |
* Adds a widget to this panel. |
|
121 |
+ |
* |
|
122 |
+ |
* @param w the child widget to be added |
|
123 |
+ |
*/ |
|
124 |
+ |
@Override |
|
125 |
+ |
public void add( Widget w ) { |
|
126 |
+ |
mScrollPanel.add( w ); |
|
127 |
+ |
} |
|
128 |
+ |
|
|
129 |
+ |
/** |
|
130 |
+ |
* Gets the panel's child widget. |
|
131 |
+ |
* |
|
132 |
+ |
* @return the child widget, or <code>null</code> if none is present |
|
133 |
+ |
*/ |
|
134 |
+ |
@Override |
|
135 |
+ |
public Widget getWidget() { |
|
136 |
+ |
return mScrollPanel.getWidget(); |
|
137 |
+ |
} |
|
138 |
+ |
|
|
139 |
+ |
@Override |
|
140 |
+ |
public Iterator<Widget> iterator() { |
|
141 |
+ |
return mScrollPanel.iterator(); |
|
142 |
+ |
} |
|
143 |
+ |
|
|
144 |
+ |
@Override |
|
145 |
+ |
public boolean remove( Widget w ) { |
|
146 |
+ |
return mScrollPanel.remove( w ); |
|
147 |
+ |
} |
|
148 |
+ |
|
|
149 |
+ |
/** |
|
150 |
+ |
* Sets this panel's widget. Any existing child widget will be removed. |
|
151 |
+ |
* |
|
152 |
+ |
* @param pWidget |
|
153 |
+ |
*/ |
|
154 |
+ |
@Override |
|
155 |
+ |
public void setWidget( Widget pWidget ) { |
|
156 |
+ |
mScrollPanel.setWidget( pWidget ); |
|
157 |
+ |
} |
|
158 |
+ |
|
|
159 |
+ |
@Override |
|
160 |
+ |
public void clear() { |
|
161 |
+ |
mScrollPanel.clear(); |
|
162 |
+ |
} |
|
163 |
+ |
} |