Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 14070 Details for
Bug 72244
Posting mouse events locks up event handling
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Example code
MouseEvents.java (text/plain), 4.50 KB, created by
Christof Marti
on 2004-08-19 06:48:17 EDT
(
hide
)
Description:
Example code
Filename:
MIME Type:
Creator:
Christof Marti
Created:
2004-08-19 06:48:17 EDT
Size:
4.50 KB
patch
obsolete
>/******************************************************************************* > * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Common Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/cpl-v10.html > * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ > >package snippets; > >import org.eclipse.swt.SWT; >import org.eclipse.swt.custom.StyledText; >import org.eclipse.swt.graphics.Point; >import org.eclipse.swt.graphics.Rectangle; >import org.eclipse.swt.layout.FillLayout; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Event; >import org.eclipse.swt.widgets.Shell; > >public class MouseEvents { > > private static final boolean POST_FROM_BACKGROUND= false; > > private static final int LINES= 1000; > > private EventPoster fEventPoster; > > private static class EventPoster implements Runnable { > private Display fDisplay; > private Shell fShell; > private StyledText fText; > private Point fThumb; > > private volatile int fTopPixel; > private int fOldTopPixel; > private int fMaxTopPixel; > > private Runnable fRunnable= new Runnable() { > public void run() { > fTopPixel= fText.getTopPixel(); > } > }; > > public EventPoster(StyledText text) { > fText= text; > fShell= text.getShell(); > fDisplay= fText.getDisplay(); > > fText.setTopPixel(Integer.MAX_VALUE); > fMaxTopPixel= fText.getTopPixel(); > fText.setTopPixel(0); > while (fDisplay.readAndDispatch()); > > Rectangle textBounds= fDisplay.map(fText.getParent(), null, fText.getBounds()); > int thumbX= textBounds.width - (fText.getVerticalBar().getSize().x >> 1); > int thumbY= fText.computeTrim(0, 0, 0, 0).height + 2; > fThumb= fDisplay.map(fText, null, thumbX, thumbY); > } > > public void run() { > try { > fTopPixel= 0; > mouseMoveEvent(fDisplay, fThumb.x, fThumb.y++); > mouseDownEvent(fDisplay, 1); > while (fTopPixel < fMaxTopPixel) { > mouseMoveEvent(fDisplay, fThumb.x, fThumb.y++); > fOldTopPixel= fTopPixel; > if (!waitForScrolling(2000)) { > System.out.println("Timeout."); > break; > } > } > } finally { > mouseUpEvent(fDisplay, 1); > } > } > > public boolean waitForScrolling(long maxTime) { > long maxEndTime= System.currentTimeMillis() + maxTime; > while (System.currentTimeMillis() < maxEndTime) { > if (POST_FROM_BACKGROUND) > fDisplay.syncExec(fRunnable); > else { > while (!fShell.isDisposed()) { > System.out.println("rAD in"); > if (!fDisplay.readAndDispatch()) { > System.out.println("rAD out (false)"); > break; > } > System.out.println("rAD out (true)"); > } > fRunnable.run(); > } > if (fOldTopPixel != fTopPixel) > return true; > } > return false; > } > } > > public static void main(String[] args) { > new MouseEvents().run(); > } > > private void run() { > Display display= new Display(); > Shell shell= new Shell(display); > shell.setLayout(new FillLayout()); > StyledText text= new StyledText(shell, SWT.H_SCROLL | SWT.V_SCROLL); > text.setText(someText()); > shell.setBounds(10, 10, 400, 300); > shell.open(); > > fEventPoster= new EventPoster(text); > if (POST_FROM_BACKGROUND) > new Thread(fEventPoster).start(); > else > fEventPoster.run(); > while (!shell.isDisposed()) > if (!display.readAndDispatch()) > display.sleep(); > } > > private String someText() { > StringBuffer buf= new StringBuffer(); > for (int i= 0; i < LINES; i++) { > buf.append(i); > buf.append('\n'); > } > return buf.toString(); > } > > private static Event sfMouseMoveEvent= new Event(); > public static void mouseMoveEvent(Display display, int x, int y) { > sfMouseMoveEvent.type= SWT.MouseMove; > sfMouseMoveEvent.x= x; > sfMouseMoveEvent.y= y; > > display.post(sfMouseMoveEvent); > } > > public static void mouseDownEvent(Display display, int button) { > mouseButtonEvent(display, SWT.MouseDown, button); > } > > public static void mouseUpEvent(Display display, int button) { > mouseButtonEvent(display, SWT.MouseUp, button); > } > > private static Event sfMouseButtonEvent= new Event(); > private static void mouseButtonEvent(Display display, int type, int button) { > sfMouseButtonEvent.type= type; > sfMouseButtonEvent.button= button; > > display.post(sfMouseButtonEvent); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 72244
: 14070 |
14788