Xoetrope
HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Carousel logo

XSvgMagnifyingWindow

class com.xoetrope.swing.svg.XSvgMagnifyingWindow

The XSvgMagnifyingWindow class provides a means of zooming an SVG image in conjunction with the XSvgImageMap class. The class provides a component for displaying the zoomed SVG image.

Magnifying Window

1. Example


import com.kitfox.svg.SVGDiagram;
import com.xoetrope.swing.svg.XSvgImageMap;
import com.xoetrope.swing.svg.XSvgMagnifyingWindow;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;

public class TestSvgMagnifier implements MouseMotionListener
{
    private static XSvgMagnifyingWindow magnifier;

    public TestSvgMagnifier()
    {
        XSvgImageMap svgImage = new XSvgImageMap();
        svgImage.setURL("images/image1.svg");
        JFrame frame = new JFrame("SVG Test");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.setBackground (Color.WHITE);
        frame.setSize(800, 600);
        frame.add(svgImage);
        SVGDiagram diagram = svgImage.display ();
        svgImage.getSvgPanel ().addMouseMotionListener (this);
        JFrame magFrame = new JFrame("Svg Magnifier");
        magFrame.setSize(200,200);
        magnifier = new XSvgMagnifyingWindow();
        magnifier.setDiagram ( diagram );
        magnifier.setImageMap ( svgImage )
        magnifier.setScaleFactor (3.0f);
        magFrame.add(magnifier);
        magFrame.setLocatiion(800,400);
        magFrame.setVisible(true);
        frame.setVisible(true);
    }
   
    public static void main(String [] args)
    {
         new TestSvgMagnifier();
    }
        
    public void mouseMoved (MouseEvent e)
    {
        magnifier.setZoomPoint(e.getPoint());
    }

    public void mouseDragged (MouseEvent e){}
}


In the above example, a new instance of XSvgMagnifyingWindow is created and passed an SVGDiagram instance from the XSvgImageMap class. The TestSvgMagnifier class implements the MouseMotionListener interface. The mouseMoved method of the interface calls the setZoomPoint method of the XSvgMagnifier class, passing the current mouse location to it. The current mouse location is used to determine the part of the SVG image that is zoomed.

2. Constructor


public XSvgMagnifyingWindow ()


Creates a new instance of XSvgMagnifyingWindow.

3. Methods


1. setDiagram

public void setDiagram(SVGDiagram diagram)


Used to set the SVGDiagram instance that is to be magnified.

2. setImageMap

public void setImageMap(XSvgImageMap imageMap)


Sets the XSvgImageMap instance that will aid in the zooming of the SVG image.

3. getImageMap

public XSvgImageMap getImageMap()


Gets the XSvgImageMap instance currently used by the magnifier.

4. setScaleFactor

public void setScaleFactor(float f)


Used to set the scaling that will be applied to the SVG image. A higher scale value implies a greater zooming of the image.

5. getScaleFactor

public float getScaleFactor()


Used to get the scaling that is currently applied to the SVG image.

6. setZoomPoint

public void setZoomPoint(Point p)


Used to set which part of the SVG image will be zoomed. This can be added to a mouseMotionListener, there-by utilising the mouse to select the part of the image that is zoomed.

7. paintComponent

protected void paintComponent(Graphics g)


Calls the JComponent's paint method and scales the area that has been selected using setZoomPoint. The scaled area is then applied to the component.

8. stopRenderer

public void stopRenderer()


Stops the renderer thread from running.

{{image link="http://www.sourceforge.net/projects/xui" url="http://sourceforge.net/sflogo.php?group_id=76693

There are no comments on this page. [Add comment]

Page was generated in 0.7253 seconds