Class ImageListField

java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.ImageListField
All Implemented Interfaces:
EventListener, ChangeListener

public class ImageListField extends FormField implements 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
  • Constructor Details

    • ImageListField

      public ImageListField(String label)
      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

      public ImageListField(String label, int initialSize)
      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 label
      initialSize - Will start with horizontal space sufficient to show this number of images.
    • ImageListField

      public 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. 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 label
      initialSize - 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:
      hasValidationLabel in class FormField
    • setShouldExpand

      public ImageListField setShouldExpand(boolean expand)
      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

      public FormField setEnabled(boolean enabled)
      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:
      setEnabled in class FormField
      Parameters:
      enabled - whether to enable or disable the components.
    • setBackground

      public void setBackground(Color color)
      Sets the background color for this field's components.
      Parameters:
      color - The desired background color
    • setMaxImageCount

      public ImageListField setMaxImageCount(int maxCount)
      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

      public ImageListField setThumbnailSize(int size)
      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

      public ImageListField addImage(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

      public ImageListField 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. 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

      public Object 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.
    • removeImageAt

      public ImageListField removeImageAt(int index)
      Removes the image at the specified index. Does nothing if the specified index is out of range.
    • clear

      public ImageListField clear()
      Removes all images from this field.
    • getImageListPanel

      public ImageListPanel getImageListPanel()
      Provides direct access to the underlying ImageListPanel, if needed.
    • isMultiLine

      public boolean isMultiLine()
      Description copied from class: FormField
      By 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:
      isMultiLine in class FormField
    • shouldExpand

      public boolean shouldExpand()
      Description copied from class: FormField
      By 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:
      shouldExpand in class FormField
    • stateChanged

      public void stateChanged(ChangeEvent e)
      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:
      stateChanged in interface ChangeListener