hillion 01/10/11 11:37:33 Modified: sources/org/apache/batik/apps/svgbrowser JSVGViewerFrame.java Main.java sources/org/apache/batik/css AbstractViewCSS.java DOMMediaList.java sources/org/apache/batik/dom StyleSheetFactory.java StyleSheetProcessingInstruction.java sources/org/apache/batik/dom/svg SVGDOMImplementation.java SVGOMDocument.java test-sources/org/apache/batik/test/svg SVGRenderingAccuracyTest.java Log: Fixed bugs with: - CSS media, - alternate stylesheets. Revision Changes Path 1.55 +27 -41 xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java Index: JSVGViewerFrame.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- JSVGViewerFrame.java 2001/10/10 13:42:37 1.54 +++ JSVGViewerFrame.java 2001/10/11 18:37:33 1.55 @@ -143,6 +143,10 @@ import org.w3c.dom.stylesheets.DocumentStyle; import org.w3c.dom.stylesheets.StyleSheetList; +import org.w3c.dom.traversal.DocumentTraversal; +import org.w3c.dom.traversal.NodeFilter; +import org.w3c.dom.traversal.TreeWalker; + import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.ViewCSS; @@ -153,7 +157,7 @@ * This class represents a SVG viewer swing frame. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: JSVGViewerFrame.java,v 1.54 2001/10/10 13:42:37 tkormann Exp $ + * @version $Id: JSVGViewerFrame.java,v 1.55 2001/10/11 18:37:33 hillion Exp $ */ public class JSVGViewerFrame extends JFrame @@ -1184,56 +1188,38 @@ protected void update() { Iterator it = components.iterator(); - if (it.hasNext()) { - + SVGDocument doc = svgCanvas.getSVGDocument(); + while (it.hasNext()) { JComponent stylesheetMenu = (JComponent)it.next(); stylesheetMenu.removeAll(); stylesheetMenu.setEnabled(false); - SVGDocument doc = svgCanvas.getSVGDocument(); - NodeList children = doc.getChildNodes(); ButtonGroup buttonGroup = new ButtonGroup(); - HashTable stylesheetTitles = new HashTable(); - - // !!! The traversal should be recursive - for (int ix=0; ix < children.getLength(); ix++) { - Node n = children.item(ix); - if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && - n instanceof StyleSheetProcessingInstruction) { - - String data = ((ProcessingInstruction)n).getData(); - - HashTable attrs = new HashTable(); - attrs.put("alternate", "no"); - - DOMUtilities.parseStyleSheetPIData(data, attrs); + TreeWalker tw; + tw = ((DocumentTraversal)doc).createTreeWalker + (doc, + NodeFilter.SHOW_PROCESSING_INSTRUCTION, + null, + true); + + for (Node n = tw.nextNode(); n != null; n = tw.nextNode()) { + if (n instanceof StyleSheetProcessingInstruction) { + StyleSheetProcessingInstruction sspi; + sspi = (StyleSheetProcessingInstruction)n; + HashTable attrs = sspi.getPseudoAttributes(); final String title = (String)attrs.get("title"); - - // If no title is specified, then the stylesheet should - // always be applied - - // If the title has already been found, then it is part - // of a group, and no new menu option is needed - if (title != null && stylesheetTitles.get(title) == null) { - stylesheetTitles.put(title, title); - + String alt = (String)attrs.get("alternate"); + if (title != null && "yes".equals(alt)) { JRadioButtonMenuItem button; button = new JRadioButtonMenuItem(title); - if (((String)attrs.get("alternate")).equals("no")) { - button.setSelected(true); - } + button.addActionListener (new java.awt.event.ActionListener() { - public void actionPerformed (ActionEvent e) { - SVGDocument doc = svgCanvas.getSVGDocument(); - StyleSheetList l; - l = ((DocumentStyle)doc).getStyleSheets(); - for (int i = 0; i < l.getLength(); i++) { - CSSStyleSheet ss; - ss = (CSSStyleSheet)l.item(i); - ss.setDisabled(!title.equals(ss.getTitle())); - } - ((SVGOMDocument)doc).clearViewCSS(); + public void actionPerformed(ActionEvent e) { + SVGOMDocument doc; + doc = (SVGOMDocument)svgCanvas.getSVGDocument(); + doc.enableAlternateStyleSheet(title); + doc.clearViewCSS(); svgCanvas.setSVGDocument(doc); } }); 1.17 +8 -13 xml-batik/sources/org/apache/batik/apps/svgbrowser/Main.java Index: Main.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/Main.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- Main.java 2001/10/10 13:42:37 1.16 +++ Main.java 2001/10/11 18:37:33 1.17 @@ -45,7 +45,7 @@ * This class contains the main method of an SVG viewer. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: Main.java,v 1.16 2001/10/10 13:42:37 tkormann Exp $ + * @version $Id: Main.java,v 1.17 2001/10/11 18:37:33 hillion Exp $ */ public class Main implements Application { @@ -411,11 +411,11 @@ * Returns the user languages. */ public String getLanguages() { - if (preferenceDialog == null) { - return Locale.getDefault().getLanguage(); - } - return preferenceDialog.getPreferenceManager().getString + String s = preferenceManager.getString (PreferenceDialog.PREFERENCE_KEY_LANGUAGES); + return (s == null) + ? Locale.getDefault().getLanguage() + : s; } /** @@ -423,10 +423,7 @@ * @return null if no user style sheet was specified. */ public String getUserStyleSheetURI() { - if (preferenceDialog == null) { - return null; - } - return preferenceDialog.getPreferenceManager().getString + return preferenceManager.getString (PreferenceDialog.PREFERENCE_KEY_USER_STYLESHEET); } @@ -435,10 +432,8 @@ * @return empty string if no CSS media was specified. */ public String getMedia() { - if (preferenceDialog == null) { - return ""; - } - return preferenceDialog.getPreferenceManager().getString + String s = preferenceManager.getString (PreferenceDialog.PREFERENCE_KEY_CSS_MEDIA); + return (s == null) ? "screen" : s; } } 1.18 +3 -2 xml-batik/sources/org/apache/batik/css/AbstractViewCSS.java Index: AbstractViewCSS.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/AbstractViewCSS.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- AbstractViewCSS.java 2001/10/09 12:29:47 1.17 +++ AbstractViewCSS.java 2001/10/11 18:37:33 1.18 @@ -44,7 +44,7 @@ * {@link org.w3c.dom.css.ViewCSS} interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AbstractViewCSS.java,v 1.17 2001/10/09 12:29:47 hillion Exp $ + * @version $Id: AbstractViewCSS.java,v 1.18 2001/10/11 18:37:33 hillion Exp $ */ public abstract class AbstractViewCSS implements ViewCSS { @@ -558,7 +558,8 @@ } for (int i = 0; i < ml.getLength(); i++) { for (int j = 0; j < media.getLength(); j++) { - if (ml.item(i).equalsIgnoreCase(media.item(j))) { + if (media.item(j).equalsIgnoreCase("all") || + ml.item(i).equalsIgnoreCase(media.item(j))) { return true; } } 1.2 +5 -2 xml-batik/sources/org/apache/batik/css/DOMMediaList.java Index: DOMMediaList.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/DOMMediaList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DOMMediaList.java 2000/10/10 18:37:15 1.1 +++ DOMMediaList.java 2001/10/11 18:37:33 1.2 @@ -20,7 +20,7 @@ * interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: DOMMediaList.java,v 1.1 2000/10/10 18:37:15 hillion Exp $ + * @version $Id: DOMMediaList.java,v 1.2 2001/10/11 18:37:33 hillion Exp $ */ public class DOMMediaList implements MediaList { /** @@ -63,8 +63,9 @@ * org.w3c.dom.stylesheets.MediaList#setMediaText(String)}. */ public void setMediaText(String mediaText) throws DOMException { + mediaText = mediaText.toLowerCase(); list.clear(); - if (!"all".equals(mediaText)) { + if (!"all".equalsIgnoreCase(mediaText)) { StringTokenizer st = new StringTokenizer(mediaText, " ,"); while (st.hasMoreTokens()) { list.add(st.nextToken()); @@ -96,6 +97,7 @@ * org.w3c.dom.stylesheets.MediaList#deleteMedium(String)}. */ public void deleteMedium(String oldMedium) throws DOMException { + oldMedium = oldMedium.toLowerCase(); if (!list.remove(oldMedium)) { throw CSSDOMExceptionFactory.createDOMException (DOMException.INVALID_ACCESS_ERR, @@ -109,6 +111,7 @@ * org.w3c.dom.stylesheets.MediaList#appendMedium(String)}. */ public void appendMedium(String newMedium) throws DOMException { + newMedium = newMedium.toLowerCase(); list.remove(newMedium); list.add(newMedium); } 1.2 +3 -2 xml-batik/sources/org/apache/batik/dom/StyleSheetFactory.java Index: StyleSheetFactory.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/StyleSheetFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- StyleSheetFactory.java 2000/10/10 18:39:00 1.1 +++ StyleSheetFactory.java 2001/10/11 18:37:33 1.2 @@ -8,6 +8,7 @@ package org.apache.batik.dom; +import org.apache.batik.dom.util.HashTable; import org.w3c.dom.Node; import org.w3c.dom.stylesheets.StyleSheet; @@ -15,7 +16,7 @@ * This interface represents a StyleSheet factory. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: StyleSheetFactory.java,v 1.1 2000/10/10 18:39:00 hillion Exp $ + * @version $Id: StyleSheetFactory.java,v 1.2 2001/10/11 18:37:33 hillion Exp $ */ public interface StyleSheetFactory { /** @@ -23,5 +24,5 @@ * processing instruction or return null when it is not possible * to create the given stylesheet. */ - StyleSheet createStyleSheet(Node node, String data); + StyleSheet createStyleSheet(Node node, HashTable pseudoAttrs); } 1.4 +23 -3 xml-batik/sources/org/apache/batik/dom/StyleSheetProcessingInstruction.java Index: StyleSheetProcessingInstruction.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/StyleSheetProcessingInstruction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StyleSheetProcessingInstruction.java 2000/12/06 21:22:00 1.3 +++ StyleSheetProcessingInstruction.java 2001/10/11 18:37:33 1.4 @@ -8,7 +8,9 @@ package org.apache.batik.dom; +import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.dom.util.HashTable; + import org.w3c.dom.DOMException; import org.w3c.dom.Node; import org.w3c.dom.stylesheets.LinkStyle; @@ -19,9 +21,8 @@ * instructions. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: StyleSheetProcessingInstruction.java,v 1.3 2000/12/06 21:22:00 hillion Exp $ + * @version $Id: StyleSheetProcessingInstruction.java,v 1.4 2001/10/11 18:37:33 hillion Exp $ */ - public class StyleSheetProcessingInstruction extends AbstractProcessingInstruction implements LinkStyle { @@ -42,6 +43,11 @@ protected StyleSheetFactory factory; /** + * The pseudo attributes. + */ + protected transient HashTable pseudoAttributes; + + /** * Creates a new ProcessingInstruction object. */ protected StyleSheetProcessingInstruction() { @@ -92,18 +98,32 @@ */ public StyleSheet getSheet() { if (sheet == null) { - sheet = factory.createStyleSheet(this, getData()); + sheet = factory.createStyleSheet(this, getPseudoAttributes()); } return sheet; } /** + * Returns the pseudo attributes in a table. + */ + public HashTable getPseudoAttributes() { + if (pseudoAttributes == null) { + pseudoAttributes = new HashTable(); + pseudoAttributes.put("alternate", "no"); + pseudoAttributes.put("media", "all"); + DOMUtilities.parseStyleSheetPIData(data, pseudoAttributes); + } + return pseudoAttributes; + } + + /** * <b>DOM</b>: Implements {@link * org.w3c.dom.ProcessingInstruction#setData(String)}. */ public void setData(String data) throws DOMException { super.setData(data); sheet = null; + pseudoAttributes = null; } /** 1.16 +3 -12 xml-batik/sources/org/apache/batik/dom/svg/SVGDOMImplementation.java Index: SVGDOMImplementation.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGDOMImplementation.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- SVGDOMImplementation.java 2001/09/28 15:40:08 1.15 +++ SVGDOMImplementation.java 2001/10/11 18:37:33 1.16 @@ -54,7 +54,7 @@ * It provides support the SVG 1.0 documents. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: SVGDOMImplementation.java,v 1.15 2001/09/28 15:40:08 hillion Exp $ + * @version $Id: SVGDOMImplementation.java,v 1.16 2001/10/11 18:37:33 hillion Exp $ */ public class SVGDOMImplementation extends AbstractDOMImplementation @@ -203,12 +203,7 @@ * Creates a stylesheet from the data of an xml-stylesheet * processing instruction or return null. */ - public StyleSheet createStyleSheet(Node n, String data) { - HashTable attrs = new HashTable(); - attrs.put("alternate", "no"); - attrs.put("media", "all"); - DOMUtilities.parseStyleSheetPIData(data, attrs); - + public StyleSheet createStyleSheet(Node n, HashTable attrs) { String type = (String)attrs.get("type"); if ("text/css".equals(type)) { @@ -232,11 +227,7 @@ CSSDocumentHandler.createParser()); CSSDocumentHandler.parseStyleSheet(ss, url.toString()); - if (title == null || alternate.equals("no")) { - ss.setDisabled (false); - } else { - ss.setDisabled (true); - } + ss.setDisabled(title != null && "yes".equals(alternate)); return ss; } catch (Exception e) { } 1.40 +19 -1 xml-batik/sources/org/apache/batik/dom/svg/SVGOMDocument.java Index: SVGOMDocument.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGOMDocument.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- SVGOMDocument.java 2001/09/28 15:40:08 1.39 +++ SVGOMDocument.java 2001/10/11 18:37:33 1.40 @@ -69,7 +69,7 @@ * This class implements {@link SVGDocument}. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: SVGOMDocument.java,v 1.39 2001/09/28 15:40:08 hillion Exp $ + * @version $Id: SVGOMDocument.java,v 1.40 2001/10/11 18:37:33 hillion Exp $ */ public class SVGOMDocument extends AbstractDocument @@ -422,6 +422,24 @@ } for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling()) { getStyleSheets(c, l); + } + } + + /** + * Enables the alternate stylesheet with the given title. + */ + public void enableAlternateStyleSheet(String title) { + getStyleSheets(); + for (int i = 0; i < styleSheets.getLength(); i++) { + StyleSheet ss = (StyleSheet)styleSheets.item(i); + Node on = ss.getOwnerNode(); + if (on instanceof StyleSheetProcessingInstruction) { + StyleSheetProcessingInstruction sspi; + sspi = (StyleSheetProcessingInstruction)on; + if ("yes".equals(sspi.getPseudoAttributes().get("alternate"))) { + ss.setDisabled(!title.equals(ss.getTitle())); + } + } } } 1.14 +2 -2 xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java Index: SVGRenderingAccuracyTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- SVGRenderingAccuracyTest.java 2001/10/08 14:51:35 1.13 +++ SVGRenderingAccuracyTest.java 2001/10/11 18:37:33 1.14 @@ -64,7 +64,7 @@ * all pixel values are the same). * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: SVGRenderingAccuracyTest.java,v 1.13 2001/10/08 14:51:35 vhardy Exp $ + * @version $Id: SVGRenderingAccuracyTest.java,v 1.14 2001/10/11 18:37:33 hillion Exp $ */ public class SVGRenderingAccuracyTest extends AbstractTest { /** @@ -355,7 +355,7 @@ * the accuracy test. For example, this can be useful to * test the alternate stylesheet support. */ - private final Document manipulateSVGDocument(Document doc) { + protected Document manipulateSVGDocument(Document doc) { return doc; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]