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

XSvgMagnifyingGlass

class com.xoetrope.swing.svg.XSvgMagnifyingGlass

The XSvgMagnifyingGlass class provides a means of zooming an SVG image in conjunction with the XSvgImageMap class. The zoomed region of the image is displayed within a rendered magnifying glass.

Magnifying Glass

1. Example


<?java
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 java.awt.event.MouseListener;
import javax.swing.JFrame;

public class TestSvgMagnifier implements MouseMotionListener, MouseListener
{
    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);
        magGlass = new XSvgMagnifyingGlass();
        glassPane = svgImage.getGlassPane();
        glassPane.setLayout( new BorderLayout() );
        svgImage.addMouseMotionListener( this );
        svgImage.addMouseListener( this );
   
        magGlass.setDiagram(  svgImage.getSvgDiagram() );
        magGlass.setImageMap( svgImage );
        magGlass.setScaleFactor( 5.0F );
        glassPane.add( magGlass );
        new Thread( magGlass ).start ();
        glassPane.setVisible( true );
    }

    public void mouseMoved( MouseEvent e )
    {
        magGlass.setZoomPoint( e.getPoint(), e.getPoint() );
    }

    public void mouseEntered( MouseEvent e )
    {
       magGlass.setAnimationMode ( XSvgMagnifyingGlass.FADE_IN, 20F );
    }

    public void mouseExited( MouseEvent e )
    {
       magGlass.setAnimationMode ( XSvgMagnifyingGlass.FADE_OUT, 10F );
    }
}
?>


In the above example, a new instance of XSvgMagnifyingGlass is created and passed an SVGDiagram instance from the XSvgImageMap class. The TestSvgMagnifier class implements the MouseMotionListener and MouseListener interfaces. 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. The mouseEntered and mouseExited methods of the MouseListener interface are used to determine when to run the fade-in and fade-out animations for the magnifying glass.

2. Constructor


public XSvgMagnifyingGlass ()


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. 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.

4. getScaleFactor

public float getScaleFactor()


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

5. 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.

6. 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.

7. stopRenderer

public void stopRenderer()


Stops the renderer thread from running.

8. setRotational

public void setRotational( boolean isRotational )


Sets whether the magnifying glass is rotated to the centre of the image during zooming.

9. setQuality

public void setQuality( boolean quality )


Improves the rendering quality of the magnifying glass.

10. setOpaque

public void setOpaque( boolean isOpaque )


Sets whether the magnifying glass is opaque or not.

11. run

public void run ()


Implemented from the Runnable interface. Called by starting a new thread on the XSvgMagnifyingGlass component, this method handles the fade-in and fade-out animations.

11. setAnimationMode

public void setAnimationMode( int animationMode, float animationSpeed )


Sets whether a fade-in or fade-out animation is to be run.

12. setTransparency

public void setTransparency( float a )


Sets the alpha transparency of the magnifier.

{{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.6242 seconds