tkormann 01/11/28 08:07:47 Modified: . build.xml sources/org/apache/batik/apps/svgbrowser JSVGViewerFrame.java sources/org/apache/batik/bridge GVTBuilder.java sources/org/apache/batik/swing JSVGCanvas.java Added: resources/org/apache/batik/util/gui/resources JErrorPane.properties sources/org/apache/batik/util/gui JErrorPane.java Log: Add a new Dialog with the canvas or the browser go in error. Now we can expand the dialog and see the stacktrace (you can even copy/paste the trace and an email to the Batik team or enter a bug in bugzilla). Revision Changes Path 1.95 +2 -2 xml-batik/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-batik/build.xml,v retrieving revision 1.94 retrieving revision 1.95 diff -u -r1.94 -r1.95 --- build.xml 2001/11/20 14:35:52 1.94 +++ build.xml 2001/11/28 16:07:46 1.95 @@ -44,7 +44,7 @@ [win32] .\build.bat help - $Id: build.xml,v 1.94 2001/11/20 14:35:52 vhardy Exp $ + $Id: build.xml,v 1.95 2001/11/28 16:07:46 tkormann Exp $ --> @@ -238,7 +238,7 @@ description="Compiles the source files"> <mkdir dir="${dest}"/> - <javac srcdir="${src}" destdir="${dest}" deprecation="on" > + <javac srcdir="${src}" destdir="${dest}" deprecation="on" debug="on"> <classpath refid="libs-classpath"/> <exclude name="**/*.html"/> <exclude name="**/rhino/*" unless="rhino.present"/> 1.1 xml-batik/resources/org/apache/batik/util/gui/resources/JErrorPane.properties Index: JErrorPane.properties =================================================================== ############################################################################# # Copyright (C) The Apache Software Foundation. All rights reserved. # # ------------------------------------------------------------------------- # # This software is published under the terms of the Apache Software License # # version 1.1, a copy of which has been included with this distribution in # # the LICENSE file. # ############################################################################# # # The resources for the JErrorPane # # Author: [EMAIL PROTECTED] # $Id: JErrorPane.properties,v 1.1 2001/11/28 16:07:47 tkormann Exp $ # ShowDetailButton.text = Show Details ShowDetailButton.text2 = Hide Details ShowDetailButton.mnemonic = D ShowDetailButton.action = ShowDetailButtonAction 1.65 +79 -71 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.64 retrieving revision 1.65 diff -u -r1.64 -r1.65 --- JSVGViewerFrame.java 2001/11/12 15:59:35 1.64 +++ JSVGViewerFrame.java 2001/11/28 16:07:47 1.65 @@ -118,6 +118,7 @@ import org.apache.batik.util.ParsedURL; import org.apache.batik.util.MimeTypeConstants; import org.apache.batik.util.gui.DOMViewer; +import org.apache.batik.util.gui.JErrorPane; import org.apache.batik.util.gui.LocationBar; import org.apache.batik.util.gui.MemoryMonitor; import org.apache.batik.util.gui.URIChooser; @@ -142,7 +143,7 @@ import org.w3c.dom.stylesheets.DocumentStyle; import org.w3c.dom.stylesheets.StyleSheetList; - + import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.ViewCSS; @@ -153,7 +154,7 @@ * This class represents a SVG viewer swing frame. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: JSVGViewerFrame.java,v 1.64 2001/11/12 15:59:35 hillion Exp $ + * @version $Id: JSVGViewerFrame.java,v 1.65 2001/11/28 16:07:47 tkormann Exp $ */ public class JSVGViewerFrame extends JFrame @@ -384,14 +385,14 @@ listeners.put(EXIT_ACTION, application.createExitAction(this)); listeners.put(VIEW_SOURCE_ACTION, new ViewSourceAction()); - javax.swing.ActionMap cMap = svgCanvas.getActionMap(); - listeners.put(RESET_TRANSFORM_ACTION, - cMap.get(JSVGCanvas.RESET_TRANSFORM_ACTION)); - listeners.put(ZOOM_IN_ACTION, - cMap.get(JSVGCanvas.ZOOM_IN_ACTION)); + javax.swing.ActionMap cMap = svgCanvas.getActionMap(); + listeners.put(RESET_TRANSFORM_ACTION, + cMap.get(JSVGCanvas.RESET_TRANSFORM_ACTION)); + listeners.put(ZOOM_IN_ACTION, + cMap.get(JSVGCanvas.ZOOM_IN_ACTION)); listeners.put(ZOOM_OUT_ACTION, - cMap.get(JSVGCanvas.ZOOM_OUT_ACTION)); - + cMap.get(JSVGCanvas.ZOOM_OUT_ACTION)); + listeners.put(PREVIOUS_TRANSFORM_ACTION, previousTransformAction); listeners.put(NEXT_TRANSFORM_ACTION, nextTransformAction); listeners.put(USE_STYLESHEET_ACTION, useStylesheetAction); @@ -838,11 +839,11 @@ final SVGDocument doc = svgDocument; new Thread() { public void run(){ - String uri = doc.getURL(); - String fragment = svgCanvas.getFragmentIdentifier(); - if (fragment != null) { - uri += "#"+fragment; - } + String uri = doc.getURL(); + String fragment = svgCanvas.getFragmentIdentifier(); + if (fragment != null) { + uri += "#"+fragment; + } // // Build a PrintTranscoder to handle printing // of the svgDocument object @@ -897,8 +898,8 @@ int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this); if (choice == JFileChooser.APPROVE_OPTION) { - float quality = - JPEGOptionPanel.showDialog(JSVGViewerFrame.this); + float quality = + JPEGOptionPanel.showDialog(JSVGViewerFrame.this); final File f = fileChooser.getSelectedFile(); BufferedImage buffer = svgCanvas.getOffScreen(); @@ -911,11 +912,11 @@ int h = buffer.getHeight(); final ImageTranscoder trans = new JPEGTranscoder(); trans.addTranscodingHint - (JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, - application.getXMLParserClassName()); + (JPEGTranscoder.KEY_XML_PARSER_CLASSNAME, + application.getXMLParserClassName()); trans.addTranscodingHint - (JPEGTranscoder.KEY_QUALITY, new Float(quality)); - + (JPEGTranscoder.KEY_QUALITY, new Float(quality)); + final BufferedImage img = trans.createImage(w, h); // paint the buffer to the image @@ -1216,7 +1217,7 @@ if (title != null && "yes".equals(alt)) { JRadioButtonMenuItem button; button = new JRadioButtonMenuItem(title); - + button.addActionListener (new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { @@ -1227,7 +1228,7 @@ svgCanvas.setSVGDocument(doc); } }); - + buttonGroup.add(button); stylesheetMenu.add(button); stylesheetMenu.setEnabled(true); @@ -1524,8 +1525,8 @@ } stopAction.update(false); svgCanvas.setCursor(DEFAULT_CURSOR); - svgCanvas.setSelectionOverlayXORMode - (application.isSelectionOverlayXORMode()); + svgCanvas.setSelectionOverlayXORMode + (application.isSelectionOverlayXORMode()); if (autoAdjust) { pack(); } @@ -1542,8 +1543,8 @@ statusBar.setMessage(resources.getString("Message.treeCancelled")); stopAction.update(false); svgCanvas.setCursor(DEFAULT_CURSOR); - svgCanvas.setSelectionOverlayXORMode - (application.isSelectionOverlayXORMode()); + svgCanvas.setSelectionOverlayXORMode + (application.isSelectionOverlayXORMode()); } /** @@ -1557,8 +1558,8 @@ statusBar.setMessage(resources.getString("Message.treeFailed")); stopAction.update(false); svgCanvas.setCursor(DEFAULT_CURSOR); - svgCanvas.setSelectionOverlayXORMode - (application.isSelectionOverlayXORMode()); + svgCanvas.setSelectionOverlayXORMode + (application.isSelectionOverlayXORMode()); if (autoAdjust) { pack(); } @@ -1678,8 +1679,11 @@ * Displays an error message. */ public void displayError(String message) { - JOptionPane pane; - pane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE); + if (debug) { + System.err.println(message); + } + JOptionPane pane = + new JOptionPane(message, JOptionPane.ERROR_MESSAGE); JDialog dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR"); dialog.setModal(false); dialog.show(); // Safe to be called from any thread @@ -1692,7 +1696,11 @@ if (debug) { ex.printStackTrace(); } - displayError(ex.getMessage()); + JOptionPane pane = + new JErrorPane(ex, JOptionPane.ERROR_MESSAGE); + JDialog dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR"); + dialog.setModal(false); + dialog.show(); // Safe to be called from any thread } /** @@ -1732,19 +1740,19 @@ return application.getXMLParserClassName(); } - /** - * Returns true if the XML parser must be in validation mode, false - * otherwise. - */ - public boolean isXMLParserValidating() { - return application.isXMLParserValidating(); - } + /** + * Returns true if the XML parser must be in validation mode, false + * otherwise. + */ + public boolean isXMLParserValidating() { + return application.isXMLParserValidating(); + } /** * Returns this user agent's CSS media. */ public String getMedia() { - return application.getMedia(); + return application.getMedia(); } /** @@ -1776,40 +1784,40 @@ * A FileFilter used when exporting the SVG document as an image. */ protected static class ImageFileFilter extends FileFilter { + + /** The extension of the image filename. */ + protected String extension; + + public ImageFileFilter(String extension) { + this.extension = extension; + } - /** The extension of the image filename. */ - protected String extension; + /** + * Returns true if <tt>f</tt> is a file with the correct extension, + * false otherwise. + */ + public boolean accept(File f) { + boolean accept = false; + String fileName = null; + if (f != null) { + if (f.isDirectory()) { + accept = true; + } else { + fileName = f.getPath().toLowerCase(); + if (fileName.endsWith(extension)) { + accept = true; + } + } + } + return accept; + } - public ImageFileFilter(String extension) { - this.extension = extension; - } - - /** - * Returns true if <tt>f</tt> is a file with the correct extension, - * false otherwise. - */ - public boolean accept(File f) { - boolean accept = false; - String fileName = null; - if (f != null) { - if (f.isDirectory()) { - accept = true; - } else { - fileName = f.getPath().toLowerCase(); - if (fileName.endsWith(extension)) { - accept = true; - } - } - } - return accept; - } - - /** - * Returns the file description - */ - public String getDescription() { - return extension; - } + /** + * Returns the file description + */ + public String getDescription() { + return extension; + } } } 1.14 +3 -3 xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java Index: GVTBuilder.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- GVTBuilder.java 2001/10/10 15:30:59 1.13 +++ GVTBuilder.java 2001/11/28 16:07:47 1.14 @@ -30,7 +30,7 @@ * This class is responsible for creating a GVT tree using an SVG DOM tree. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: GVTBuilder.java,v 1.13 2001/10/10 15:30:59 cjolif Exp $ + * @version $Id: GVTBuilder.java,v 1.14 2001/11/28 16:07:47 tkormann Exp $ */ public class GVTBuilder implements SVGConstants { @@ -79,7 +79,7 @@ ex.setGraphicsNode(rootNode); Element errElement = ex.getElement(); ex.setLineNumber(ctx.getDocumentLoader().getLineNumber(errElement)); - ex.printStackTrace(); + //ex.printStackTrace(); throw ex; // re-throw the udpated exception } finally { if (topNode != null) { @@ -199,7 +199,7 @@ gnBridge.buildGraphicsNode(ctx, e, errNode); ex.setGraphicsNode(null); } - ex.printStackTrace(); + //ex.printStackTrace(); throw ex; } } 1.30 +193 -187 xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java Index: JSVGCanvas.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- JSVGCanvas.java 2001/11/14 14:34:06 1.29 +++ JSVGCanvas.java 2001/11/28 16:07:47 1.30 @@ -47,6 +47,7 @@ import org.apache.batik.swing.svg.SVGDocumentLoaderEvent; import org.apache.batik.swing.svg.SVGUserAgent; +import org.apache.batik.util.gui.JErrorPane; import org.apache.batik.util.SVGConstants; import org.apache.batik.util.XMLConstants; @@ -68,7 +69,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: JSVGCanvas.java,v 1.29 2001/11/14 14:34:06 hillion Exp $ + * @version $Id: JSVGCanvas.java,v 1.30 2001/11/28 16:07:47 tkormann Exp $ */ public class JSVGCanvas extends JSVGComponent { @@ -91,7 +92,7 @@ * The key for the Action to scroll down. */ public static final String SCROLL_DOWN_ACTION = "ScrollDown"; - + /** * The key for the Action to quickly scroll right. */ @@ -111,7 +112,7 @@ * The key for the Action to quickly scroll down. */ public static final String FAST_SCROLL_DOWN_ACTION = "FastScrollDown"; - + /** * The key for the Action to zoom in. */ @@ -121,7 +122,7 @@ * The key for the Action to zoom out. */ public static final String ZOOM_OUT_ACTION = "ZoomOut"; - + /** * The key for the Action to reset the transform. */ @@ -187,17 +188,17 @@ * @param ua a SVGUserAgent instance or null. * @param eventEnabled Whether the GVT tree should be reactive to mouse and * key events. - * @param selectableText Whether the text should be selectable. + * @param selectableText Whether the text should be selectable. */ - public JSVGCanvas(SVGUserAgent ua, - boolean eventsEnabled, + public JSVGCanvas(SVGUserAgent ua, + boolean eventsEnabled, boolean selectableText) { super(ua, eventsEnabled, selectableText); setPreferredSize(new Dimension(200, 200)); setMinimumSize(new Dimension(100, 100)); - + List intl = getInteractors(); intl.add(zoomInteractor); intl.add(imageZoomInteractor); @@ -205,17 +206,17 @@ intl.add(rotateInteractor); intl.add(resetTransformInteractor); - installActions(); + installActions(); - if (eventsEnabled) { - addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent evt) { - requestFocus(); - } - }); + if (eventsEnabled) { + addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent evt) { + requestFocus(); + } + }); - installKeyboardActions(); - } + installKeyboardActions(); + } } /** @@ -223,65 +224,65 @@ * <tt>Action</tt>s. */ protected void installActions() { - ActionMap actionMap = getActionMap(); - - actionMap.put(SCROLL_RIGHT_ACTION, new ScrollRightAction(10)); - actionMap.put(SCROLL_LEFT_ACTION, new ScrollLeftAction(10)); - actionMap.put(SCROLL_UP_ACTION, new ScrollUpAction(10)); - actionMap.put(SCROLL_DOWN_ACTION, new ScrollDownAction(10)); - - actionMap.put(FAST_SCROLL_RIGHT_ACTION, new ScrollRightAction(30)); - actionMap.put(FAST_SCROLL_LEFT_ACTION, new ScrollLeftAction(30)); - actionMap.put(FAST_SCROLL_UP_ACTION, new ScrollUpAction(30)); - actionMap.put(FAST_SCROLL_DOWN_ACTION, new ScrollDownAction(30)); + ActionMap actionMap = getActionMap(); - actionMap.put(ZOOM_IN_ACTION, new ZoomInAction()); - actionMap.put(ZOOM_OUT_ACTION, new ZoomOutAction()); + actionMap.put(SCROLL_RIGHT_ACTION, new ScrollRightAction(10)); + actionMap.put(SCROLL_LEFT_ACTION, new ScrollLeftAction(10)); + actionMap.put(SCROLL_UP_ACTION, new ScrollUpAction(10)); + actionMap.put(SCROLL_DOWN_ACTION, new ScrollDownAction(10)); + + actionMap.put(FAST_SCROLL_RIGHT_ACTION, new ScrollRightAction(30)); + actionMap.put(FAST_SCROLL_LEFT_ACTION, new ScrollLeftAction(30)); + actionMap.put(FAST_SCROLL_UP_ACTION, new ScrollUpAction(30)); + actionMap.put(FAST_SCROLL_DOWN_ACTION, new ScrollDownAction(30)); - actionMap.put(RESET_TRANSFORM_ACTION, new ResetTransformAction()); + actionMap.put(ZOOM_IN_ACTION, new ZoomInAction()); + actionMap.put(ZOOM_OUT_ACTION, new ZoomOutAction()); + + actionMap.put(RESET_TRANSFORM_ACTION, new ResetTransformAction()); } /** * Builds the InputMap of this canvas with a set of predefined - * <tt>Action</tt>s. + * <tt>Action</tt>s. */ protected void installKeyboardActions() { - InputMap inputMap = getInputMap(JComponent.WHEN_FOCUSED); - KeyStroke key; + InputMap inputMap = getInputMap(JComponent.WHEN_FOCUSED); + KeyStroke key; - key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0); - inputMap.put(key, SCROLL_RIGHT_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0); + inputMap.put(key, SCROLL_RIGHT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0); - inputMap.put(key, SCROLL_LEFT_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0); + inputMap.put(key, SCROLL_LEFT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0); - inputMap.put(key, SCROLL_UP_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0); + inputMap.put(key, SCROLL_UP_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0); - inputMap.put(key, SCROLL_DOWN_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0); + inputMap.put(key, SCROLL_DOWN_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_MASK); - inputMap.put(key, FAST_SCROLL_RIGHT_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_MASK); + inputMap.put(key, FAST_SCROLL_RIGHT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_MASK); - inputMap.put(key, FAST_SCROLL_LEFT_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_MASK); + inputMap.put(key, FAST_SCROLL_LEFT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_MASK); - inputMap.put(key, FAST_SCROLL_UP_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_MASK); + inputMap.put(key, FAST_SCROLL_UP_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_MASK); - inputMap.put(key, FAST_SCROLL_DOWN_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_MASK); + inputMap.put(key, FAST_SCROLL_DOWN_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_MASK); - inputMap.put(key, ZOOM_IN_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_MASK); + inputMap.put(key, ZOOM_IN_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK); - inputMap.put(key, ZOOM_OUT_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK); + inputMap.put(key, ZOOM_OUT_ACTION); - key = KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_MASK); - inputMap.put(key, RESET_TRANSFORM_ACTION); + key = KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_MASK); + inputMap.put(key, RESET_TRANSFORM_ACTION); } /** @@ -307,7 +308,7 @@ * property. * * @param propertyName the name of the property to listen on - * @param pcl the property change listener to add + * @param pcl the property change listener to add */ public void addPropertyChangeListener(String propertyName, PropertyChangeListener pcl) { @@ -319,7 +320,7 @@ * property. * * @param propertyName the name of the property that was listened on - * @param pcl the property change listener to remove + * @param pcl the property change listener to remove */ public void removePropertyChangeListener(String propertyName, PropertyChangeListener pcl) { @@ -430,15 +431,15 @@ } else { getInteractors().remove(resetTransformInteractor); } - pcs.firePropertyChange("enableResetTransformInteractor", - oldValue, - b); + pcs.firePropertyChange("enableResetTransformInteractor", + oldValue, + b); } } - + /** * Returns true if the reset transform interactor is enabled, false - * otherwise. + * otherwise. */ public boolean getEnableResetTransformInteractor() { return isResetTransformInteractorEnabled; @@ -462,7 +463,7 @@ loadSVGDocument(uri); pcs.firePropertyChange("URI", oldValue, uri); } - + /** * Creates a UserAgent. */ @@ -486,7 +487,7 @@ * Called when the loading of a document was started. */ public void documentLoadingStarted(SVGDocumentLoaderEvent e) { - JSVGCanvas.this.setToolTipText(null); + JSVGCanvas.this.setToolTipText(null); } } @@ -499,17 +500,17 @@ * A swing action to reset the rendering transform of the canvas. */ protected class ResetTransformAction extends AbstractAction { - public void actionPerformed(ActionEvent evt) { - setFragmentIdentifier(null); + public void actionPerformed(ActionEvent evt) { + setFragmentIdentifier(null); resetRenderingTransform(); - } + } } /** * A swing action to zoom in the canvas. */ protected class ZoomInAction extends AbstractAction { - public void actionPerformed(ActionEvent evt) { + public void actionPerformed(ActionEvent evt) { AffineTransform at = getRenderingTransform(); if (at != null) { Dimension dim = getSize(); @@ -520,15 +521,15 @@ t.translate(-x, -y); t.concatenate(at); setRenderingTransform(t); - } - } + } + } } /** * A swing action to zoom out the canvas. */ protected class ZoomOutAction extends AbstractAction { - public void actionPerformed(ActionEvent evt) { + public void actionPerformed(ActionEvent evt) { AffineTransform at = getRenderingTransform(); if (at != null) { Dimension dim = getSize(); @@ -539,8 +540,8 @@ t.translate(-x, -y); t.concatenate(at); setRenderingTransform(t); - } - } + } + } } /** @@ -548,37 +549,37 @@ */ protected class ScrollRightAction extends AbstractAction { - /** The scroll increment. */ - protected int inc; + /** The scroll increment. */ + protected int inc; + + public ScrollRightAction(int inc) { + this.inc = inc; + } - public ScrollRightAction(int inc) { - this.inc = inc; - } - - public void actionPerformed(ActionEvent evt) { - AffineTransform at = new AffineTransform(getRenderingTransform()); - at.translate(-inc, 0); - setRenderingTransform(at); - } + public void actionPerformed(ActionEvent evt) { + AffineTransform at = new AffineTransform(getRenderingTransform()); + at.translate(-inc, 0); + setRenderingTransform(at); + } } /** * A swing action to scroll the canvas to the left. */ protected class ScrollLeftAction extends AbstractAction { + + /** The scroll increment. */ + protected int inc; - /** The scroll increment. */ - protected int inc; + public ScrollLeftAction(int inc) { + this.inc = inc; + } - public ScrollLeftAction(int inc) { - this.inc = inc; - } - - public void actionPerformed(ActionEvent evt) { - AffineTransform at = new AffineTransform(getRenderingTransform()); - at.translate(inc, 0); - setRenderingTransform(at); - } + public void actionPerformed(ActionEvent evt) { + AffineTransform at = new AffineTransform(getRenderingTransform()); + at.translate(inc, 0); + setRenderingTransform(at); + } } /** @@ -586,18 +587,18 @@ */ protected class ScrollUpAction extends AbstractAction { - /** The scroll increment. */ - protected int inc; + /** The scroll increment. */ + protected int inc; - public ScrollUpAction(int inc) { - this.inc = inc; - } - - public void actionPerformed(ActionEvent evt) { - AffineTransform at = new AffineTransform(getRenderingTransform()); - at.translate(0, inc); - setRenderingTransform(at); - } + public ScrollUpAction(int inc) { + this.inc = inc; + } + + public void actionPerformed(ActionEvent evt) { + AffineTransform at = new AffineTransform(getRenderingTransform()); + at.translate(0, inc); + setRenderingTransform(at); + } } /** @@ -605,18 +606,18 @@ */ protected class ScrollDownAction extends AbstractAction { - /** The scroll increment. */ - protected int inc; + /** The scroll increment. */ + protected int inc; - public ScrollDownAction(int inc) { - this.inc = inc; - } - - public void actionPerformed(ActionEvent evt) { - AffineTransform at = new AffineTransform(getRenderingTransform()); - at.translate(0, -inc); - setRenderingTransform(at); - } + public ScrollDownAction(int inc) { + this.inc = inc; + } + + public void actionPerformed(ActionEvent evt) { + AffineTransform at = new AffineTransform(getRenderingTransform()); + at.translate(0, -inc); + setRenderingTransform(at); + } } // ---------------------------------------------------------------------- @@ -704,24 +705,24 @@ * The <tt>CanvasUserAgent</tt> only adds tooltips to the behavior of the * default <tt>BridgeUserAgent</tt>.<br /> A tooltip will be displayed * wheneven the mouse lingers over an element which has a <title> or a - * <desc> child element. + * <desc> child element. */ - protected class CanvasUserAgent extends BridgeUserAgent + protected class CanvasUserAgent extends BridgeUserAgent implements XMLConstants { - final String TOOLTIP_TITLE_ONLY + final String TOOLTIP_TITLE_ONLY = "JSVGCanvas.CanvasUserAgent.ToolTip.titleOnly"; - final String TOOLTIP_DESC_ONLY + final String TOOLTIP_DESC_ONLY = "JSVGCanvas.CanvasUserAgent.ToolTip.descOnly"; - final String TOOLTIP_TITLE_AND_TEXT + final String TOOLTIP_TITLE_AND_TEXT = "JSVGCanvas.CanvasUserAgent.ToolTip.titleAndDesc"; /** * The handleElement method builds a tool tip from the * content of a <title> element, a <desc> * element or both. <br/> - * Because these elements can appear in any order, here + * Because these elements can appear in any order, here * is the algorithm used to build the tool tip:<br /> * <ul> * <li>If a <title> is passed to <tt>handleElement</tt> @@ -729,70 +730,70 @@ * there is one, nothing is done (because the desc will do * it). If there in none, the tool tip is set to the value * of the <title> element content.</li> - * <li>If a <desc> is passed to <tt>handleElement</tt> + * <li>If a <desc> is passed to <tt>handleElement</tt> * the method checks if there is a <title> peer. If there * is one, the content of that peer is pre-pended to the * content of the <desc> element.</li> - * </ul> + * </ul> */ public void handleElement(Element elt, Object data){ super.handleElement(elt, data); - + if (elt.getNamespaceURI().equals(SVGConstants.SVG_NAMESPACE_URI)) { if (elt.getLocalName().equals(SVGConstants.SVG_TITLE_TAG)) { // If there is a <desc> peer, do nothing as the tooltip will // be handled when handleElement is invoked for the <desc> // peer. if (hasPeerWithTag - (elt, - SVGConstants.SVG_NAMESPACE_URI, - SVGConstants.SVG_DESC_TAG)){ + (elt, + SVGConstants.SVG_NAMESPACE_URI, + SVGConstants.SVG_DESC_TAG)){ return; } - + elt.normalize(); - if (elt.getFirstChild() == null) { - return; - } + if (elt.getFirstChild() == null) { + return; + } String toolTip = elt.getFirstChild().getNodeValue(); - if (toolTip == null || toolTip.length() == 0) { - return; - } + if (toolTip == null || toolTip.length() == 0) { + return; + } toolTip = Messages.formatMessage - (TOOLTIP_TITLE_ONLY, - new Object[]{toFormattedHTML(toolTip)}); - + (TOOLTIP_TITLE_ONLY, + new Object[]{toFormattedHTML(toolTip)}); + setToolTip((Element)(elt.getParentNode()), toolTip); } else if (elt.getLocalName().equals - (SVGConstants.SVG_DESC_TAG)) { + (SVGConstants.SVG_DESC_TAG)) { // If there is a <title> peer, prepend its content to the // content of the <desc> element. elt.normalize(); - if (elt.getFirstChild() == null) { - return; - } + if (elt.getFirstChild() == null) { + return; + } String toolTip = elt.getFirstChild().getNodeValue(); - if (toolTip == null || toolTip.length() == 0) { - return; - } - - Element titlePeer = - getPeerWithTag(elt, - SVGConstants.SVG_NAMESPACE_URI, - SVGConstants.SVG_TITLE_TAG); + if (toolTip == null || toolTip.length() == 0) { + return; + } + + Element titlePeer = + getPeerWithTag(elt, + SVGConstants.SVG_NAMESPACE_URI, + SVGConstants.SVG_TITLE_TAG); if (titlePeer != null) { titlePeer.normalize(); toolTip = Messages.formatMessage(TOOLTIP_TITLE_AND_TEXT, - new Object[] { - toFormattedHTML(titlePeer.getFirstChild().getNodeValue()), - toFormattedHTML(toolTip)}); + new Object[] { + toFormattedHTML(titlePeer.getFirstChild().getNodeValue()), + toFormattedHTML(toolTip)}); } else { - toolTip = - Messages.formatMessage - (TOOLTIP_DESC_ONLY, - new Object[]{toFormattedHTML(toolTip)}); + toolTip = + Messages.formatMessage + (TOOLTIP_DESC_ONLY, + new Object[]{toFormattedHTML(toolTip)}); } - + setToolTip((Element)(elt.getParentNode()), toolTip); } } @@ -801,7 +802,7 @@ /** * Converts line breaks to HTML breaks and encodes special entities. * Poor way of replacing '<', '>', '"', '&' and ''' in attribute values. - */ + */ public String toFormattedHTML(String str) { StringBuffer sb = new StringBuffer(str); replace(sb, XML_CHAR_AMP, XML_ENTITY_AMP); @@ -812,11 +813,11 @@ replace(sb, '\n', "<br>"); return sb.toString(); } - + protected void replace(StringBuffer s, char c, String r) { String v = s.toString() + 1; int i = v.length(); - + while( (i=v.lastIndexOf(c, --i)) != -1 ) { s.deleteCharAt(i); s.insert(i, r); @@ -826,16 +827,16 @@ /** * Checks if there is a peer element of a given type. This returns the * first occurence of the given type or null if none is found. - */ - public Element getPeerWithTag(Element elt, - String nameSpaceURI, + */ + public Element getPeerWithTag(Element elt, + String nameSpaceURI, String localName) { Element p = (Element)elt.getParentNode(); if (p == null) { return null; } - + for (Node n=p.getFirstChild(); n!=null; n = n.getNextSibling()) { if (!nameSpaceURI.equals(n.getNamespaceURI())){ continue; @@ -849,35 +850,35 @@ } return null; } - + /** * Returns a boolean defining whether or not there is a peer of - * <tt>elt</tt> with the given qualified tag. - */ + * <tt>elt</tt> with the given qualified tag. + */ public boolean hasPeerWithTag(Element elt, String nameSpaceURI, String localName){ return !(getPeerWithTag(elt, nameSpaceURI, localName) == null); } - + /** * Sets the tool tip on the input element. */ public void setToolTip(Element elt, String toolTip){ EventTarget target = (EventTarget)elt; - elt.normalize(); - + elt.normalize(); + // On mouseover, set the tooltip to the title value - target.addEventListener(SVGConstants.SVG_EVENT_MOUSEOVER, + target.addEventListener(SVGConstants.SVG_EVENT_MOUSEOVER, new ToolTipModifier(toolTip), false); - + // On mouseout, remove the tooltip target.addEventListener(SVGConstants.SVG_EVENT_MOUSEOUT, new ToolTipModifier(null), false); - + if (locationListener == null) { locationListener = new LocationListener(); addMouseMotionListener(locationListener); @@ -891,11 +892,12 @@ if (svgUserAgent != null) { super.displayError(message); } else { - JOptionPane pane; - pane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE); - JDialog dialog = pane.createDialog(JSVGCanvas.this, "ERROR"); + JOptionPane pane = + new JOptionPane(message, JOptionPane.ERROR_MESSAGE); + JDialog dialog = + pane.createDialog(JSVGCanvas.this, "ERROR"); dialog.setModal(false); - dialog.show(); + dialog.show(); // Safe to be called from any thread } } @@ -906,7 +908,11 @@ if (svgUserAgent != null) { super.displayError(ex); } else { - displayError(ex.getMessage()); + JOptionPane pane = + new JErrorPane(ex, JOptionPane.ERROR_MESSAGE); + JDialog dialog = pane.createDialog(JSVGCanvas.this, "ERROR"); + dialog.setModal(false); + dialog.show(); // Safe to be called from any thread } } } @@ -927,14 +933,14 @@ lastX = evt.getX(); lastY = evt.getY(); } - + public int getLastX() { - return lastX; - } + return lastX; + } public int getLastY() { - return lastY; - } + return lastY; + } } /** @@ -953,7 +959,7 @@ protected String toolTip; /** - * @param toolTip value to which the JSVGCanvas should be + * @param toolTip value to which the JSVGCanvas should be * set when the event occurs. */ public ToolTipModifier(String toolTip){ 1.1 xml-batik/sources/org/apache/batik/util/gui/JErrorPane.java Index: JErrorPane.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.batik.util.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.io.PrintWriter; import java.io.StringWriter; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import org.apache.batik.util.gui.resource.ActionMap; import org.apache.batik.util.gui.resource.ButtonFactory; import org.apache.batik.util.gui.resource.MissingListenerException; import org.apache.batik.util.gui.resource.ResourceManager; /** * This class represents a dialog to display an error (message + Exception). * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: JErrorPane.java,v 1.1 2001/11/28 16:07:47 tkormann Exp $ */ public class JErrorPane extends JOptionPane { /** * The resource file name */ protected final static String RESOURCES = "org.apache.batik.util.gui.resources.JErrorPane"; /** * The resource bundle */ protected static ResourceBundle bundle; /** * The resource manager */ protected static ResourceManager resources; static { bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault()); resources = new ResourceManager(bundle); } /** * The error message. */ protected String msg; /** * The stack trace. */ protected String stacktrace; /** * Constructs a new JErrorPane. * * @param th the throwable object that describes the errror * @param type the dialog type */ public JErrorPane(Throwable th, int type) { this.msg = th.getMessage(); StringWriter writer = new StringWriter(); th.printStackTrace(new PrintWriter(writer)); writer.flush(); this.stacktrace = writer.toString(); setMessage(new MessagePanel()); setMessageType(type); } /** * The message panel. */ protected class MessagePanel extends JPanel implements ActionMap { /** * The button factory. */ protected ButtonFactory bf = new ButtonFactory(bundle, this); /** * The text area used to show the stack trace. */ protected JComponent detailsArea; /** * The button used to show or not the details. */ protected JButton showDetailButton; /** * This flag bit indicates whether or not the stack trace is shown. */ protected boolean isDetailShown = false; /** * The sub panel that contains the stack trace text area. */ protected JPanel subpanel; /** * Constructs a new <tt>MessagePanel</tt>. */ public MessagePanel() { super(new GridBagLayout()); listeners.put("ShowDetailButtonAction", new ShowDetailButtonAction()); ExtendedGridBagConstraints constraints = new ExtendedGridBagConstraints(); JTextArea msgArea = new JTextArea(4, 50); msgArea.setFont(new JLabel().getFont()); msgArea.setForeground(new JLabel().getForeground()); msgArea.setOpaque(false); msgArea.setEditable(false); msgArea.setText(msg); msgArea.setLineWrap(true); constraints.insets = new Insets(10, 10, 10, 10); constraints.setWeight(0, 0); constraints.anchor = GridBagConstraints.WEST; constraints.fill = GridBagConstraints.NONE; constraints.setGridBounds(0, 0, 2, 1); add(msgArea, constraints); constraints.insets = new Insets(0, 10, 10, 10); showDetailButton = bf.createJButton("ShowDetailButton"); constraints.setWeight(0, 0); constraints.anchor = GridBagConstraints.NORTHWEST; constraints.fill = GridBagConstraints.NONE; constraints.setGridBounds(0, 1, 1, 1); add(showDetailButton, constraints); JTextArea details = new JTextArea(); details.setText(stacktrace); details.setEditable(false); detailsArea = new JScrollPane(details); subpanel = new JPanel(new BorderLayout()); constraints.setWeight(1d, 1d); constraints.anchor = GridBagConstraints.CENTER; constraints.fill = GridBagConstraints.BOTH; constraints.setGridBounds(1, 1, 1, 1); add(subpanel, constraints); } /** * The map that contains the listeners */ protected Map listeners = new HashMap(); /** * Returns the action associated with the given string or null on error * * @param key the key mapped with the action to get * @throws MissingListenerException if the action is not found */ public Action getAction(String key) throws MissingListenerException { return (Action)listeners.get(key); } /** * The action associated with the 'Show Detail' button. */ protected class ShowDetailButtonAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { if (isDetailShown) { subpanel.remove(detailsArea); isDetailShown = false; showDetailButton.setText (resources.getString("ShowDetailButton.text")); } else { subpanel.add(detailsArea, BorderLayout.CENTER); showDetailButton.setText (resources.getString("ShowDetailButton.text2")); isDetailShown = true; } ((JDialog)getTopLevelAncestor()).pack(); } } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]