Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Mirah/SWTSnippets/Snippet9"
< Mirah | SWTSnippets
(New page: <pre>/******************************************************************************* * Copyright(child 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the...) |
|||
Line 1: | Line 1: | ||
+ | Compare with [http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet9.java?view=co the original]. | ||
<pre>/******************************************************************************* | <pre>/******************************************************************************* | ||
* Copyright(child 2000, 2011 IBM Corporation and others. | * Copyright(child 2000, 2011 IBM Corporation and others. |
Latest revision as of 12:21, 27 March 2011
Compare with the original.
/******************************************************************************* * Copyright(child 2000, 2011 IBM 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: * IBM Corporation - initial API and implementation *******************************************************************************/ /* * Composite example snippet: scroll a child control automatically * * For a list of SWT example snippets ported to Mirah, see * http://wiki.eclipse.org/Mirah/SWTSnippets */ import org.eclipse.swt.* import org.eclipse.swt.events.* import org.eclipse.swt.graphics.* import org.eclipse.swt.widgets.* display = Display.new shell = Shell.new display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL composite = Composite.new shell, SWT.BORDER composite.setSize 700, 600 red = display.getSystemColor SWT.COLOR_RED composite.addPaintListener do |e| e.gc.setBackground red e.gc.fillOval 5, 5, 690, 590 end hBar = shell.getHorizontalBar hBar.addListener(SWT.Selection) do |e| location = composite.getLocation location.x = -hBar.getSelection composite.setLocation location end vBar = shell.getVerticalBar vBar.addListener(SWT.Selection) do |e| location = composite.getLocation location.y = -vBar.getSelection composite.setLocation location end shell.addListener(SWT.Resize) do |e| size = composite.getSize rect = shell.getClientArea hBar.setMaximum size.x vBar.setMaximum size.y hBar.setThumb Math.min(size.x, rect.width) vBar.setThumb Math.min(size.y, rect.height) hPage = size.x - rect.width vPage = size.y - rect.height hSelection = hBar.getSelection vSelection = vBar.getSelection location = composite.getLocation if hSelection >= hPage hSelection = 0 if hPage <= 0 location.x = -hSelection end if vSelection >= vPage vSelection = 0 if vPage <= 0 location.y = -vSelection end composite.setLocation location end shell.setSize 600, 500 shell.open until shell.isDisposed unless display.readAndDispatch display.sleep end end display.dispose