Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Swing integration respective batik (SVG rendering library)
SWT Swing integration respective batik (SVG rendering library) [message #531351] Tue, 04 May 2010 15:05
Eclipse UserFriend
Originally posted by: micha.on.the.road.web.de

This is a multi-part message in MIME format.
--------------040004070401060009050209
Content-Type: text/plain; charset=ISO-8859-1; 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


PS: please excuse the wrong threaded post before

--------------040004070401060009050209
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

}

});

}
}

}

--------------040004070401060009050209--
Previous Topic:Redirecting Scroll Wheel Events
Next Topic:Set backgroud in the tree
Goto Forum:
  


Current Time: Thu Sep 26 02:06:14 GMT 2024

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

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

Back to the top