|
|
|
Re: Redirecting Scroll Wheel Events [message #517970 is a reply to message #517686] |
Tue, 02 March 2010 15:51 |
Grant Gayed 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
|
|
|
|
SWT Swing integration respective batik (SVG rendering library) [message #531350 is a reply to message #517258] |
Tue, 04 May 2010 15:03 |
Eclipse User |
|
|
|
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--
|
|
|
Powered by
FUDForum. Page generated in 0.04406 seconds