Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Redirecting Scroll Wheel Events
Redirecting Scroll Wheel Events [message #517258] Fri, 26 February 2010 17:17 Go to next message
Terran Gilman is currently offline Terran GilmanFriend
Messages: 67
Registered: July 2009
Member
Is there a way to intercept scroll wheel events from either a Text widget or ScrolledComposite and redirect the events to their parent? I have a ScrolledComposite that contains several Text widgets. The text widgets are being resized vertically automatically as the contents change.

I'd like to have the mouse wheel events captured by these Text widgets to be processed by the parent ScrolledComposite to allow a more fluid user experience. Thanks for any help you can provide.
Re: Redirecting Scroll Wheel Events [message #517637 is a reply to message #517258] Mon, 01 March 2010 15:05 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

I thought that re-posting the event to the ScrolledComposite
(Display.post()) would do this, but this isn't working for me (at least on
Windows 2000). A simpler approach that will handle this case specifically
since the widget underneath is a ScrolledComposite is to add a Listener like
the one below to your Text controls.

t.addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event event) {
Point origin = sc.getOrigin();
origin.y -= event.count;
sc.setOrigin(origin);
}
});

Grant


"Trip Gilman" <trip@openmethods.com> wrote in message
news:hm8vn8$hok$1@build.eclipse.org...
> Is there a way to intercept scroll wheel events from either a Text widget
or ScrolledComposite and redirect the events to their parent? I have a
ScrolledComposite that contains several Text widgets. The text widgets are
being resized vertically automatically as the contents change.
>
> I'd like to have the mouse wheel events captured by these Text widgets to
be processed by the parent ScrolledComposite to allow a more fluid user
experience. Thanks for any help you can provide.
Re: Redirecting Scroll Wheel Events [message #517686 is a reply to message #517637] Mon, 01 March 2010 17:28 Go to previous messageGo to next message
Terran Gilman is currently offline Terran GilmanFriend
Messages: 67
Registered: July 2009
Member
Hi Grant,

I implemented your example and it works well except for a couple of things. First, there appears to be an invisible 1-2 pixel dead zone (just outside the visible border lines) in which events don't seem to be generated.

The second may be related to my development platform of Mac OSX. The text area has the H_SCROLL style to allow horizontal growth of text with wrapping turned off to preserve the visual formatting if any. On Mac, when the text is not long enough to trigger the scroll bar, the space is still reserved for the bar anyways. This area appears to be another dead zone for events. I attempted to add the listener to the bar directly but still don't see the events in that case.

Thanks
Re: Redirecting Scroll Wheel Events [message #517970 is a reply to message #517686] Tue, 02 March 2010 15:51 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
I don't think there's a way to work around these issues since they're
physical areas that belong to the text widget but do not trigger events. My
initial idea of post()ing the received events to the parent
ScrolledComposite would have the same problems since it would also rely on
receiving the events. However I think that this approach is the only one to
do what you want since events in swt do not bubble automatically.

I notice on win32 that MouseWheeling over a Table's disabled scrollbar does
send these events, but on gtk they're not set. I'm not sure which behaviour
is correct, but regardless, it currently can't be depended upon. I've
logged https://bugs.eclipse.org/bugs/show_bug.cgi?id=304372 for the
inconsistency, but in the meantime, I don't think there's a way to handle
these cases.

Grant


"Trip Gilman" <trip@openmethods.com> wrote in message
news:hmgtg6$sq4$1@build.eclipse.org...
> Hi Grant,
>
> I implemented your example and it works well except for a couple of
things. First, there appears to be an invisible 1-2 pixel dead zone (just
outside the visible border lines) in which events don't seem to be
generated.
>
> The second may be related to my development platform of Mac OSX. The text
area has the H_SCROLL style to allow horizontal growth of text with wrapping
turned off to preserve the visual formatting if any. On Mac, when the text
is not long enough to trigger the scroll bar, the space is still reserved
for the bar anyways. This area appears to be another dead zone for events.
I attempted to add the listener to the bar directly but still don't see the
events in that case.
>
> Thanks
Re: Redirecting Scroll Wheel Events [message #517977 is a reply to message #517970] Tue, 02 March 2010 16:15 Go to previous messageGo to next message
Terran Gilman is currently offline Terran GilmanFriend
Messages: 67
Registered: July 2009
Member
Grant,

Thanks for the reply. I completely understand the difficulties of supporting multiple underlying systems. We encounter similar inconsistencies developing the voice tools project. The initial suggestion works pretty well. The scrolling isn't as smooth as i'd like, but it's serviceable. Again, thanks for the help.
SWT Swing integration respective batik (SVG rendering library) [message #531350 is a reply to message #517258] Tue, 04 May 2010 15:03 Go to previous message
Eclipse UserFriend
Originally posted by: micha.on.the.road.web.de

This is a multi-part message in MIME format.
--------------040806040309010600050001
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

I have quite some trouble getting batik (SVG rendering library)
well-running in an embedded SWT composite.
Using Direct3D or openGL (vm argument -Dsun.java2d.opengl=true) as
rendering, different problems arise, from cheesy doubled background
(D3D) to vertical shaking while resizing (openGL). The worst is that
rendering frequently gets stucked. Especially resizing causes this
trouble, in Swing everything works fine with batik.

Anybody has an idea how to improve SWT_AWT integration for this purpose
or for resizing in general?

I attached a code Snippet,

System.setProperty("sun.awt.noerasebackground", "true"),
SWT.NO_REDRAW_RESIZE, SWT.NO_BACKGROUND are not connected to the problem.

Regards
Michael

--------------040806040309010600050001
Content-Type: text/x-java;
name="SimpleWhiteboard.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="SimpleWhiteboard.java"

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.svg.AbstractJSVGComponent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;

public class SimpleWhiteboard extends Composite {

static {
System.setProperty("sun.awt.noerasebackground", "true");
}

public SimpleWhiteboard(Composite parent, int mode) {
super(parent, mode);

this.setLayout(new FillLayout());
new SimpleSVGSurface(this);

}

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Whiteboard");
shell.setLayout(new FillLayout());
SimpleWhiteboard instance = new SimpleWhiteboard(shell,
SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
instance.dispose();
}

public static class SimpleSVGSurface extends Composite {

private JSVGCanvas svgCanvas = null;
private Frame frame = null;

private Document svgDocument = null;

public SimpleSVGSurface(Composite parent) {
this(parent, SWT.NONE);
}

public SimpleSVGSurface(Composite parent, int mode) {
super(parent, mode | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE
| SWT.EMBEDDED);

init();
initXMLGraphics();
initListeners();

}

protected void init() {

svgCanvas = new JSVGCanvas();

svgCanvas.setDocumentState(AbstractJSVGComponent.ALWAYS_DYNA MIC);
svgCanvas.setLayout(new BorderLayout());
svgCanvas.setDoubleBuffered(true);
svgCanvas.setDoubleBufferedRendering(true);

frame = SWT_AWT.new_Frame(this);
frame.setLayout(new BorderLayout());
frame.add(BorderLayout.CENTER, svgCanvas);
frame.setEnabled(true);

frame.pack();
frame.setVisible(true);
}

protected void initXMLGraphics() {
DOMImplementation impl = SVGDOMImplementation
.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;

svgDocument = impl.createDocument(svgNS, "svg", null);

SVGGraphics2D svgGraphics = new SVGGraphics2D(svgDocument);
// fill the SVG Document with the Defaults
Element root = svgGraphics
.getRoot(svgDocument.getDocumentElement());

root.setAttributeNS(null, "overflow", "visible");

svgCanvas.setDocument(svgDocument);
}

private static Point lastPoint = null;

protected void initListeners() {
svgCanvas.addMouseListener(new java.awt.event.MouseListener() {

public void mouseClicked(java.awt.event.MouseEvent e) {
//
}

public void mouseEntered(java.awt.event.MouseEvent e) {
// TODO Auto-generated method stub

}

public void mouseExited(java.awt.event.MouseEvent e) {
//

}

public void mousePressed(java.awt.event.MouseEvent e) {
System.out.print("MouseDown ");
if (lastPoint == null)
lastPoint = e.getPoint();

appendLine(lastPoint, e.getPoint());
lastPoint = e.getPoint();
}

public void mouseReleased(java.awt.event.MouseEvent e) {
//
}

});

svgCanvas
.addMouseMotionListener(new java.awt.event.MouseMotionListener() {

public void mouseDragged(java.awt.event.MouseEvent e) {
System.out.print("MouseDragged ");

appendLine(lastPoint, e.getPoint());
lastPoint = e.getPoint();

}

public void mouseMoved(java.awt.event.MouseEvent e) {
// System.out.println("MouseMoved");

}

});

initDebugListener();
}

private void appendLine(final Point start, final Point end) {

svgCanvas.getUpdateManager().getUpdateRunnableQueue().invoke Later(
new Runnable() {

public void run() {
System.out.println("WM works");

SVGDocument doc = svgCanvas.getSVGDocument();
String SVGNS = SVGDOMImplementation.SVG_NAMESPACE_URI;

Element g = doc.createElementNS(SVGNS, "g");

Element e = doc.createElementNS(SVGNS, "line");

e.setAttributeNS(null, "fill", "none");
e.setAttributeNS(null, "x1", String.valueOf(start
.getX()));
e.setAttributeNS(null, "y1", String.valueOf(start
.getY()));
e
.setAttributeNS(null, "x2", String.valueOf(end
.getX()));
e
.setAttributeNS(null, "y2", String.valueOf(end
.getY()));

g.appendChild(e);

doc.getRootElement().appendChild(g);
}
});
}

@Override
public void dispose() {
// should be disposed by the AWT thread to avoid deadlocks
EventQueue.invokeLater(new Runnable() {
public void run() {
svgCanvas.dispose();
frame.dispose();
}
});
super.dispose();
}

private void initDebugListener() {
svgCanvas.addComponentListener(new ComponentListener() {

public void componentHidden(ComponentEvent arg0) {
// TODO Auto-generated method stub

}

public void componentMoved(ComponentEvent arg0) {
// TODO Auto-generated method stub

}

public void componentResized(ComponentEvent arg0) {

System.out.println("Resize: " + svgCanvas.getSize());

}

public void componentShown(ComponentEvent arg0) {
// TODO Auto-generated method stub

}

});

}
}

}

--------------040806040309010600050001--
Previous Topic:xpath
Next Topic:SWT Swing integration respective batik (SVG rendering library)
Goto Forum:
  


Current Time: Tue Apr 16 19:11:37 GMT 2024

Powered by FUDForum. Page generated in 0.44531 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top