1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
package org.eclipse.gef.internal.ui.palette.editparts;
|
12
|
|
13
|
import org.eclipse.draw2d.IFigure;
|
14
|
import org.eclipse.draw2d.ScrollBar;
|
15
|
import org.eclipse.draw2d.ScrollPane;
|
16
|
import org.eclipse.draw2d.ScrollPaneLayout;
|
17
|
import org.eclipse.draw2d.Viewport;
|
18
|
import org.eclipse.draw2d.geometry.Dimension;
|
19
|
import org.eclipse.draw2d.geometry.Insets;
|
20
|
import org.eclipse.draw2d.geometry.Rectangle;
|
21
|
|
22
|
public class OverlayScrollPaneLayout extends ScrollPaneLayout {
|
23
|
|
24
|
/**
|
25
|
* {@inheritDoc} In OverlayScrollPane, scrollbars are overlayed on top of
|
26
|
* the Viewport, so the preferred size is just the Viewports preferred size.
|
27
|
*
|
28
|
* @since 2.0
|
29
|
*/
|
30
|
protected Dimension calculatePreferredSize(IFigure container, int wHint,
|
31
|
int hHint) {
|
32
|
ScrollPane scrollpane = (ScrollPane) container;
|
33
|
Insets insets = scrollpane.getInsets();
|
34
|
|
35
|
int excludedWidth = insets.getWidth();
|
36
|
int excludedHeight = insets.getHeight();
|
37
|
|
38
|
return scrollpane
|
39
|
.getViewport()
|
40
|
.getPreferredSize(wHint - excludedWidth, hHint - excludedHeight)
|
41
|
.getExpanded(excludedWidth, excludedHeight);
|
42
|
}
|
43
|
|
44
|
/** {@inheritDoc} */
|
45
|
public void layout(IFigure parent) {
|
46
|
ScrollPane scrollpane = (ScrollPane) parent;
|
47
|
Rectangle clientArea = parent.getClientArea();
|
48
|
|
49
|
ScrollBar hBar = scrollpane.getHorizontalScrollBar(), vBar = scrollpane
|
50
|
.getVerticalScrollBar();
|
51
|
Viewport viewport = scrollpane.getViewport();
|
52
|
|
53
|
Insets insets = new Insets();
|
54
|
insets.bottom = hBar.getPreferredSize(clientArea.width,
|
55
|
clientArea.height).height;
|
56
|
insets.right = vBar.getPreferredSize(clientArea.width,
|
57
|
clientArea.height).width;
|
58
|
|
59
|
int hVis = scrollpane.getHorizontalScrollBarVisibility(), vVis = scrollpane
|
60
|
.getVerticalScrollBarVisibility();
|
61
|
|
62
|
Dimension available = clientArea.getSize(), preferred = viewport
|
63
|
.getPreferredSize(available.width, available.height).getCopy();
|
64
|
|
65
|
boolean none = available.contains(preferred), both = !none
|
66
|
&& vVis != NEVER && hVis != NEVER
|
67
|
&& preferred.contains(available), showV = both
|
68
|
|| preferred.height > available.height, showH = both
|
69
|
|| preferred.width > available.width;
|
70
|
|
71
|
// Adjust for visibility override flags
|
72
|
showV = !(vVis == NEVER) && (showV || vVis == ALWAYS);
|
73
|
showH = !(hVis == NEVER) && (showH || hVis == ALWAYS);
|
74
|
|
75
|
if (!showV)
|
76
|
insets.right = 0;
|
77
|
if (!showH)
|
78
|
insets.bottom = 0;
|
79
|
Rectangle bounds, viewportArea = clientArea;
|
80
|
|
81
|
if (showV) {
|
82
|
bounds = new Rectangle(viewportArea.right() - insets.right,
|
83
|
viewportArea.y, insets.right, viewportArea.height);
|
84
|
vBar.setBounds(bounds);
|
85
|
// vBar.setMaximum(preferred.height);
|
86
|
}
|
87
|
if (showH) {
|
88
|
bounds = new Rectangle(viewportArea.x, viewportArea.bottom()
|
89
|
- insets.bottom, viewportArea.width, insets.bottom);
|
90
|
hBar.setBounds(bounds);
|
91
|
// hBar.setMaximum(preferred.width);
|
92
|
}
|
93
|
vBar.setVisible(showV);
|
94
|
hBar.setVisible(showH);
|
95
|
viewport.setBounds(viewportArea);
|
96
|
}
|
97
|
|
98
|
}
|