Class ImagePanelConfig

java.lang.Object
ca.corbett.extras.properties.AbstractProperty
ca.corbett.extras.image.ImagePanelConfig
All Implemented Interfaces:
EventListener, ChangeListener

public class ImagePanelConfig extends AbstractProperty implements ChangeListener
Represents configuration options for ImagePanel. This class is optional - if you don't specify it when creating and using an ImagePanel, an instance will be created automatically with default values set for all properties. You can modify any property in this class and hand the new instance to ImagePanel.setPanelProperties().
Since:
2017-11-07
Author:
scorbett
  • Constructor Details

    • ImagePanelConfig

      protected ImagePanelConfig(String fullyQualifiedName)
      Constructor is protected to force callers to use the factory methods.
  • Method Details

    • createDefaultProperties

      public static ImagePanelConfig createDefaultProperties()
      Creates an ImagePanelConfig instance with all default values set.
      Returns:
      A default ImagePanelConfig instance.
    • createDefaultProperties

      public static ImagePanelConfig createDefaultProperties(String name)
    • createSimpleReadOnlyProperties

      public static ImagePanelConfig createSimpleReadOnlyProperties()
      Creates an ImagePanelConfig suitable for simply display of a non-zoomable, non-scrollable image.
      Returns:
      An ImagePanelConfig configured for simple non-interactive display.
    • createSimpleReadOnlyProperties

      public static ImagePanelConfig createSimpleReadOnlyProperties(String name)
    • cloneProperties

      public static ImagePanelConfig cloneProperties(ImagePanelConfig other)
      Clones the given ImagePanelConfig into a new instance. If you pass in null, you'll get back a defaulted instance, same as if you had called createDefaultProperties.
      Parameters:
      other - The ImagePanelConfig object to be cloned.
      Returns:
      The new, cloned properties instance.
    • cloneProperties

      public static ImagePanelConfig cloneProperties(ImagePanelConfig other, String newName)
    • resetToDefaults

      public void resetToDefaults()
      Resets all properties back to their default values.
    • getBgColor

      public Color getBgColor()
      The background colour of the panel, defaults to Color.DARK_GRAY.
      Returns:
      The panel background colour.
    • setRenderingQuality

      public void setRenderingQuality(ImagePanelConfig.Quality quality)
      Sets the image rendering quality preference: QUICK_AND_DIRTY emphasizes speed over quality, while SLOW_AND_ACCURATE does the opposite.
      Parameters:
      quality - The desired rendering quality.
    • getRenderingQuality

      public ImagePanelConfig.Quality getRenderingQuality()
      Gets the image rendering quality preference: QUICK_AND_DIRTY emphasizes speed over quality, while SLOW_AND_ACCURATE does the opposite.
      Returns:
      The current rendering quality.
    • setBgColor

      public void setBgColor(Color bgColor)
      Sets the background colour of the panel, defaults to the panel bg color from the current Look and Feel. This can also be set directly on the ImagePanel itself, as it is a JPanel property. It is here as a convenience.

      Note that explicitly setting a bgcolor here will override the current look and feel, and this instance will ignore any future look and feel changes in favour of the given bg color.

      Parameters:
      bgColor - The desired background colour.
    • getMagnifierCursor

      public Cursor getMagnifierCursor()
      If enableZoomOnMouseClick or enableZoomOnMouseWheel are set, this cursor will be used when the mouse pointer is over the panel, as a visual clue to the user that zoom operations are supported. The default value is a magnifier cursor.
      Returns:
      The currently set mouse cursor.
    • setMagnifierCursor

      public void setMagnifierCursor(Cursor magnifierCursor)
      If enableZoomOnMouseClick or enableZoomOnMouseWheel are set, this cursor will be used when the mouse pointer is over the panel, as a visual clue to the user that zoom operations are supported. The default value is a magnifier cursor. If enableZoomOnMouseClick and enableZoomOnMouseWheel are both disabled, this property is ignored. You can set null here to force the use of the default system cursor even if zooming is enabled.
      Parameters:
      magnifierCursor - The mouse cursor to use.
    • getNullCursor

      public Cursor getNullCursor()
      Returns a "null" cursor that can be used if the cursor is to be hidden.
      Returns:
      An empty cursor.
    • isEnableZoomOnMouseClick

      public boolean isEnableZoomOnMouseClick()
      Enables the use of mouse clicks to zoom: left click to zoom in, right click to zoom out. The default value is true.
      Returns:
      Whether mouse clicks can be used to zoom in and out of the image.
    • setEnableZoomOnMouseClick

      public void setEnableZoomOnMouseClick(boolean enableZoomOnMouseClick)
      Enables the use of mouse clicks to zoom: left click to zoom in, right click to zoom out. The default value is true.
      Parameters:
      enableZoomOnMouseClick - Whether mouse clicks can be used to zoom in and out of the image.
    • isEnableZoomOnMouseWheel

      public boolean isEnableZoomOnMouseWheel()
      Enables the use of mouse wheel for zooming: wheel up to zoom in, wheel down to zoom out. The default value is true.
      Returns:
      Whether the mouse wheel can be used to zoom in and out of the image.
    • setEnableZoomOnMouseWheel

      public void setEnableZoomOnMouseWheel(boolean enableZoomOnMouseWheel)
      Enables the use of mouse wheel for zooming: wheel up to zoom in, wheel down to zoom out. The default value is true.
      Parameters:
      enableZoomOnMouseWheel - Whether the mouse wheel can be used to zoom in and out.
    • getDisplayMode

      public ImagePanelConfig.DisplayMode getDisplayMode()
      Returns the current DisplayMode.
      • NONE: just display the image unscaled at 0,0
      • CENTER: center the image in the panel, but don't resize it
      • BEST_FIT: center the image and scale it up or down as needed to fit the panel.
      • STRETCH: distort the image so it fully fills the panel.
      • CUSTOM: this is used internally when zooming in/out and should be ignored otherwise.
      Returns:
      The current display mode as outlined above.
    • setDisplayMode

      public void setDisplayMode(ImagePanelConfig.DisplayMode mode)
      Sets the DisplayMode.
      • NONE: just display the image unscaled at 0,0
      • CENTER: center the image in the panel, but don't resize it
      • BEST_FIT: center the image and scale it up or down as needed to fit the panel.
      • STRETCH: distort the image so it fully fills the panel.
      • CUSTOM: this is used internally when zooming in/out and should be ignored otherwise.
      Parameters:
      mode - The DisplayMode to use, as outlined above.
    • isEnableMouseCursor

      public boolean isEnableMouseCursor()
      If disabled, mouse cursor will be hidden while over the panel. This is enabled by default. The cursor will either be the system default cursor if enableZoomOnMouseClick and enableZoomOnMouseWheel are both disabled, or it will be set to the current magnifier cursor otherwise (see setMagnifierCursor).
      Returns:
      Whether the mouse cursor will be visible over the panel.
    • setEnableMouseCursor

      public void setEnableMouseCursor(boolean enableMouseCursor)
      If disabled, mouse cursor will be hidden while over the panel. This is enabled by default. The cursor will either be the system default cursor if enableZoomOnMouseClick and enableZoomOnMouseWheel are both disabled, or it will be set to the current magnifier cursor otherwise (see setMagnifierCursor).
      Parameters:
      enableMouseCursor - Whether the mouse cursor will be visible over the panel.
    • isEnableMouseDragging

      public boolean isEnableMouseDragging()
      If enabled, users can click and drag on a zoomed-in image to scroll it around within the panel. Note that this property does nothing if the image is not zoomed in to the point where it is larger than the panel. The default value is true.
      Returns:
      Whether mouse dragging is allowed to scroll zoomed-in images.
    • setEnableMouseDragging

      public void setEnableMouseDragging(boolean enableMouseDragging)
      If enabled, users can click and drag on a zoomed-in image to scroll it around within the panel. Note that this property does nothing if the image is not zoomed in to the point where it is larger than the panel. The default value is true.
      Parameters:
      enableMouseDragging - Whether mouse dragging is allowed to scroll zoomed-in images.
    • getZoomFactorIncrement

      public double getZoomFactorIncrement()
      When zooming in or out, represents the percentage step to apply up or down. The default value is 0.1, meaning the image will be scaled up in incrememts of 10% for each zoom operation.
      Returns:
      The current zoom increment.
    • setZoomFactorIncrement

      public void setZoomFactorIncrement(double zoomFactorIncrement)
      When zooming in or out, represents the percentage step to apply up or down. The default value is 0.1, meaning the image will be scaled up in incrememts of 10% for each zoom operation.
      Parameters:
      zoomFactorIncrement - The zoom increment to use.
    • saveToProps

      public void saveToProps(Properties props)
      Description copied from class: AbstractProperty
      Saves the current value(s) of this property to the given Properties instance.
      Specified by:
      saveToProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which will receive the value(s) of this property.
    • loadFromProps

      public void loadFromProps(Properties props)
      Description copied from class: AbstractProperty
      Loads the value(s) for this property from the given Properties instance, overwriting any current value. The current value of this property will be used as a default value in the event that this property does not exist in the given Properties instance.
      Specified by:
      loadFromProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which contains value(s) for this property.
    • generateFormFieldImpl

      protected FormField generateFormFieldImpl()
      Description copied from class: AbstractProperty
      Descendant classes must implement this method to generate a FormField associated with this property. The generateFormField() method in this class will call this abstract method to create the FormField, which will then be augmented with our fully qualified name, read-only state, help text, and extra attributes.
      Specified by:
      generateFormFieldImpl in class AbstractProperty
      Returns:
      A FormField associated with this property.
    • loadFromFormField

      public void loadFromFormField(FormField field)
      Description copied from class: AbstractProperty
      Populates this Property's value(s) from the given form field, assuming the field is of the correct type.
      Specified by:
      loadFromFormField in class AbstractProperty
      Parameters:
      field - The FormField containing a value for this property.
    • stateChanged

      public void stateChanged(ChangeEvent e)
      Invoked from LookAndFeelManager when the Look and Feel is changed. If we have never been given an explicit background color, then we'll auto-set it according to the new look and feel.
      Specified by:
      stateChanged in interface ChangeListener
      Parameters:
      e - a ChangeEvent object