Class VirtualView
- All Implemented Interfaces:
IFeedbackProvider,IFileDropHandler,IViewListener,ComponentListener,FocusListener,MouseListener,MouseMotionListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible,InternalFrameListener,RootPaneContainer,WindowConstants
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
JFramein 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
JFramehook is installed inaddNotify()(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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JInternalFrame
JInternalFrame.AccessibleJInternalFrame, JInternalFrame.JDesktopIconNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstrain placement to bottom center of the target cell.static final intConstrain placement to bottom-left of the target cell.static final intConstrain placement to bottom-right of the target cell.static final intConstrain placement to center of the target cell (special-cases).static final intFit the view into the left half of the target cell.static final intFit the view into the right half of the target cell.static final intConstrain placement to top center of the target cell.static final intConstrain placement to upper-left of the target cell.static final intConstrain placement to upper-right of the target cell.Fields inherited from class edu.cnu.mdi.view.BaseView
container, desktop, infoDialog, properties, scrollPane, statusWP, viewPopupMenu, VIEWPROPNAME, virtualItemFields inherited from class javax.swing.JInternalFrame
closable, CONTENT_PANE_PROPERTY, desktopIcon, FRAME_ICON_PROPERTY, frameIcon, GLASS_PANE_PROPERTY, iconable, IS_CLOSED_PROPERTY, IS_ICON_PROPERTY, IS_MAXIMUM_PROPERTY, IS_SELECTED_PROPERTY, isClosed, isIcon, isMaximum, isSelected, LAYERED_PANE_PROPERTY, maximizable, MENU_BAR_PROPERTY, resizable, ROOT_PANE_PROPERTY, rootPane, rootPaneCheckingEnabled, title, TITLE_PROPERTYFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateViewCell(BaseView view) Activate the virtual column containing the given view so that it becomes visible.voidCalled when this component is added to a realized containment hierarchy.voidEnforce a minimum internal frame height.static VirtualViewcreateVirtualView(int numcol) Create and show a newVirtualView.intReturns the currently visible column index.intReturns the horizontal pixel offset currently applied to all managed views — that is, how far left they have been shifted from their column-0 positions.static VirtualViewPublic access to the singleton virtual view.intintgetViewColumn(BaseView view) Estimate the virtual column containing a given view.voidgotoColumn(int col) Go to a specific column, making it visible.voidvoidvoidvoidvoidvoidvoidbooleanisViewVisible(BaseView view) Crude visibility test: whether the view's bounds intersect the application's current frame bounds.voidmouseClicked(MouseEvent mouseEvent) voidvoidvoidClose the magnify window when the mouse leaves any view canvas.voidvoidvoidvoidMove a view to the centre of a specific virtual column.voidMove a view to a specific virtual cell using a placement constraint, with no additional pixel offsets.voidMove a view to a specific column, applying a placement constraint and additional pixel offsets.voidoffset(int dh, int dv) Virtual view: no offsetting.voidReconfigure the virtual desktop world system and update all virtual window items.voidCalled when this component is removed from the UI hierarchy.voidsyncCurrentColumn(int col) Directly synchronizes this virtual desktop's own notion of "current column" tocol, without shifting any managed view's bounds -- unlikegotoColumn(int), which always does.Total world offset corresponding to the current virtual column.voidvoidviewRemoved(BaseView view) Methods inherited from class edu.cnu.mdi.view.BaseView
addWestPanel, applyFocusFix, center, checkBooleanProperty, componentHidden, componentMoved, componentShown, enableFileDrop, enableFileDrop, filesDropped, focusGained, focusLost, getAnnotationLayer, getCenterComponent, getConfigurationProperties, getConnectionLayer, getDefaultLayer, getFeedbackStrings, getFileFilter, getIContainer, getImageComponent, getInfoButton, getInsets, getIntProperty, getName, getParentFrame, getProperties, getPropertyName, getScrollPane, getSpecialClip, getToolBar, getViewInfo, getViewPopupMenu, getVirtualItem, handleMagnify, hoverClosed, hoverUpdate, initFeedback, initFeedback, isOnTop, isScrollable, isViewVisible, onFirstRealize, prepareForExit, refresh, resolveContainer, rightClicked, setAfterDraw, setBeforeDraw, setBooleanProperty, setFileFilter, setFromProperties, setIntProperty, setVirtualItem, viewInfoMethods inherited from class javax.swing.JInternalFrame
addImpl, addInternalFrameListener, createRootPane, dispose, doDefaultCloseAction, fireInternalFrameEvent, getAccessibleContext, getContentPane, getDefaultCloseOperation, getDesktopIcon, getDesktopPane, getFocusCycleRootAncestor, getFocusOwner, getFrameIcon, getGlassPane, getInternalFrameListeners, getJMenuBar, getLastCursor, getLayer, getLayeredPane, getMenuBar, getMostRecentFocusOwner, getNormalBounds, getRootPane, getTitle, getUI, getUIClassID, getWarningString, hide, isClosable, isClosed, isFocusCycleRoot, isIcon, isIconifiable, isMaximizable, isMaximum, isResizable, isRootPaneCheckingEnabled, isSelected, moveToBack, moveToFront, pack, paintComponent, paramString, remove, removeInternalFrameListener, reshape, restoreSubcomponentFocus, setClosable, setClosed, setContentPane, setCursor, setDefaultCloseOperation, setDesktopIcon, setFocusCycleRoot, setFrameIcon, setGlassPane, setIcon, setIconifiable, setJMenuBar, setLayer, setLayer, setLayeredPane, setLayout, setMaximizable, setMaximum, setMenuBar, setNormalBounds, setResizable, setRootPane, setRootPaneCheckingEnabled, setSelected, setTitle, setUI, show, toBack, toFront, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
UPPERLEFT
public static final int UPPERLEFTConstrain placement to upper-left of the target cell.- See Also:
-
UPPERRIGHT
public static final int UPPERRIGHTConstrain placement to upper-right of the target cell.- See Also:
-
BOTTOMLEFT
public static final int BOTTOMLEFTConstrain placement to bottom-left of the target cell.- See Also:
-
BOTTOMRIGHT
public static final int BOTTOMRIGHTConstrain placement to bottom-right of the target cell.- See Also:
-
TOPCENTER
public static final int TOPCENTERConstrain placement to top center of the target cell.- See Also:
-
BOTTOMCENTER
public static final int BOTTOMCENTERConstrain placement to bottom center of the target cell.- See Also:
-
CENTER
public static final int CENTERConstrain placement to center of the target cell (special-cases).- See Also:
-
CENTERLEFT
public static final int CENTERLEFTFit the view into the left half of the target cell.- See Also:
-
CENTERRIGHT
public static final int CENTERRIGHTFit the view into the right half of the target cell.- See Also:
-
-
Method Details
-
createVirtualView
Create and show a newVirtualView.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:
_instanceis published here, afternew 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 access to the singleton virtual view.- Returns:
- the current virtual view instance, or
nullif 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:
addNotifyin classJComponent
-
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:
removeNotifyin classJComponent
-
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
- Specified by:
internalFrameOpenedin interfaceInternalFrameListener
-
internalFrameClosing
- Specified by:
internalFrameClosingin interfaceInternalFrameListener
-
internalFrameClosed
- Specified by:
internalFrameClosedin interfaceInternalFrameListener
-
internalFrameIconified
- Specified by:
internalFrameIconifiedin interfaceInternalFrameListener
-
internalFrameDeiconified
- Specified by:
internalFrameDeiconifiedin interfaceInternalFrameListener
-
internalFrameActivated
- Specified by:
internalFrameActivatedin interfaceInternalFrameListener
-
internalFrameDeactivated
- Specified by:
internalFrameDeactivatedin interfaceInternalFrameListener
-
viewAdded
- Specified by:
viewAddedin interfaceIViewListener
-
viewRemoved
- Specified by:
viewRemovedin interfaceIViewListener
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener
-
offset
public void offset(int dh, int dv) Virtual view: no offsetting.A
VirtualViewitself stays fixed; it offsets other views. -
mouseClicked
- Specified by:
mouseClickedin interfaceMouseListener- Overrides:
mouseClickedin classBaseView
-
gotoColumn
public void gotoColumn(int col) Go to a specific column, making it visible.- Parameters:
col- the column to go to
-
mousePressed
- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classBaseView
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classBaseView
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener- Overrides:
mouseEnteredin classBaseView
-
mouseExited
Description copied from class:BaseViewClose the magnify window when the mouse leaves any view canvas.- Specified by:
mouseExitedin interfaceMouseListener- Overrides:
mouseExitedin classBaseView
-
totalOffset
Total world offset corresponding to the current virtual column.- Returns:
- offset in world coordinates;
x = currentCol*dx, y = 0
-
moveTo
Move a view to the centre of a specific virtual column.- Parameters:
view- the view to move; ignored ifnullor not managedcol- the target column index
-
getViewColumn
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" tocol, without shifting any managed view's bounds -- unlikegotoColumn(int), which always does.Use this only when every managed view's bounds have already been set to reflect being at
colby some means other thangotoColumn-- 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 realizedViewConfigurationwith saved layout data callsgotoColumnto its own saved column as part of restoring itself) -- stale bookkeeping that a later, unrelatedgotoColumn(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 viewsconfigureViews()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
Move a view to a specific virtual cell using a placement constraint, with no additional pixel offsets.- Parameters:
view- the view to movecol- the target columnconstraint- placement constraint constant (e.g.UPPERLEFT)
-
moveTo
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.CENTERLEFTandCENTERRIGHTinstead tile a view into the corresponding half of the usable cell. The special valueCENTERdelegates tomoveTo(BaseView, int)for centred placement.- Parameters:
view- the view to move; ignored ifnullor not managedcol- the target column indexdelh- additional horizontal pixel offset applied after the constraint position is computeddelv- additional vertical pixel offset applied after the constraint position is computedconstraint- placement constraint constant
-
activateViewCell
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
Crude visibility test: whether the view's bounds intersect the application's current frame bounds.- Parameters:
view- the view to check- Returns:
trueif the view appears to be visible
-
componentResized
Enforce a minimum internal frame height.- Specified by:
componentResizedin interfaceComponentListener- Overrides:
componentResizedin classBaseView
-