Package ca.corbett.forms.fields
Class ImageListField
java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.ImageListField
- All Implemented Interfaces:
EventListener,ChangeListener
A FormField implementation that allows the user to select one or more images, and display
them in a scrollable form field. The field contains controls to allow the user to add
or remove items within the list. Double-clicking an image launches a preview window for it.
- Since:
- swing-extras 2.5
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.forms.fields.FormField
DEFAULT_FONT, defaultFont, extraAttributes, fieldComponent, fieldLabel, fieldValidators, helpLabel, ICON_SIZE, identifier, isEnabled, isVisible, margins, validationLabel, valueChangedListeners -
Constructor Summary
ConstructorsConstructorDescriptionImageListField(String label) Creates a new ImageListField with a default width sufficient to show a single image.ImageListField(String label, int initialSize) Creates a new ImageListField with a starting width large enough to show the given count of images.ImageListField(String label, int initialSize, int thumbDimension) Creates a new ImageListField with a starting width large enough to show the given count of images, and with the given square thumbnail pixel dimensions. -
Method Summary
Modifier and TypeMethodDescriptionaddImage(BufferedImage image) Programmatically adds an image to this image field, assuming the number of images currently contained is less than the configured image limit.addImage(BufferedImage thumbnail, ImageIcon imageIcon) Programmatically adds an animated GIF image to this field, assuming the number of images currently contained is less than the configured image limit.clear()Removes all images from this field.getImageAt(int index) Returns EITHER a BufferedImage for static image types like jpeg or png, OR an ImageIcon if the image at the given index is an animated GIF.intReturns the count of images currently contained in this field.Provides direct access to the underlying ImageListPanel, if needed.intReturns the maximum number of images allowed in this field, or Integer.MAX_VALUE if there is no limit.booleanOverridden here as we generally don't want to show a validation label on an image list.booleanBy default, FormFields occupy a single "line", or row, on the form.removeImageAt(int index) Removes the image at the specified index.voidsetBackground(Color color) Sets the background color for this field's components.setEnabled(boolean enabled) Enables or disables the underlying ImageListPanel.setMaxImageCount(int maxCount) Optionally restrict how many images this field will allow.setShouldExpand(boolean expand) Optionally make this FormField expand to fill the entire width of the parent FormPanel.setThumbnailSize(int size) Adjusts the desired thumbnail size for images in this field.booleanBy default, FormPanel will allocate only the space that the field component requires.voidWe receive ChangeEvents from our underlying ImageListPanel as images are added or removed.Methods inherited from class ca.corbett.forms.fields.FormField
addAllExtraAttributes, addFieldValidator, addValueChangedListener, clearExtraAttribute, clearExtraAttributes, clearValidationResults, equals, fireValueChangedEvent, getDefaultFont, getExtraAttribute, getFieldComponent, getFieldLabel, getHelpLabel, getHelpText, getIdentifier, getMargins, getValidationLabel, hasFieldLabel, hashCode, hasHelpLabel, isEnabled, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, validate
-
Constructor Details
-
ImageListField
Creates a new ImageListField with a default width sufficient to show a single image. Use ImageListField(String, int) to pick a different image size, OR use setShouldExpand(true) to consume as much horizontal width as the containing FormPanel will allow. -
ImageListField
Creates a new ImageListField with a starting width large enough to show the given count of images. Alternatively, you can use setShouldExpand(true) to allow this field to consume as much horizontal width as the containing FormPanel allows.- Parameters:
label- The text for the field labelinitialSize- Will start with horizontal space sufficient to show this number of images.
-
ImageListField
Creates a new ImageListField with a starting width large enough to show the given count of images, and with the given square thumbnail pixel dimensions. You can also optionally use setShouldExpand(true) to allow this panel to consume as much horizontal space as the containing FormPanel allows.- Parameters:
label- The text for the field labelinitialSize- Will start with horizontal space sufficient to show this number of images.thumbDimension- The square thumbnail dimensions to use for each image.
-
-
Method Details
-
hasValidationLabel
public boolean hasValidationLabel()Overridden here as we generally don't want to show a validation label on an image list. Will return true only if one or more FieldValidators have been explicitly assigned.- Overrides:
hasValidationLabelin classFormField
-
setShouldExpand
Optionally make this FormField expand to fill the entire width of the parent FormPanel. This overrides the "initialSize" that was given to the constructor. Defaults to false. -
setEnabled
Enables or disables the underlying ImageListPanel. When disabled, features like drag and drop to add images, or right click to remove images, are switched off.- Overrides:
setEnabledin classFormField- Parameters:
enabled- whether to enable or disable the components.
-
setBackground
Sets the background color for this field's components.- Parameters:
color- The desired background color
-
setMaxImageCount
Optionally restrict how many images this field will allow. By default, this is Integer.MAX_VALUE. The value must be at least 1 (otherwise what is the point).Warning: If you pass a value that is less than the number of images currently held in this field, the images at indexes above the new max limit will be dropped.
-
getMaxImageCount
public int getMaxImageCount()Returns the maximum number of images allowed in this field, or Integer.MAX_VALUE if there is no limit. -
setThumbnailSize
Adjusts the desired thumbnail size for images in this field. Note that you shouldn't bypass this method by doing imageListField.getImageListPanel().setThumbnailSize(), because then this FormField is cut out of the loop and will not resize to the new thumbnail dimensions. This method intercepts the request, adjusts this FormField size, and then forwards the request to the underlying ImageListPanel. -
addImage
Programmatically adds an image to this image field, assuming the number of images currently contained is less than the configured image limit. -
addImage
Programmatically adds an animated GIF image to this field, assuming the number of images currently contained is less than the configured image limit. Caller must supply a static image which will be scaled to use as the thumbnail. A good choice is usually the first frame of the animation. This image will be scaled as needed to fit the thumbnail panel. -
getImageCount
public int getImageCount()Returns the count of images currently contained in this field. -
getImageAt
Returns EITHER a BufferedImage for static image types like jpeg or png, OR an ImageIcon if the image at the given index is an animated GIF. -
removeImageAt
Removes the image at the specified index. Does nothing if the specified index is out of range. -
clear
Removes all images from this field. -
getImageListPanel
Provides direct access to the underlying ImageListPanel, if needed. -
isMultiLine
public boolean isMultiLine()Description copied from class:FormFieldBy default, FormFields occupy a single "line", or row, on the form. However, some FormFields may have a field component that spans multiple lines, like a multi-line text box, or a list, or a custom panel. Descendant classes can override the default false value here. It controls the placement of the field label. For tall form fields, the field label will be anchored to the top-left of its area.- Overrides:
isMultiLinein classFormField
-
shouldExpand
public boolean shouldExpand()Description copied from class:FormFieldBy default, FormPanel will allocate only the space that the field component requires. Descendant classes can override the default false value here to indicate that their field component should be allowed to expand as much space as is available to it. For example: PanelField.- Overrides:
shouldExpandin classFormField
-
stateChanged
We receive ChangeEvents from our underlying ImageListPanel as images are added or removed. We can use that to send value changed events to our own listeners.- Specified by:
stateChangedin interfaceChangeListener
-