Class VirtualView

All Implemented Interfaces:
IFeedbackProvider, IFileDropHandler, IViewListener, ComponentListener, FocusListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, InternalFrameListener, RootPaneContainer, WindowConstants

public class VirtualView extends BaseView implements InternalFrameListener, IViewListener, MouseMotionListener, MouseListener
A "virtual desktop" overview view.

A VirtualView displays a small thumbnail representation of each open BaseView and supports a simple column-based virtual desktop: internally-managed views can be arranged into N virtual columns (cells). Clicking a column in the VirtualView shifts all views horizontally so that the chosen column becomes the visible "current" column.

Lifecycle

  • This view needs a reference to the top-level JFrame in order to know the real window dimensions and respond to frame resizes.
  • In Swing, the window ancestor is not reliably available inside the constructor. Therefore, the JFrame hook is installed in addNotify() (when this component is actually attached to a realized containment hierarchy).

Singleton

The singleton reference (_instance) is assigned by the factory method createVirtualView(int) after the constructor returns, so no code reachable from the constructor can observe a partially-constructed instance through the singleton reference.

See Also:
  • Field Details

    • UPPERLEFT

      public static final int UPPERLEFT
      Constrain placement to upper-left of the target cell.
      See Also:
    • UPPERRIGHT

      public static final int UPPERRIGHT
      Constrain placement to upper-right of the target cell.
      See Also:
    • BOTTOMLEFT

      public static final int BOTTOMLEFT
      Constrain placement to bottom-left of the target cell.
      See Also:
    • BOTTOMRIGHT

      public static final int BOTTOMRIGHT
      Constrain placement to bottom-right of the target cell.
      See Also:
    • TOPCENTER

      public static final int TOPCENTER
      Constrain placement to top center of the target cell.
      See Also:
    • BOTTOMCENTER

      public static final int BOTTOMCENTER
      Constrain placement to bottom center of the target cell.
      See Also:
    • CENTER

      public static final int CENTER
      Constrain placement to center of the target cell (special-cases).
      See Also:
    • CENTERLEFT

      public static final int CENTERLEFT
      Fit the view into the left half of the target cell.
      See Also:
    • CENTERRIGHT

      public static final int CENTERRIGHT
      Fit the view into the right half of the target cell.
      See Also:
  • Method Details

    • createVirtualView

      public static VirtualView createVirtualView(int numcol)
      Create and show a new VirtualView.

      The view is created with a small fixed pixel size (thumbnail-style), and its world system is sized to numCols × maxScreenWidth.

      The parent frame is resolved later in addNotify() so it is safe to call this factory before the application frame is visible.

      Singleton assignment: _instance is published here, after new VirtualView(...) returns. This guarantees that no code reachable from the constructor can observe a partially-constructed instance through the singleton reference.

      Parameters:
      numcol - number of virtual columns; clamped to at least 1
      Returns:
      the newly created virtual desktop view; never null
    • getInstance

      public static VirtualView getInstance()
      Public access to the singleton virtual view.
      Returns:
      the current virtual view instance, or null if none has been created
    • addNotify

      public void addNotify()
      Called when this component is added to a realized containment hierarchy.

      This is the correct place to safely resolve the top-level window ancestor and install a resize listener on the parent JFrame. Attempting to access the window ancestor in the constructor is unreliable.

      Overrides:
      addNotify in class JComponent
    • removeNotify

      public void removeNotify()
      Called when this component is removed from the UI hierarchy.

      Removes listeners that were installed on the parent frame to avoid leaks.

      Overrides:
      removeNotify in class JComponent
    • reconfigure

      public void reconfigure()
      Reconfigure the virtual desktop world system and update all virtual window items.

      This should be called when the parent application frame size changes. It updates the virtual desktop's world width to be numCols * frameWidth (one frame-width per virtual column) and updates the stored per-column offsets.

    • getCurrentColumnPixelOffset

      public int getCurrentColumnPixelOffset()
      Returns the horizontal pixel offset currently applied to all managed views — that is, how far left they have been shifted from their column-0 positions.

      This is used by Desktop.writeConfigurationFile() to normalise saved view bounds back to column-0 coordinates, so that they restore correctly regardless of which column was active when the layout was saved.

      Returns:
      current horizontal pixel offset (non-negative; zero when at column 0)
    • getNumCol

      public int getNumCol()
      Returns:
      number of virtual columns (cells)
    • internalFrameOpened

      public void internalFrameOpened(InternalFrameEvent e)
      Specified by:
      internalFrameOpened in interface InternalFrameListener
    • internalFrameClosing

      public void internalFrameClosing(InternalFrameEvent e)
      Specified by:
      internalFrameClosing in interface InternalFrameListener
    • internalFrameClosed

      public void internalFrameClosed(InternalFrameEvent e)
      Specified by:
      internalFrameClosed in interface InternalFrameListener
    • internalFrameIconified

      public void internalFrameIconified(InternalFrameEvent e)
      Specified by:
      internalFrameIconified in interface InternalFrameListener
    • internalFrameDeiconified

      public void internalFrameDeiconified(InternalFrameEvent e)
      Specified by:
      internalFrameDeiconified in interface InternalFrameListener
    • internalFrameActivated

      public void internalFrameActivated(InternalFrameEvent e)
      Specified by:
      internalFrameActivated in interface InternalFrameListener
    • internalFrameDeactivated

      public void internalFrameDeactivated(InternalFrameEvent e)
      Specified by:
      internalFrameDeactivated in interface InternalFrameListener
    • viewAdded

      public void viewAdded(BaseView view)
      Specified by:
      viewAdded in interface IViewListener
    • viewRemoved

      public void viewRemoved(BaseView view)
      Specified by:
      viewRemoved in interface IViewListener
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Specified by:
      mouseDragged in interface MouseMotionListener
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
    • offset

      public void offset(int dh, int dv)
      Virtual view: no offsetting.

      A VirtualView itself stays fixed; it offsets other views.

      Overrides:
      offset in class BaseView
      Parameters:
      dh - horizontal offset in pixels (positive = right)
      dv - vertical offset in pixels (positive = down)
    • mouseClicked

      public void mouseClicked(MouseEvent mouseEvent)
      Specified by:
      mouseClicked in interface MouseListener
      Overrides:
      mouseClicked in class BaseView
    • gotoColumn

      public void gotoColumn(int col)
      Go to a specific column, making it visible.
      Parameters:
      col - the column to go to
    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
      Overrides:
      mousePressed in class BaseView
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
      Overrides:
      mouseReleased in class BaseView
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
      Overrides:
      mouseEntered in class BaseView
    • mouseExited

      public void mouseExited(MouseEvent e)
      Description copied from class: BaseView
      Close the magnify window when the mouse leaves any view canvas.
      Specified by:
      mouseExited in interface MouseListener
      Overrides:
      mouseExited in class BaseView
    • totalOffset

      public Point2D.Double totalOffset()
      Total world offset corresponding to the current virtual column.
      Returns:
      offset in world coordinates; x = currentCol*dx, y = 0
    • moveTo

      public void moveTo(BaseView view, int col)
      Move a view to the centre of a specific virtual column.
      Parameters:
      view - the view to move; ignored if null or not managed
      col - the target column index
    • getViewColumn

      public int getViewColumn(BaseView view)
      Estimate the virtual column containing a given view.

      This uses the view's current bounds and the current virtual column width.

      Parameters:
      view - the view
      Returns:
      the column index, clamped to [0, numCols-1]
    • getCurrentColumn

      public int getCurrentColumn()
      Returns the currently visible column index.
      Returns:
      current column index
    • syncCurrentColumn

      public void syncCurrentColumn(int col)
      Directly synchronizes this virtual desktop's own notion of "current column" to col, without shifting any managed view's bounds -- unlike gotoColumn(int), which always does.

      Use this only when every managed view's bounds have already been set to reflect being at col by some means other than gotoColumn -- e.g. Desktop.configureViews(), which restores each view's saved, column-0-relative bounds by setting them directly, with no column bookkeeping of its own. Without a resync afterward, getCurrentColumn() still reports whatever column a view's own individual restoration happened to leave it at (each realized ViewConfiguration with saved layout data calls gotoColumn to its own saved column as part of restoring itself) -- stale bookkeeping that a later, unrelated gotoColumn(int) call (e.g. an application's own default-layout hook, documented to reliably run last and "win") then trusts, re-applying a shift on top of views configureViews() had already positioned correctly and silently corrupting every one of them by the same stale amount. Confirmed against a real saved-layout round trip in mdi_ced.

      Parameters:
      col - the column every managed view's current bounds actually reflect; out-of-range values are ignored
    • moveTo

      public void moveTo(BaseView view, int col, int constraint)
      Move a view to a specific virtual cell using a placement constraint, with no additional pixel offsets.
      Parameters:
      view - the view to move
      col - the target column
      constraint - placement constraint constant (e.g. UPPERLEFT)
    • moveTo

      public void moveTo(BaseView view, int col, int delh, int delv, int constraint)
      Move a view to a specific column, applying a placement constraint and additional pixel offsets.

      The constraint constants (UPPERLEFT, UPPERRIGHT, BOTTOMLEFT, BOTTOMRIGHT, TOPCENTER, BOTTOMCENTER) place the view at the corresponding position within the target cell. CENTERLEFT and CENTERRIGHT instead tile a view into the corresponding half of the usable cell. The special value CENTER delegates to moveTo(BaseView, int) for centred placement.

      Parameters:
      view - the view to move; ignored if null or not managed
      col - the target column index
      delh - additional horizontal pixel offset applied after the constraint position is computed
      delv - additional vertical pixel offset applied after the constraint position is computed
      constraint - placement constraint constant
    • activateViewCell

      public void activateViewCell(BaseView view)
      Activate the virtual column containing the given view so that it becomes visible.

      The actual view bounds are authoritative. Navigation therefore still works if its thumbnail has not yet been painted or is temporarily hidden.

      Parameters:
      view - the view
    • isViewVisible

      public boolean isViewVisible(BaseView view)
      Crude visibility test: whether the view's bounds intersect the application's current frame bounds.
      Parameters:
      view - the view to check
      Returns:
      true if the view appears to be visible
    • componentResized

      public void componentResized(ComponentEvent arg0)
      Enforce a minimum internal frame height.
      Specified by:
      componentResized in interface ComponentListener
      Overrides:
      componentResized in class BaseView