xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DeWeese Thomas <thomas.dewe...@gmail.com>
Subject Re: batik not updating when resizing
Date Mon, 07 Jan 2013 23:23:59 GMT
Hi Ruben,
   I think this is really late to be setting the width of the root SVG element.  If you want
to go this route you would probably need to load the XML yourself, update the width and then
pass the XML DOM to the canvas.

   Alternately I would suggest overriding setMySize on the JSVGCanvas so that it ignores the
size from the SVG document so that it is statically sized (well really just respecting the
normal Swing layout rules).

   Thomas

On Jan 7, 2013, at 9:22 AM, Rubén Pérez <ruben@astraia.com> wrote:

> Hello,
> 
> I'm in Mac (I read there are some problems in Mac so it might be actually my problem,
but I'd like to confirm that with you guys).
> 
> I have a JPanel with a BorderLayout in which I have added on the EAST area a JSVGCanvas
loading a small arrow (originally on the file is 65px width). I want to load that arrow but
resized to 100px.
> 
> I simply can't achieve this. When I run my code, the JSVGCanvas measures 69px width instead
of the 100px, and there is nothing on it, it's just the panel empty with my orange background.
> 
> Here is basically what I'm doing:
> 
> 
> 	private void changeWidth(final JSVGCanvas form, final int size) {
> 		Runnable cmd=new Runnable() {
> 			public void run() {
> 				Element svgRoot = form.getSVGDocument().getDocumentElement();
> 				svgRoot.setAttributeNS(null, "width", String.valueOf(size));
> 			}
> 		};
> 		
> 		form.getUpdateManager().getUpdateRunnableQueue().invokeLater(cmd);
> 	}
> 	
> 	private JSVGCanvas buildArrow() {
> 		try {
> 			String parser = XMLResourceDescriptor.getXMLParserClassName();
> 			SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
> 			URI uri = this.getClass().getResource("/com/myapp/app/dicomview/player/arrow.svg").toURI();
> 			final SVGDocument doc = (SVGDocument) f.createDocument(uri.toString());
> 			Element svgRoot = doc.getDocumentElement();
> 		
> 			final JSVGCanvas arrow=new JSVGCanvas();
> 			
> 			arrow.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
> 			arrow.setOpaque(true);
> 			arrow.setVisible(true);
> 			
> 			Color inst=new Color(Color.orange.getRed(), Color.orange.getGreen(), Color.orange.getBlue(),
75);
> 			arrow.setBackground( inst );
> 			arrow.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
> 				@Override
> 				public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
> 					changeWidth(arrow, 100);
> 				}
> 			});
> 			
> 			arrow.setSVGDocument(doc);
> 
> 			add(arrow, BorderLayout.EAST);
> 			
> 			repaint();
> 			return arrow;
> 		} catch (Throwable ex) {
> 			ex.printStackTrace(System.out);
> 			ErrorReport.process(ex);
> 			return null;
> 		}	
> 	}
> 
> 
> 
> Can anybody please give me a hint in what could be going wrong?
> 
> Thanks!
> Ruben


Mime
View raw message