Class MagnifyWindow

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer

public class MagnifyWindow extends JWindow
A floating magnifier window used to display a zoomed-in view of a BaseContainer around the current mouse location.

Typical usage is to call magnify(BaseContainer, MouseEvent) from a mouse event handler in the source container. The magnified view is shown in a small JWindow near the mouse cursor, and the magnification factor is controlled via the menu returned by magnificationMenu().

The implementation is intentionally singleton-based: there is at most one MagnifyWindow instance shared across the application.

Author:
David
See Also:
  • Method Details

    • magnificationMenu

      public static JMenu magnificationMenu()
      Returns a menu that allows the user to select the magnification factor used by the magnifier window.

      The menu is lazily created on first call and then reused. It is intended to be inserted into the application's main menu bar.

      Returns:
      the magnification factor menu
    • magnify

      public static void magnify(BaseContainer sourceContainer, MouseEvent event)
      Shows the magnifier window for a given source container at the location of the supplied mouse event.

      The magnifier window is positioned near the mouse pointer and configured to display a zoomed-in view of the region under the cursor. The source container's model is shared and the magnifier behaves like a zoomed copy.

      Parameters:
      sourceContainer - the BaseContainer to magnify (must not be null)
      event - the mouse event that triggered the magnification (must not be null)
    • getWorldCenter

      public static Point2D.Double getWorldCenter()
      Returns the world coordinates of the center of the magnifier window.

      This is the world point currently under the mouse in the source container and corresponds to the center of the magnified region.

      Returns:
      the world coordinates of the center of the magnified region
    • closeMagnifyWindow

      public static void closeMagnifyWindow()
      Hides the magnify window if it is currently visible.
    • getInsets

      public Insets getInsets()
      Returns the insets to use for this window.

      This implementation slightly increases the default insets, which can help provide a small visual margin around the magnified content.

      Overrides:
      getInsets in class Container
      Returns:
      the insets for this window