下面列出了怎么用org.eclipse.swt.widgets.Scrollable的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Convert overview coordinates to global coordinates.
*
* @param loc
* the control reference
* @param x
* The x coordinate to convert
* @param y
* The y coordinate to convert
* @return The new converted Point
*/
protected Point toGlobalCoordinates(Control loc, int x, int y) {
Point p = new Point(x, y);
for (Control c = loc; c != null; c = c.getParent()) {
// control might have client area with 'decorations'
int trimX = 0, trimY = 0;
// other kind of widget with trimming ??
if (c instanceof Scrollable) {
Scrollable s = (Scrollable) c;
Rectangle rr = s.getClientArea();
Rectangle tr = s.computeTrim(rr.x, rr.y, rr.width, rr.height);
trimX = rr.x - tr.x;
trimY = rr.y - tr.y;
}
p.x += c.getLocation().x + trimX;
p.y += c.getLocation().y + trimY;
}
return p;
}
/**
* {@inheritDoc}
*/
protected void setColumnWidths(Scrollable tableTree, int[] widths) {
GridColumn[] columns = ((Grid) tableTree).getColumns();
for (int i = 0; i < widths.length; i++) {
columns[i].setWidth(widths[i]);
}
}
/**
* @param c2
* @param movement
*/
public ScrollingSmoother(final Scrollable c2, IMovement movement) {
this.component = c2;
verticalScrollBar = c2.getVerticalBar();
horizontalScrollBar = c2.getHorizontalBar();
this.movement = movement;
}
protected Result getReportBounds( Rectangle reportSize )
{
Result revValue = new Result( );
revValue.reportSize.y = MINTOPSPACE;
revValue.reportSize.width = reportSize.width;
revValue.reportSize.height = reportSize.height;
EditPartViewer viewer = owner.getViewer( );
Scrollable control = viewer == null ? null : (Scrollable)viewer.getControl( );
Rectangle containerSize = control == null ? new Rectangle( )
: new Rectangle( control.getClientArea( ) );
PrecisionDimension dim = new PrecisionDimension( containerSize.width,
containerSize.height );
double scale = getZoomManager( ).getZoom( );
dim.performScale( 1 / scale );
if ( dim.width > reportSize.width + MINLEFTSPACE + MINRIGHTSPACE )
{
revValue.reportSize.x = ( dim.width - reportSize.width ) / 2;
revValue.rightSpace = ( dim.width - reportSize.width ) / 2;
}
else
{
revValue.reportSize.x = MINLEFTSPACE;
revValue.rightSpace = MINRIGHTSPACE;
}
if ( dim.height > reportSize.height + MINTOPSPACE + MINBOTTOMSPACE )
{
revValue.bottomSpace = dim.height - reportSize.height
- revValue.reportSize.y;
}
else
{
revValue.bottomSpace = MINBOTTOMSPACE;
}
return revValue;
}
/**
* {@inheritDoc}
*/
protected int getColumnCount(Scrollable tableTree) {
return ((Grid) tableTree).getColumnCount();
}
/**
* {@inheritDoc}
*/
protected ColumnLayoutData getLayoutData(Scrollable tableTree,
int columnIndex) {
GridColumn column = ((Grid) tableTree).getColumn(columnIndex);
return (ColumnLayoutData) column.getData(LAYOUT_DATA);
}
TraceDisplayResizer(final Tree resizingTree) {
tree = resizingTree;
treeParentComponent = (Scrollable)tree.getParent();
columns = new TreeColumn[COLUMN_TEXTS.length];
}
public ScrollbarHandler(Scrollable view, GLScene scene) {
this.view = view;
this.scene = scene;
this.vertBar = view.getVerticalBar();
this.horizBar = view.getHorizontalBar();
}
protected void addSelectionColorOverride()
{
if (controlIsDisposed())
{
return;
}
// Override selection color to match what is set in theme
selectionOverride = new Listener()
{
public void handleEvent(Event event)
{
if (!invasiveThemesEnabled())
{
return;
}
GC gc = event.gc;
Color oldBackground = gc.getBackground();
if ((event.detail & SWT.SELECTED) != 0)
{
Scrollable scrollable = (Scrollable) event.widget;
Rectangle clientArea = scrollable.getClientArea();
gc.setBackground(getSelection());
// The +2 on width is for Linux, since clientArea begins at [-2,-2] and
// without it we don't properly color full width (see broken coloring when scrolling horizontally)
gc.fillRectangle(clientArea.x, event.y, clientArea.width + 2, event.height);
event.detail &= ~SWT.SELECTED;
event.detail &= ~SWT.BACKGROUND;
gc.setBackground(oldBackground);
}
else
{
// Draw normal background color. This seems to only be necessary for some variants of Linux,
// and is the correct way to force custom painting of background when setBackground() doesn't work
// properly.
if (!isWindows && !isMacOSX)
{
Color controlBG = control.getBackground();
if (controlBG.getRGB().equals(oldBackground.getRGB()))
{
gc.setBackground(getBackground());
gc.fillRectangle(event.x, event.y, event.width, event.height);
event.detail &= ~SWT.BACKGROUND;
gc.setBackground(oldBackground);
}
}
}
// force foreground color. Otherwise on dark themes we get black FG (all the time on Win, on
// non-focus for Mac)
gc.setForeground(getForeground());
}
};
getControl().addListener(SWT.EraseItem, selectionOverride);
}
public ClientAreaResizeCommand(Scrollable scrollable) {
super();
this.scrollable = scrollable;
}
public Scrollable getScrollable() {
return scrollable;
}
public ClientAreaResizeCommand(Scrollable scrollable) {
super();
this.scrollable = scrollable;
}
public Scrollable getScrollable() {
return scrollable;
}
/**
* Create a Scrolling Smoother instance over a scrollable widget. This
* effect can then be activated using
* {@link ScrollingSmoother#smoothControl(boolean)}.
*
* @see ScrollingSmoother#smoothControl(boolean)
*
* @param c2
* @param movement
*/
public ScrollingSmoother(final Scrollable c2, IMovement movement) {
this.component = c2;
verticalScrollBar = c2.getVerticalBar();
horizontalScrollBar = c2.getHorizontalBar();
this.movement = movement;
}
/**
* Create a Scrolling Smoother instance over a scrollable widget. This
* effect can then be activated using
* {@link ScrollingSmoother#smoothControl(boolean)}.
*
* @see ScrollingSmoother#smoothControl(boolean)
*
* @param c2
* @param movement
* @param duration
*/
public ScrollingSmoother(final Scrollable c2, IMovement movement,
int duration) {
this(c2, movement);
this.duration = duration;
}