From: Timothy W. <tw...@us...> - 2006-08-29 15:37:53
|
The core AWT tester implementation for JComponent (and derived classes) overrides a low-level method (click or mouseMove) to ensure that the scrollable component has the active area visible before performing the action. On Aug 25, 2006, at 6:13 PM, Scott Symmank wrote: > TreeItemTester.showItem(TreeItem) might help. > > > Or, if you *have* to actually scroll by clicking the > scroll, you might try something like this ( > i don't think it back into abbot.swt yet): > > import org.eclipse.swt.SWT; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.ScrollBar; > import org.eclipse.swt.widgets.Scrollable; > import org.eclipse.swt.widgets.Widget; > > import abbot.Log; > import abbot.Platform; > import abbot.tester.swt.Robot; > import abbot.tester.swt.RunnableWithResult; > import abbot.tester.swt.ScrollBarTester; > import abbot.tester.swt.ScrollableTester; > > /** @todo: write tests for below methods for > ScrollBar, > * add to SWTWorkarounds and ScrollBarTester > */ > public class ScrollBarTesterPatch extends > ScrollBarTester { > > public static int DEFAULT_DELAY = 200; > > /** > * Scroll the given amount, where amount==the > number of > * times the arrow is pressed. > * > * Positive amounts scroll down for vertical > scrollbars, > * horizontal ones. > * > * 1. Assuming the arrow is a square. > * 2. HORIZONTAL ScrollBars have a width of size.y > * 3. VERTICAL ScrollBars have a width of size.x > */ > @Override > public void actionScroll(final ScrollBar bar, > final int amount){ > Log.debug("actionScroll("+amount+")"); > actionFocus(bar); > Point barSize = getSize(bar); > Log.debug("ScrollBarSize="+barSize); > Rectangle barBounds = getBounds(bar); > int arrowWidth = barSize.x; > if (isHorizontal(bar)) { > arrowWidth = barSize.y; > } > Log.debug("ScrollBarArrowSize="+arrowWidth); > if(amount<0){ > Point p = new Point( > > barBounds.x+arrowWidth/2, > > barBounds.y+arrowWidth/2 > ); > mouseMove(p.x,p.y); > for(int i=amount; i<=0; i++){ > Log.debug("ScrollBarArrowClick= - "+p); > mousePress(SWT.BUTTON1); > mouseRelease(SWT.BUTTON1); > Robot.delay(DEFAULT_DELAY); > } > } > else if(amount>0){ > Point p = new Point( > > barBounds.x+barBounds.width - arrowWidth/2, > > barBounds.y+barBounds.height - arrowWidth/2 > ); > mouseMove(p.x,p.y); > for(int i=0; i<amount;i++){ > Log.debug("ScrollBarArrowClick= + "+p); > mousePress(SWT.BUTTON1); > mouseRelease(SWT.BUTTON1); > } > } > actionWaitForIdle(bar.getDisplay()); > } > > public Rectangle getBounds(final ScrollBar > scrollBar) { > Log.debug("ScrollBarTester.getBounds()"); > final Scrollable parent = > getParent(scrollBar); > final Rectangle relativeBounds = > getRelativeBounds(scrollBar); > final Display display = > scrollBar.getDisplay(); > Rectangle result = (Rectangle) > Robot.syncExec(display, new RunnableWithResult() { > @Override > public Object runWithResult() { > return display.map (parent, null, > relativeBounds); > } > }); > Log.debug("ScrollBarBounds="+result); > return result; > } > > public Rectangle getRelativeBounds (ScrollBar > scrollBar) { > Log.debug("ScrollBarTester.getRelativeBounds()"); > Point size = getSize(scrollBar); > Log.debug("ScrollBarSize="+size); > Scrollable parent = getParent(scrollBar); > ScrollableTester scrollableTester = new > ScrollableTester(); > Rectangle bounds = > scrollableTester.getBounds(parent); > Log.debug("ScrollableRelativeBounds="+bounds); > if (isLeftToRight(parent)) { > Log.debug("LEFT_TO_RIGHT"); > //SWT.LEFT_TO_RIGHT > if (isHorizontal(scrollBar)) { > Log.debug("HORIZONTAL"); > //SWT.HORIZONTAL > bounds.x = 0; > bounds.y = bounds.height - size.y; > } else { > Log.debug("VERTICAL"); > //SWT.VERTICAL > bounds.x = bounds.width - size.x; > //bounds.y = bounds.y; > } > } else { > Log.debug("RIGHT_TO_LEFT"); > //SWT.RIGHT_TO_LEFT > if (isHorizontal(scrollBar)) { > Log.debug("HORIZONTAL"); > //SWT.HORIZONTAL > bounds.x = bounds.width - size.x; > bounds.y = 0; > } else { > Log.debug("VERTICAL"); > //SWT.VERTICAL > bounds.x = 0; > bounds.y = bounds.height - size.y; > } > } > bounds.width = size.x; > bounds.height = size.y; > Log.debug("ScrollBarRelativeBounds="+bounds); > return bounds; > } > > @Override > /** CR271861 ScrollBar.getSize() seems to return the > * size of the thumb on linux, not the size > * of the whole bar. So, get the size from > * the parent Scrollable. > */ > public Point getSize(final ScrollBar s) { > Point size = null; > if (Platform.isLinux()) { > size = super.getSize(s); > Scrollable parent = getParent(s); > Point scrollableSize = > TesterFactory.newScrollableTester().getSize(parent); > size.y = scrollableSize.y; > } else { > size = super.getSize(s); > } > > return size; > } > > /** > * This method will return true if ScrollBar has > the horizontal style bit set. > * > * SWT.HORIZONTAL > * > */ > public boolean isHorizontal(final ScrollBar s) { > return (getStyle(s) & SWT.HORIZONTAL) != 0; > } > > /** > * This method will return true if ScrollBar has > the vertical style bit set. > * > * SWT.VERTICAL > * > */ > public boolean isVertical(final ScrollBar s) { > return (getStyle(s) & SWT.VERTICAL) != 0; > } > > public boolean isLeftToRight(final Widget w) { > return (getStyle(w) & SWT.LEFT_TO_RIGHT) != 0; > } > > public boolean isRightToLeft(final Widget w) { > return (getStyle(w) & SWT.RIGHT_TO_LEFT) != 0; > } > > } > > --- "Chen, Min" <Min...@bm...> wrote: > >> Hi there, >> >> >> >> I have been using abbot.swt to automate >> our Eclipse (SWT) >> based application, but ran into a problem in >> clicking a TableItem (or >> TreeItem) which is currently out-of-view and needs >> to use ScrollBar to >> bring it into view. I noticed that >> TableItemTester.actionClick does not >> know where to click in this case. I also tried >> TableItemTester.actionFocus to see if it can bring >> that item into view, >> but no avail. Really appreciate that some experts >> out there can help me >> on this. Thanks a lot! >> >> >> >> -min >> >>> > ---------------------------------------------------------------------- > --- >> Using Tomcat but need to do more? Need to support >> web services, security? >> Get stuff done quickly with pre-integrated >> technology to make your job easier >> Download IBM WebSphere Application Server v.1.0.1 >> based on Apache Geronimo >> > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642> > _______________________________________________ >> abbot-users mailing list >> abb...@li... >> > https://lists.sourceforge.net/lists/listinfo/abbot-users >> > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > ---------------------------------------------------------------------- > --- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > abbot-users mailing list > abb...@li... > https://lists.sourceforge.net/lists/listinfo/abbot-users > Timothy Wall http://abbot.sf.net |