tkormann    01/09/10 08:23:33

  Modified:    sources/org/apache/batik/apps/svgbrowser
                        JSVGViewerFrame.java
               sources/org/apache/batik/swing JSVGCanvas.java
  Log:
  The JSVGViewerFrame now uses the Action of the JSVGCanvas.
  
  Revision  Changes    Path
  1.48      +13 -59    
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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- JSVGViewerFrame.java      2001/09/06 08:32:28     1.47
  +++ JSVGViewerFrame.java      2001/09/10 15:23:33     1.48
  @@ -138,7 +138,7 @@
    * This class represents a SVG viewer swing frame.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: JSVGViewerFrame.java,v 1.47 2001/09/06 08:32:28 tkormann Exp $
  + * @version $Id: JSVGViewerFrame.java,v 1.48 2001/09/10 15:23:33 tkormann Exp $
    */
   public class JSVGViewerFrame
       extends    JFrame
  @@ -343,6 +343,9 @@
               }
           });
   
  +        svgCanvas = new JSVGCanvas(userAgent, true, true);
  +        svgCanvas.setDoubleBufferedRendering(true);
  +
           listeners.put(ABOUT_ACTION, new AboutAction());
           listeners.put(OPEN_ACTION, new OpenAction());
           listeners.put(OPEN_LOCATION_ACTION, new OpenLocationAction());
  @@ -358,9 +361,15 @@
           listeners.put(CLOSE_ACTION, new CloseAction());
           listeners.put(EXIT_ACTION, application.createExitAction(this));
           listeners.put(VIEW_SOURCE_ACTION, new ViewSourceAction());
  -        listeners.put(RESET_TRANSFORM_ACTION, new ResetTransformAction());
  -        listeners.put(ZOOM_IN_ACTION, new ZoomInAction());
  -        listeners.put(ZOOM_OUT_ACTION, new ZoomOutAction());
  +
  +     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));
  + 
           listeners.put(PREVIOUS_TRANSFORM_ACTION, previousTransformAction);
           listeners.put(NEXT_TRANSFORM_ACTION, nextTransformAction);
           listeners.put(STOP_ACTION, stopAction);
  @@ -371,10 +380,6 @@
           listeners.put(THUMBNAIL_DIALOG_ACTION, new ThumbnailDialogAction());
           listeners.put(FLUSH_ACTION, new FlushAction());
   
  -        svgCanvas = new JSVGCanvas(userAgent, true, true);
  -
  -        svgCanvas.setDoubleBufferedRendering(true);
  -
           JPanel p = null;
           try {
               // Create the menu
  @@ -1071,57 +1076,6 @@
               svgCanvas.flush();
               // Force redraw...
               svgCanvas.setRenderingTransform(svgCanvas.getRenderingTransform());
  -        }
  -    }
  -
  -    /**
  -     * To reset the document transform.
  -     */
  -    public class ResetTransformAction extends AbstractAction {
  -        public ResetTransformAction() {}
  -        public void actionPerformed(ActionEvent e) {
  -            svgCanvas.setFragmentIdentifier(null);
  -            svgCanvas.resetRenderingTransform();
  -        }
  -    }
  -
  -    /**
  -     * To zoom in.
  -     */
  -    public class ZoomInAction extends AbstractAction {
  -        public ZoomInAction() {}
  -        public void actionPerformed(ActionEvent e) {
  -            AffineTransform at = svgCanvas.getRenderingTransform();
  -            if (at != null) {
  -                Dimension dim = getSize();
  -                int x = dim.width / 2;
  -                int y = dim.height / 2;
  -                AffineTransform t = AffineTransform.getTranslateInstance(x, y);
  -                t.scale(2, 2);
  -                t.translate(-x, -y);
  -                t.concatenate(at);
  -                svgCanvas.setRenderingTransform(t);
  -            }
  -        }
  -    }
  -
  -    /**
  -     * To zoom out.
  -     */
  -    public class ZoomOutAction extends AbstractAction {
  -        public ZoomOutAction() {}
  -        public void actionPerformed(ActionEvent e) {
  -            AffineTransform at = svgCanvas.getRenderingTransform();
  -            if (at != null) {
  -                Dimension dim = getSize();
  -                int x = dim.width / 2;
  -                int y = dim.height / 2;
  -                AffineTransform t = AffineTransform.getTranslateInstance(x, y);
  -                t.scale(0.5, 0.5);
  -                t.translate(-x, -y);
  -                t.concatenate(at);
  -                svgCanvas.setRenderingTransform(t);
  -            }
           }
       }
   
  
  
  
  1.27      +101 -104  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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- JSVGCanvas.java   2001/09/10 14:37:39     1.26
  +++ JSVGCanvas.java   2001/09/10 15:23:33     1.27
  @@ -65,11 +65,66 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thierry Kormann</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: JSVGCanvas.java,v 1.26 2001/09/10 14:37:39 tkormann Exp $
  + * @version $Id: JSVGCanvas.java,v 1.27 2001/09/10 15:23:33 tkormann Exp $
    */
   public class JSVGCanvas extends JSVGComponent {
   
       /**
  +     * The key for the Action to scroll right.
  +     */
  +    public static final String SCROLL_RIGHT_ACTION = "ScrollRight";
  +
  +    /**
  +     * The key for the Action to scroll left.
  +     */
  +    public static final String SCROLL_LEFT_ACTION = "ScrollLeft";
  +
  +    /**
  +     * The key for the Action to scroll up.
  +     */
  +    public static final String SCROLL_UP_ACTION = "ScrollUp";
  +
  +    /**
  +     * 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.
  +     */
  +    public static final String FAST_SCROLL_RIGHT_ACTION = "FastScrollRight";
  +
  +    /**
  +     * The key for the Action to quickly scroll left.
  +     */
  +    public static final String FAST_SCROLL_LEFT_ACTION = "FastScrollLeft";
  +
  +    /**
  +     * The key for the Action to quickly scroll up.
  +     */
  +    public static final String FAST_SCROLL_UP_ACTION = "FastScrollUp";
  +
  +    /**
  +     * 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.
  +     */
  +    public static final String ZOOM_IN_ACTION = "ZoomIn";
  +
  +    /**
  +     * 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.
  +     */
  +    public static final String RESET_TRANSFORM_ACTION = "ResetTransform";
  +
  +    /**
        * This flag bit indicates whether or not the zoom interactor is
        * enabled. True means the zoom interactor is functional.
        */
  @@ -147,6 +202,8 @@
           intl.add(rotateInteractor);
           intl.add(resetTransformInteractor);
   
  +     installActions();
  +
        if (eventsEnabled) {
            addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent evt) {
  @@ -154,7 +211,6 @@
                }
            });
   
  -         installActions();
            installKeyboardActions();
        }
       }
  @@ -166,20 +222,20 @@
       protected void installActions() {
        ActionMap actionMap = getActionMap();
        
  -     actionMap.put(ScrollRightAction.NAME, new ScrollRightAction());
  -     actionMap.put(ScrollLeftAction.NAME, new ScrollLeftAction());
  -     actionMap.put(ScrollUpAction.NAME, new ScrollUpAction());
  -     actionMap.put(ScrollDownAction.NAME, new ScrollDownAction());
  +     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(FastScrollRightAction.NAME, new FastScrollRightAction());
  -     actionMap.put(FastScrollLeftAction.NAME, new FastScrollLeftAction());
  -     actionMap.put(FastScrollUpAction.NAME, new FastScrollUpAction());
  -     actionMap.put(FastScrollDownAction.NAME, new FastScrollDownAction());
  +     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(ZoomInAction.NAME, new ZoomInAction());
  -     actionMap.put(ZoomOutAction.NAME, new ZoomOutAction());
  +     actionMap.put(ZOOM_IN_ACTION, new ZoomInAction());
  +     actionMap.put(ZOOM_OUT_ACTION, new ZoomOutAction());
   
  -     actionMap.put(ResetTransformAction.NAME, new ResetTransformAction());
  +     actionMap.put(RESET_TRANSFORM_ACTION, new ResetTransformAction());
       }
   
       /**
  @@ -192,37 +248,37 @@
        KeyStroke key;
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0);
  -     inputMap.put(key, ScrollRightAction.NAME);
  +     inputMap.put(key, SCROLL_RIGHT_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0);
  -     inputMap.put(key, ScrollLeftAction.NAME);
  +     inputMap.put(key, SCROLL_LEFT_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);
  -     inputMap.put(key, ScrollUpAction.NAME);
  +     inputMap.put(key, SCROLL_UP_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0);
  -     inputMap.put(key, ScrollDownAction.NAME);
  +     inputMap.put(key, SCROLL_DOWN_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_MASK);
  -     inputMap.put(key, FastScrollRightAction.NAME);
  +     inputMap.put(key, FAST_SCROLL_RIGHT_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_MASK);
  -     inputMap.put(key, FastScrollLeftAction.NAME);
  +     inputMap.put(key, FAST_SCROLL_LEFT_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_MASK);
  -     inputMap.put(key, FastScrollUpAction.NAME);
  +     inputMap.put(key, FAST_SCROLL_UP_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_MASK);
  -     inputMap.put(key, FastScrollDownAction.NAME);
  +     inputMap.put(key, FAST_SCROLL_DOWN_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_MASK);
  -     inputMap.put(key, ZoomInAction.NAME);
  +     inputMap.put(key, ZOOM_IN_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK);
  -     inputMap.put(key, ZoomOutAction.NAME);
  +     inputMap.put(key, ZOOM_OUT_ACTION);
   
        key = KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_MASK);
  -     inputMap.put(key, ResetTransformAction.NAME);
  +     inputMap.put(key, RESET_TRANSFORM_ACTION);
       }
   
       /**
  @@ -419,11 +475,8 @@
        * A swing action to reset the rendering transform of the canvas.
        */
       protected class ResetTransformAction extends AbstractAction {
  -
  -     /** The action name. */
  -     public static final String NAME = "resetTransform";
  -
        public void actionPerformed(ActionEvent evt) {
  +         setFragmentIdentifier(null);
               resetRenderingTransform();
        }
       }
  @@ -432,10 +485,6 @@
        * A swing action to zoom in the canvas.
        */
       protected class ZoomInAction extends AbstractAction {
  -
  -     /** The action name. */
  -     public static final String NAME = "zoomIn";
  -
        public void actionPerformed(ActionEvent evt) {
               AffineTransform at = getRenderingTransform();
               if (at != null) {
  @@ -455,10 +504,6 @@
        * A swing action to zoom out the canvas.
        */
       protected class ZoomOutAction extends AbstractAction {
  -
  -     /** The action name. */
  -     public static final String NAME = "zoomOut";
  -
        public void actionPerformed(ActionEvent evt) {
               AffineTransform at = getRenderingTransform();
               if (at != null) {
  @@ -479,12 +524,13 @@
        */
       protected class ScrollRightAction extends AbstractAction {
   
  -     /** The action name. */
  -     public static final String NAME = "scrollRight";
  -
        /** The scroll increment. */
  -     protected int inc = 10;
  +     protected int inc;
   
  +     public ScrollRightAction(int inc) {
  +         this.inc = inc;
  +     }
  +
        public void actionPerformed(ActionEvent evt) {
            AffineTransform at = new AffineTransform(getRenderingTransform());
            at.translate(-inc, 0);
  @@ -497,11 +543,12 @@
        */
       protected class ScrollLeftAction extends AbstractAction {
   
  -     /** The action name. */
  -     public static final String NAME = "scrollLeft";
  -
        /** The scroll increment. */
  -     protected int inc = 10;
  +     protected int inc;
  +
  +     public ScrollLeftAction(int inc) {
  +         this.inc = inc;
  +     }
   
        public void actionPerformed(ActionEvent evt) {
            AffineTransform at = new AffineTransform(getRenderingTransform());
  @@ -515,11 +562,12 @@
        */
       protected class ScrollUpAction extends AbstractAction {
   
  -     /** The action name. */
  -     public static final String NAME = "scrollUp";
  -
        /** The scroll increment. */
  -     protected int inc = 10;
  +     protected int inc;
  +
  +     public ScrollUpAction(int inc) {
  +         this.inc = inc;
  +     }
   
        public void actionPerformed(ActionEvent evt) {
            AffineTransform at = new AffineTransform(getRenderingTransform());
  @@ -533,68 +581,17 @@
        */
       protected class ScrollDownAction extends AbstractAction {
   
  -     /** The action name. */
  -     public static final String NAME = "scrollDown";
  -
        /** The scroll increment. */
  -     protected int inc = 10;
  +     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);
  -     }
  -    }
  -
  -    /**
  -     * A swing action to scroll the canvas to the right fastely.
  -     */
  -    protected class FastScrollRightAction extends ScrollRightAction {
  -
  -     /** The action name. */
  -     public static final String NAME = "fastScrollRight";
  -
  -     public FastScrollRightAction() {
  -         inc = 30;
  -     }
  -    }
  -
  -    /**
  -     * A swing action to scroll the canvas to the left.
  -     */
  -    protected class FastScrollLeftAction extends ScrollLeftAction {
  -
  -     /** The action name. */
  -     public static final String NAME = "fastScrollLeft";
  -
  -     public FastScrollLeftAction() {
  -         inc = 30;
  -     }
  -    }
  -
  -    /**
  -     * A swing action to scroll the canvas up fastely.
  -     */
  -    protected class FastScrollUpAction extends ScrollUpAction {
  -
  -     /** The action name. */
  -     public static final String NAME = "fastScrollUp";
  -
  -     public FastScrollUpAction() {
  -         inc = 30;
  -     }
  -    }
  -
  -    /**
  -     * A swing action to scroll the canvas down fastely.
  -     */
  -    protected class FastScrollDownAction extends ScrollDownAction {
  -
  -     /** The action name. */
  -     public static final String NAME = "fastScrollDown";
  -
  -     public FastScrollDownAction() {
  -         inc = 30;
        }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to