ccs.cpc
Class ImageHolder

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by ccs.cpc.ImageHolder
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, java.util.EventListener
Direct Known Subclasses:
Previewer

public class ImageHolder
extends javax.swing.JComponent
implements java.awt.event.ActionListener, java.lang.Runnable

A graphical component containing an image. ImageHolder is designed to liase with the ImageManager. Note that the ImageHolder is transparent, so needs an opaque ancestor. We recommend that the ImageHolder be used on a black background.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  CpcImage cimg
           
protected  VFile current
           
protected  ImageManager imgr
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageHolder(ImageManager imgr)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          Reserved (for GIF animation.)
 void dispose()
          Dispose of the holder when finished with it.
 VFile getCurrent()
          return the current VFile, if any.
 CpcImage getImage()
          Return the currently-displayed image, which may be null.
 java.awt.Dimension getPackSize()
          Return the size which would be needed in order to display the current image at scale 1.
 float getScale()
          Return the current scaling for the image.
protected  void imageChanged()
          Called in dispatch thread when the state of an image has changed.
 void imageFlushed(VFile job)
          Notification that an image has been destroyed.
 void imageLoaded(VFile job)
          Async notification that an image has been loaded.
 boolean isAutoscale()
          Whether auto-scale is enabled.
 boolean isLoading()
          Whether the current file is still being loaded.
protected  boolean isNullOnChange()
          Whether to use null transitions.
 void paintComponent(java.awt.Graphics g)
           
protected  void paintImage(java.awt.Graphics g)
          Draw the image.
protected  void paintNull(java.awt.Graphics g)
          Draw the no-image placeholder.
 void run()
          Reserved.
 void setAutoscale(boolean isAuto)
          Set whether auto-scale is active.
 void setImage(VFile current)
          change the currently-displayed image file, possibly to null.
 void setScale(float scale)
          Set a fixed scaling for the image.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, update, updateUI
 
Methods inherited from class java.awt.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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods 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, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

imgr

protected ImageManager imgr

current

protected VFile current

cimg

protected CpcImage cimg
Constructor Detail

ImageHolder

public ImageHolder(ImageManager imgr)
Method Detail

dispose

public void dispose()
Dispose of the holder when finished with it. Must be called to disconnect the (dying) holder from the persistent ImageManager.


setImage

public void setImage(VFile current)
change the currently-displayed image file, possibly to null.


getImage

public CpcImage getImage()
Return the currently-displayed image, which may be null. Note the asymmetry between get and set.


getCurrent

public VFile getCurrent()
return the current VFile, if any.


setAutoscale

public void setAutoscale(boolean isAuto)
Set whether auto-scale is active. If true (the default) the scale will automatically be shrunk to fit the image into the available space. (The image will not be auto-scaled up if surplus space is available.)


isAutoscale

public boolean isAutoscale()
Whether auto-scale is enabled.


setScale

public void setScale(float scale)
Set a fixed scaling for the image. The holder may need to be repainted for this to take effect. This disables auto-scaling.

Parameters:
scale - the new scaling factor for the image.

getScale

public float getScale()
Return the current scaling for the image. In auto-scale mode, paint code will alter this to suit the current component size.


getPackSize

public java.awt.Dimension getPackSize()
Return the size which would be needed in order to display the current image at scale 1. Returns a small fixed value if no current image (the placeholder would like some room to display in.) NOTE: the return is "live", not a clone. Don't change it. (Apropos, the same is true of getPreferredSize.)


isLoading

public final boolean isLoading()
Whether the current file is still being loaded. This is true from the moment when setImage is called to the moment the image mananger returns a result. (The result may be null, ie. the image load failed.)


imageLoaded

public final void imageLoaded(VFile job)
Async notification that an image has been loaded. May or may not be of interest.


imageFlushed

public final void imageFlushed(VFile job)
Notification that an image has been destroyed. May or may not be of interest. (It's currently intended that this will only happen in dispatch thread, ie. as part of a manual flush).


run

public final void run()
Reserved. (For image-loaded handling in dispatch thread).

Specified by:
run in interface java.lang.Runnable

imageChanged

protected void imageChanged()
Called in dispatch thread when the state of an image has changed. The function should at least call repaint, and possibly resize as well. Default calls repaint.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
Reserved (for GIF animation.)

Specified by:
actionPerformed in interface java.awt.event.ActionListener

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

paintNull

protected void paintNull(java.awt.Graphics g)
Draw the no-image placeholder.


paintImage

protected void paintImage(java.awt.Graphics g)
Draw the image. If auto-scale is on, adjusts the image scale as required to fit in the current size of the component. (Scale won't exceed unity.)


isNullOnChange

protected boolean isNullOnChange()
Whether to use null transitions. If true (the default), the display resets to null image (ie. the placeholder) while the new image is loading. This guarantees consistency but may cause flashing for some ranges of transition times (ie. data fetch time + decode time + render time).