You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Tracey Zellmann <tr...@comcast.net> on 2005/08/17 13:41:52 UTC
JSVGCanvas behavior in Layout
I am having a problem with the behavior of a JSVGCanvas in a Layout. It initially shows in an appropriate size, but when the overall layout changes, the SVG image and the JSVGCanvas increase in size and overwhelm the other components in the layout.
I am using Java 1.5.0_04 in Windows XP sp2 with batik 1.6.
I have an application that shows the image of an automobile in a JSVGCanvas. The user is asked questions about the car and soem of teh questions ask the user to mark locations on teh car.
The overall layout is a BorderLayout. North is a JPanel handling status. South is a JPanel handling navigation - basically going to the next question. The questions are held in a JPanel using a CardLayout to move through the question list. The JSVGCanvas goes into another JPanel. I have had the best results using a HorizontalBox as the central panel, holding the JPanel holding the questions on the left and the canvas on the right. The navigation panel has a Next Question button which moves through the card stack. The first quetion loads OK - although the image isnt't where I want it.. Then, when Next Question is pressed, the SVG image increases in size and moves - up and to the left, mostly out of view.
I am relatively new to Batik and I am not sure what is happenign or what to do about it. Any help would be appreciated. I believe I may have to rernder the image after the next button.
The code is pasted below.
import input.Context;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.MalformedURLException;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.apache.batik.swing.JSVGCanvas;
/**
*
* @author Michael Tracey Zellmann tracey.zellmann@comcast.net
* @version 1.0
*
*/
public class Mediator implements ActionListener {
private static final int QCOUNT = 5;
private static final Dimension CANVAS_DIMENSION = new Dimension(250, 700);
private QuestionPanel q1 = new QuestionOne("Q1");
private QuestionPanel q2 = new QuestionTwo("Q2");
private QuestionPanel q3 = new QuestionThree("Q3");
private QuestionPanel q4 = new QuestionFour("Q4");
private QuestionPanel q5 = new QuestionFive("Q5");
private NavigationPanel navPanel = new NavigationPanel(this);
private StatusPanel statusPanel = new StatusPanel();
private JPanel overallPanel = new JPanel(new BorderLayout());
private CardLayout card = new CardLayout();
private JSVGCanvas canvas = getCarImage();
private JPanel rightPanel = new JPanel();
private JPanel leftPanel = new JPanel(this.card);
/**
* Constructor.
*
*/
public Mediator() {
buildCardStack();
this.canvas.setPreferredSize(CANVAS_DIMENSION);
this.rightPanel.add(this.canvas);
this.overallPanel.add(this.statusPanel, BorderLayout.NORTH);
Box centralBox = Box.createHorizontalBox();
centralBox.add(this.leftPanel);
centralBox.add(this.rightPanel);
this.overallPanel.add(centralBox, BorderLayout.CENTER);
this.overallPanel.add(this.navPanel, BorderLayout.SOUTH);
}
private void buildCardStack() {
this.leftPanel.add(this.q1, "Q1");
this.leftPanel.add(this.q2, "Q2");
this.leftPanel.add(this.q3, "Q3");
this.leftPanel.add(this.q4, "Q4");
this.leftPanel.add(this.q5, "Q5");
}
/**
* Get the overall panel.
* @return the panel.
*/
public final JPanel getOverallPanel() {
return this.overallPanel;
}
/**
* Perform action.
* @param ae action event.
*/
public final void actionPerformed(final ActionEvent ae) {
if (ae.getActionCommand().equalsIgnoreCase("Next")) {
this.card.next(this.leftPanel);
}
}
/**
* Obtain the survey car image on an svg canvas.
* @return the canvas with the image.
*/
public final JSVGCanvas getCarImage() {
JSVGCanvas canv = new JSVGCanvas();
String path = Context.getInstance().getSetUp("ImagePath");
File f = new File(path);
try {
canv.setURI(f.toURL().toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
return canv;
}
/**
* Exercise.
* @param args command-line args.
*/
public static void main(final String[] args) {
Mediator m = new Mediator();
JFrame jf = new JFrame("This is a test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setContentPane(m.getOverallPanel());
jf.pack();
jf.setVisible(true);
}
}
Re: JSVGCanvas behavior in Layout
Posted by Tracey Zellmann <tr...@comcast.net>.
Thanks for your advice. I have been able to get this to behave the way I
want now.
----- Original Message -----
From: "Thomas DeWeese" <Th...@Kodak.com>
To: <ba...@xmlgraphics.apache.org>
Sent: Friday, August 19, 2005 7:27 AM
Subject: Re: JSVGCanvas behavior in Layout
> Hi Tracey,
>
> Tracey Zellmann wrote:
>
>> I am having a problem with the behavior of a JSVGCanvas in a Layout. It
>> initially shows in an appropriate size, but when the overall layout
>> changes, the SVG image and the JSVGCanvas increase in size and overwhelm
>> the other components in the layout.
>
> This is probably because the default behavior of the Canvas when
> reading a file is to set it's 'preferredSize' to the size of the
> SVG image it just read. If this happens after the component is layed
> out it essentially has no effect, however if the components are
> relayed out (and you haven't done something to counter act it) the
> default layout alg will attempt to give the canvas it's preferred size.
>
> The simplest thing to do if you don't want the canvas to pay
> attention to the size the SVG document requests is to override
> the method 'setMySize' in JSVGCanvas to do nothing.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: JSVGCanvas behavior in Layout
Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Tracey,
Tracey Zellmann wrote:
> I am having a problem with the behavior of a JSVGCanvas in a Layout. It
> initially shows in an appropriate size, but when the overall layout
> changes, the SVG image and the JSVGCanvas increase in size and overwhelm
> the other components in the layout.
This is probably because the default behavior of the Canvas when
reading a file is to set it's 'preferredSize' to the size of the
SVG image it just read. If this happens after the component is layed
out it essentially has no effect, however if the components are
relayed out (and you haven't done something to counter act it) the
default layout alg will attempt to give the canvas it's preferred size.
The simplest thing to do if you don't want the canvas to pay
attention to the size the SVG document requests is to override
the method 'setMySize' in JSVGCanvas to do nothing.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: BridgeException afer deepCloneDocument
Posted by "Kenneth B. Harwood" <ru...@comcast.net>.
Fixed.
Thanks TD. Your guidance set me on the right course. My code now looks like this:
SVGOMDocument doc1= (SVGOMDocument) jSVGCanvas1.getSVGDocument();
DOMImplementation imp= doc1.getImplementation();
SVGOMDocument doc2= (SVGOMDocument) deepCloneDocument(doc1, imp);
URL url= doc1.getURLObject(); // get the source doc's URI
doc2.setURLObject(url); // put it in the copy's URI
...
setSVGDocument(doc2); // bravo!
----- Original Message -----
From: "Thomas DeWeese" <Th...@Kodak.com>
Sent: Thursday, August 18, 2005 2:49 AM
> As I said earlier for internal references
> (URL's that start with '#') or absolute references
> (URL's that start with '<protocol>://') it shouldn't
> be needed and I consider all such cases to be errors.
Could you please be more specific? Which do you
consider to be in *error*: the API-rejected SVG file,
the SVG spec, or the batik API?
> The most logical thing would be the same as
> the source documents. However this would only
> 'hide' the problem (which may be all you are
> interested in doing).
Yes. I guess I've hid the problem. I'm curious
about what it would take to *fix* the problem.
> This isn't an SVG URI thing it's how all
> URL/URI's work (or are supposed to work).
?
Thanks again.
- Ken H.
Re: BridgeException afer deepCloneDocument
Posted by Thomas DeWeese <Th...@Kodak.com>.
Kenneth B. Harwood wrote:
> After (deep) copying an SVG Document, I
> attempt to render using /setSVGDocument/. I
> receive a BridgeException associated with an invalid <linear gradient>.
> ParsedURL purl = new ParsedURL(doc.getURL(), uri);
> if (!purl.complete())
> throw new BridgeException(paintElement,
> ERR_URI_MALFORMED, <--- EXCEPTION PROBABLY HERE
> new Object[] {uri});
> I can understand a URI for the "original"
> document but why should a URI be required
> for its clone?
As I said earlier for internal references
(URL's that start with '#') or absolute references
(URL's that start with '<protocol>://') it shouldn't
be needed and I consider all such cases to be errors.
The basic problem is that there are also relative
URL's (things like "batikLogo.svg#batikTag") that do
need the document's URL in order to resolve where
the relative document is in respect to the current
document.
> Apparently the URI for my clone is ~null~. That seems perfectly
> logical. But then /extractStop()/ tries to parse it!
Actually it checks to see if the URL is complete,
i.e. if it has a protocol, host, and path. Your's isn't
but but is still usable in this case (since presumably
it starts with '#').
> What *should* a clone's URI truly be?
> If someone can tell me that I'm sure
> I can figure out when/where to set it.
The most logical thing would be the same as
the source documents. However this would only
'hide' the problem (which may be all you are
interested in doing).
> I was getting errors like this a couple of
> weeks ago; an input stream & transcoding
> problem.
Yes, at the time I also considered it a bug
but I couldn't see how the problem was really
occurring.
> The usergroup archive correctly
> diagnosed my problem was related to
> a screwy document URI. Can anyone point
> me to some docus where I can get a grip
> on this SVG URI thing?
This isn't an SVG URI thing it's how all
URL/URI's work (or are supposed to work).
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
BridgeException afer deepCloneDocument
Posted by "Kenneth B. Harwood" <ru...@comcast.net>.
After (deep) copying an SVG Document, I
attempt to render using setSVGDocument. I
receive a BridgeException associated with an invalid <linear gradient>.
The stackTrace shows that the Exception is being generated within AbstractSVGGradientElementBridge:
protected static List extractStop(Element paintElement,
float opacity,
BridgeContext ctx) {
List refs = new LinkedList();
for (;;) {
List stops = extractLocalStop(paintElement, opacity, ctx);
if (stops != null) {
return stops; // stop elements found, exit
}
String uri = XLinkSupport.getXLinkHref(paintElement);
if (uri.length() == 0) {
return null; // no xlink:href found, exit
}
// check if there is circular dependencies
SVGOMDocument doc = (SVGOMDocument)paintElement.getOwnerDocument();
ParsedURL purl = new ParsedURL(doc.getURL(), uri);
if (!purl.complete())
throw new BridgeException(paintElement,
ERR_URI_MALFORMED, <--- EXCEPTION PROBABLY HERE
new Object[] {uri});
if (contains(refs, purl)) {
throw new BridgeException(paintElement,
ERR_XLINK_HREF_CIRCULAR_DEPENDENCIES,
new Object[] {uri});
}
refs.add(purl);
paintElement = ctx.getReferencedElement(paintElement, uri);
}
}
I can understand a URI for the "original"
document but why should a URI be required
for its clone? Apparently the URI for my
clone is ~null~. That seems perfectly
logical. But then extractStop() tries to
parse it!
What *should* a clone's URI truly be?
If someone can tell me that I'm sure
I can figure out when/where to set it.
I was getting errors like this a couple of
weeks ago; an input stream & transcoding
problem. The usergroup archive correctly
diagnosed my problem was related to
a screwy document URI. Can anyone point
me to some docus where I can get a grip
on this SVG URI thing?
- Ken H.