Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0ce636b95737d559eb3c259e2565a59ae40858b3 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2009 Tilera Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     William R. Swanson (Tilera Corporation)
 *******************************************************************************/

package org.eclipse.cdt.visualizer.ui.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;


// ---------------------------------------------------------------------------
// ScrollPanel
// ---------------------------------------------------------------------------

/**
 * Container panel that adds scrollbar(s) to a content control.
 */
public class ScrollPanel extends ScrolledComposite
{
	// --- constructors/destructors ---
	
	/** Constructor. */
	public ScrollPanel(Composite parent)
	{
		this(parent, null, true, true);
	}
	
	/** Constructor. */
	public ScrollPanel(Composite parent, boolean hscrollbar, boolean vscrollbar)
	{
		this(parent, null, hscrollbar, vscrollbar);
	}
	
	/** Constructor. */
	public ScrollPanel(Composite parent, Control contentControl, boolean hscrollbar, boolean vscrollbar)
	{
		super(parent, ((hscrollbar) ? SWT.H_SCROLL : SWT.NONE) |
					  ((vscrollbar) ? SWT.V_SCROLL : SWT.NONE));
		initScrollPanel(contentControl, hscrollbar, vscrollbar);
	}
	
	/** Dispose method. */
	public void dispose() {
		cleanupScrollPanel();
		super.dispose();
	}

	/** Overridden to permit subclassing */
	protected void checkSubclass() {
		// do nothing -- superclass implementation throws a "Subclassing not allowed" exception
	}
	
	
	// --- init methods ---
	
	/** Initializes control */
	protected void initScrollPanel(Control contentControl, boolean hscrollbar, boolean vscrollbar) {
     setMinSize(0,0);
     setShowFocusedControl(true);
     // If user doesn't want either scrollbar, we'll auto-size in that direction by default.
     setAutoResizeWidth(! hscrollbar);
     setAutoResizeHeight(! vscrollbar);
     if (contentControl != null) setContent(contentControl);
	}
	
	/** Cleans up control */
	protected void cleanupScrollPanel() {
	}
	
	
	// --- methods ---
	
	/** Sets whether ScrollPanel auto-resizes the width of its contained control
	 *  to match the size of the scrollpanel's content area, save when the control
	 *  is smaller than the minimum width. (This also implicitly disables/hides
	 *  the scrollbar when the control is auto-sized.)
	 */
	public void setAutoResizeWidth(boolean resizeWidth) {
		setExpandHorizontal(resizeWidth);
	}
	
	/** Sets whether ScrollPanel auto-resizes the height of its contained control
	 *  to match the size of the scrollpanel's content area, save when the control
	 *  is smaller than the minimum width. (This also implicitly disables/hides
	 *  the scrollbar when the control is auto-sized.)
	 */
	public void setAutoResizeHeight(boolean resizeHeight) {
		setExpandVertical(resizeHeight);
	}
}

Back to the top