]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ui/widgets/ScrolledPage.java
Prepare next development cycle
[lgpl/argeo-commons.git] / ui / widgets / ScrolledPage.java
1 package org.argeo.cms.ui.widgets;
2
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.custom.ScrolledComposite;
5 import org.eclipse.swt.events.ControlEvent;
6 import org.eclipse.swt.graphics.Point;
7 import org.eclipse.swt.graphics.Rectangle;
8 import org.eclipse.swt.widgets.Composite;
9
10 /**
11 * A composite that can be scrolled vertically. It wraps a
12 * {@link ScrolledComposite} (and is being wrapped by it), simplifying its
13 * configuration.
14 */
15 public class ScrolledPage extends Composite {
16 private static final long serialVersionUID = 1593536965663574437L;
17
18 private ScrolledComposite scrolledComposite;
19
20 public ScrolledPage(Composite parent, int style) {
21 this(parent, style, false);
22 }
23
24 public ScrolledPage(Composite parent, int style, boolean alwaysShowScroll) {
25 super(createScrolledComposite(parent, alwaysShowScroll), style);
26 scrolledComposite = (ScrolledComposite) getParent();
27 scrolledComposite.setContent(this);
28
29 scrolledComposite.setExpandVertical(true);
30 scrolledComposite.setExpandHorizontal(true);
31 scrolledComposite.addControlListener(new ScrollControlListener());
32 }
33
34 private static ScrolledComposite createScrolledComposite(Composite parent, boolean alwaysShowScroll) {
35 ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL);
36 scrolledComposite.setAlwaysShowScrollBars(alwaysShowScroll);
37 return scrolledComposite;
38 }
39
40 @Override
41 public void layout(boolean changed, boolean all) {
42 updateScroll();
43 super.layout(changed, all);
44 }
45
46 protected void updateScroll() {
47 Rectangle r = scrolledComposite.getClientArea();
48 Point preferredSize = computeSize(r.width, SWT.DEFAULT);
49 scrolledComposite.setMinHeight(preferredSize.y);
50 }
51
52 // public ScrolledComposite getScrolledComposite() {
53 // return this.scrolledComposite;
54 // }
55
56 /** Set it on the wrapping scrolled composite */
57 @Override
58 public void setLayoutData(Object layoutData) {
59 scrolledComposite.setLayoutData(layoutData);
60 }
61
62 private class ScrollControlListener extends org.eclipse.swt.events.ControlAdapter {
63 private static final long serialVersionUID = -3586986238567483316L;
64
65 public void controlResized(ControlEvent e) {
66 updateScroll();
67 }
68 }
69 }