Package ca.corbett.extras.image
Class ImageListPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ca.corbett.extras.image.ImageListPanel
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
A scrollable panel that can show a list of images, each represented by a thumbnail
and an optional label to describe the image. The user can optionally add new images
to the list, remove them from the list, or double-click an image to view it in a
popup window.
NOTE: this component will grow horizontally without ever wrapping! The intention is that it will be added to a JScrollPane to prevent the component from taking up an unreasonable amount of space. It contains mouse listeners that will allow clicking and dragging on any image panel to scroll left/right within the list, if the ImageListPanel is added to a JScrollPane container.
- Since:
- swing-extras 2.5
- Author:
- scorbo2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested 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 intstatic final intstatic final intFields 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, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeListener(ChangeListener listener) Callers can subscribe to receive ChangeEvents when images are added or removed to or from this panel.voidaddImage(BufferedImage image) Adds a new image to the list.voidaddImage(BufferedImage thumbnail, ImageIcon imageIcon) Adds a new animated gif to the list.voidclear()Removes all images.voidEnables drag-and-drop of image files from the filesystem onto this panel.getImageAt(int index) Returns the image at the given index, or null if the given index is invalid.intReports how many images are in the current list.intReturns the configured maximum image count that this panel will allow.Returns the owner Window that will be used as a parent for the popup preview window (null is acceptable).getThumbnailAt(int index) Returns the scaled thumbnail at the given index, or null if the given index is invalid.booleanReturns whether this panel allows image addition and removal operations, and also whether drag and drop from the file system is allowed.voidremoveChangeListener(ChangeListener listener) voidremoveImage(int index) Remove an image by index.voidsetBackground(Color color) We override this so that we can update any child ImagePanels to have the same background color.voidsetMaxListSize(int max) Puts a limit on the number of images that this panel will allow.voidsetOwnerWindow(Window ownerWindow) Sets the owner Window that will be used as a parent for the popup preview window (null is acceptable).voidsetReadOnly(boolean readOnly) Determines whether image addition and removal operations are permitted, and also whether drag and drop from the file system is allowed.voidsetThumbnailSize(int newSize) Sets a new pixel size for our image thumbnails.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.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, 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, 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 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, 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
-
DEFAULT_THUMB_SIZE
public static final int DEFAULT_THUMB_SIZE- See Also:
-
MINIMUM_THUMB_SIZE
public static final int MINIMUM_THUMB_SIZE- See Also:
-
MAXIMUM_THUMB_SIZE
public static final int MAXIMUM_THUMB_SIZE- See Also:
-
-
Constructor Details
-
ImageListPanel
Creates a new, empty ImageListPanel.
-
-
Method Details
-
setReadOnly
public void setReadOnly(boolean readOnly) Determines whether image addition and removal operations are permitted, and also whether drag and drop from the file system is allowed. -
isReadOnly
public boolean isReadOnly()Returns whether this panel allows image addition and removal operations, and also whether drag and drop from the file system is allowed. -
getMaxListSize
public int getMaxListSize()Returns the configured maximum image count that this panel will allow. Addition attempts beyond this count are discarded. -
setMaxListSize
public void setMaxListSize(int max) Puts a limit on the number of images that this panel will allow. By default, this is Integer.MAX_VALUE.WARNING: Passing a value that is less than the number of images currently held in this panel will cause all images at indexes higher than this count to be dropped.
-
setThumbnailSize
public void setThumbnailSize(int newSize) Sets a new pixel size for our image thumbnails. Note that our thumbnails will always be scaled proportionally to fit a square bounding area, so the given pixel value represents both the desired width and the height of each thumbnail. This method will force a reload of the panel to force all current images to redisplay at the new thumb size. -
addImage
Adds a new image to the list. The list displays images in the order that they are added! Re-ordering the list dynamically is not yet possible. -
addImage
Adds a new animated gif to the list. The list displays images in the order that they are added! Re-ordering the list dynamically is not yet possible. -
getImageCount
public int getImageCount()Reports how many images are in the current list. -
setBackground
We override this so that we can update any child ImagePanels to have the same background color.- Overrides:
setBackgroundin classJComponent- Parameters:
color- the desired backgroundColor
-
clear
public void clear()Removes all images. -
getImageAt
Returns the image at the given index, or null if the given index is invalid. The return will be EITHER a BufferedImage for static image formats like jpeg or png, OR an ImageIcon if the image was an animated GIF. Caller has to check. -
getThumbnailAt
Returns the scaled thumbnail at the given index, or null if the given index is invalid. If the image at the given index is an animated GIF, this will give you the scaled static thumbnail which was based on the first frame of the animation. -
removeImage
public void removeImage(int index) Remove an image by index. If the given index is invalid, this call does nothing. -
getOwnerWindow
Returns the owner Window that will be used as a parent for the popup preview window (null is acceptable). -
setOwnerWindow
Sets the owner Window that will be used as a parent for the popup preview window (null is acceptable). -
addChangeListener
Callers can subscribe to receive ChangeEvents when images are added or removed to or from this panel. -
removeChangeListener
-
enableDragAndDrop
public void enableDragAndDrop()Enables drag-and-drop of image files from the filesystem onto this panel.
-