Class SwingImageViewer
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
uno.anahata.asi.swing.agi.render.SwingImageViewer
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, MediaViewerComponent
High-fidelity pure Swing image viewer implementing
MediaViewerComponent.
Supports smooth interactive zoom (mouse wheel), mouse dragging to pan when zoomed,
double-click fit/1:1 toggle, integrated MediaToolbar, and right-click context actions.
- Author:
- anahata
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classInteractive canvas rendering the scaled image centered in the viewport.Nested classes/interfaces inherited from class JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SwingImageViewer.ImageCanvasThe interactive image drawing canvas.private booleanWhether the image is currently fitted to the viewport dimensions.private BufferedImageDecoded full-resolution image.private doubleCurrent zoom scale factor (1.0 = 100% 1:1).private final JScrollPaneThe scroll pane enclosing the canvas.private final MediaToolbarThe action and metadata toolbar.Fields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionSwingImageViewer(@NonNull AgiPanel agiPanel) Constructs a new SwingImageViewer. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidComputes the scale needed to fit the image inside the viewport.voiddispose()Permanently disposes of the component, releasing native decoders, textures, and timers.Returns the Swing JComponent to be embedded in the UI hierarchy.voidLoads and initializes the media data for display and playback.private voidConfigures mouse wheel zoom, pan dragging, and context menu.private voidDisplays a popup context menu with common image actions.voidstop()Stops active audio or video playback, pausing decoding threads.voidToggles between fit-to-view and actual 1:1 pixel size.private voidUpdates the canvas dimensions to match the scaled image size.voidZooms the image by a multiplier centered on the given anchor point.Methods inherited from class JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class JComponent
addAncestorListener, addNotify, 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, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, 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 Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class 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, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, 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, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
toolbar
The action and metadata toolbar. -
scrollPane
The scroll pane enclosing the canvas. -
canvas
The interactive image drawing canvas. -
image
Decoded full-resolution image. -
scale
private double scaleCurrent zoom scale factor (1.0 = 100% 1:1). -
fitToView
private boolean fitToViewWhether the image is currently fitted to the viewport dimensions.
-
-
Constructor Details
-
SwingImageViewer
Constructs a new SwingImageViewer.- Parameters:
agiPanel- The parent AgiPanel providing session and configuration context.
-
-
Method Details
-
setupInteractions
private void setupInteractions()Configures mouse wheel zoom, pan dragging, and context menu. -
toggleFitOrActualSize
public void toggleFitOrActualSize()Toggles between fit-to-view and actual 1:1 pixel size. -
zoom
Zooms the image by a multiplier centered on the given anchor point.- Parameters:
factor- Zoom factor.anchor- Mouse anchor point.
-
calculateFitScale
private void calculateFitScale()Computes the scale needed to fit the image inside the viewport. -
updateCanvasSize
private void updateCanvasSize()Updates the canvas dimensions to match the scaled image size. -
showContextMenu
Displays a popup context menu with common image actions.- Parameters:
e- Mouse event triggering the popup.
-
getComponent
Returns the Swing JComponent to be embedded in the UI hierarchy.Returns this JPanel as the primary visual component.
- Specified by:
getComponentin interfaceMediaViewerComponent- Returns:
- the Swing component.
-
load
Loads and initializes the media data for display and playback.Decodes image bytes and updates metadata and toolbar.
- Specified by:
loadin interfaceMediaViewerComponent- Parameters:
data- The raw binary data.mimeType- The detected MIME type (e.g."video/mp4","image/png","audio/wav").displayName- An optional human-readable name or file name for the media item.sourceUri- An optional source URI on disk or remote network.
-
stop
public void stop()Stops active audio or video playback, pausing decoding threads.No active audio or video playback in image viewer.
- Specified by:
stopin interfaceMediaViewerComponent
-
dispose
public void dispose()Permanently disposes of the component, releasing native decoders, textures, and timers.Releases image buffer.
- Specified by:
disposein interfaceMediaViewerComponent
-

