Class JXImageView

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

@JavaBean public class JXImageView extends JXPanel

A panel which shows an image centered. The user can drag an image into the panel from other applications and move the image around within the view. The JXImageView has built in actions for scaling, rotating, opening a new image, and saving. These actions can be obtained using the relevant get*Action() methods.

TODO: has dashed rect and text indicating you should drag there.

If the user drags more than one photo at a time into the JXImageView only the first photo will be loaded and shown. Any errors generated internally, such as dragging in a list of files which are not images, will be reported to any attached ErrorListener added by the addErrorListener(org.jdesktop.swingx.error.ErrorListener)() method.

Author:
Joshua Marinacci joshua.marinacci@sun.com
See Also:
  • Constructor Details

    • JXImageView

      public JXImageView()
      Creates a new instance of JXImageView
  • Method Details

    • getImageLocation

      public Point2D getImageLocation()
      Gets the current image location. This location can be changed programmatically or by the user dragging the image within the JXImageView.
      Returns:
      the current image location
    • setImageLocation

      public void setImageLocation(Point2D imageLocation)
      Set the current image location.
      Parameters:
      imageLocation - The new image location.
    • getImage

      public Image getImage()
      Gets the currently set image, or null if no image is set.
      Returns:
      the currently set image, or null if no image is set.
    • setImage

      public void setImage(Image image)
      Sets the current image. Can set null if there should be no image show.
      Parameters:
      image - the new image to set, or null.
    • setImage

      public void setImage(URL url) throws IOException
      Set the current image to an image pointed to by this URL.
      Parameters:
      url - a URL pointing to an image, or null
      Throws:
      IOException - thrown if the image cannot be loaded
    • setImage

      public void setImage(File file) throws IOException
      Set the current image to an image pointed to by this File.
      Parameters:
      file - a File pointing to an image
      Throws:
      IOException - thrown if the image cannot be loaded
    • getScale

      public double getScale()
      Gets the current image scale. When the scale is set to 1.0 then one image pixel = one screen pixel. When scale < 1.0 the draw image will be smaller than it's real size. When scale ≥ 1.0 the drawn image will be larger than it's real size. 1.0 is the default value.
      Returns:
      the current image scale
    • setScale

      public void setScale(double scale)
      Sets the current image scale. When the scale is set to 1.0 then one image pixel = one screen pixel. When scale < 1.0 the draw image will be smaller than it's real size. When scale ≥ 1.0 the drawn image will be larger than it's real size. 1.0 is the default value.
      Parameters:
      scale - the new image scale
    • isEditable

      public boolean isEditable()
      Returns whether or not the user can drag images.
      Returns:
      whether or not the user can drag images
    • setEditable

      public void setEditable(boolean editable)
      Sets whether or not the user can drag images. When set to true the user can drag the photo around with their mouse. Also the cursor will be set to the 'hand' cursor. When set to false the user cannot drag photos around and the cursor will be set to the default.
      Parameters:
      editable - whether or not the user can drag images
    • setDragEnabled

      public void setDragEnabled(boolean dragEnabled)
      Sets the dragEnabled property, which determines whether or not the user can drag images out of the image view and into other components or application. Note: setting this to true will disable the ability to move the image around within the well., though it will not change the editable property directly.
      Parameters:
      dragEnabled - the value to set the dragEnabled property to.
    • isDragEnabled

      public boolean isDragEnabled()
      Gets the current value of the dragEnabled property.
      Returns:
      the current value of the dragEnabled property
    • addErrorListener

      public void addErrorListener(ErrorListener el)
      Adds an ErrorListener to the list of listeners to be notified of ErrorEvents
      Parameters:
      el - an ErrorListener to add
    • removeErrorListener

      public void removeErrorListener(ErrorListener el)
      Remove an ErrorListener from the list of listeners to be notified of ErrorEvents.
      Parameters:
      el - an ErrorListener to remove
    • fireError

      protected void fireError(Throwable throwable)
      Send a new ErrorEvent to all registered ErrorListeners
      Parameters:
      throwable - the Error or Exception which was thrown
    • getOpenAction

      @Deprecated public Action getOpenAction()
      Deprecated.
      see SwingX issue 990
      Returns an Action which will open a file chooser, ask the user for an image file then load the image into the view. If the load fails an error will be fired to all registered ErrorListeners
      Returns:
      the action
      See Also:
    • getSaveAction

      @Deprecated public Action getSaveAction()
      Deprecated.
      see SwingX issue 990
      Returns an Action which will open a file chooser, ask the user for an image file then save the image from the view. If the save fails an error will be fired to all registered ErrorListeners
      Returns:
      an Action
    • getRotateClockwiseAction

      @Deprecated public Action getRotateClockwiseAction()
      Deprecated.
      see SwingX issue 990
      Get an action which will rotate the currently selected image clockwise.
      Returns:
      an action
    • getRotateCounterClockwiseAction

      @Deprecated public Action getRotateCounterClockwiseAction()
      Deprecated.
      see SwingX issue 990
      Gets an action which will rotate the current image counter clockwise.
      Returns:
      an Action
    • getZoomOutAction

      @Deprecated public Action getZoomOutAction()
      Deprecated.
      see SwingX issue 990
      Gets an action which will zoom the current image out by a factor of 2.
      Returns:
      an action
    • getZoomInAction

      @Deprecated public Action getZoomInAction()
      Deprecated.
      see SwingX issue 990
      Gets an action which will zoom the current image in by a factor of 2
      Returns:
      an action
    • paintComponent

      protected void paintComponent(Graphics g)
      Implementation detail.
      Overrides:
      paintComponent in class JXPanel
      Parameters:
      g - Graphics
    • getExportName

      public String getExportName()
      Returns:
      String exportName
    • setExportName

      public void setExportName(String exportName)
      Parameters:
      exportName - String
    • getExportFormat

      public String getExportFormat()
      Returns:
      String exportFormat
    • setExportFormat

      public void setExportFormat(String exportFormat)
      Parameters:
      exportFormat - String
    • getImageURL

      public URL getImageURL()
      Returns:
      URL imageURL
    • setImageURL

      public void setImageURL(URL imageURL) throws IOException
      Parameters:
      imageURL - URL
      Throws:
      IOException - TODO explain
    • getImageString

      public String getImageString()
      Returns the current image's URL (if available) as a string. If the image has no URL, or if there is no image, then this method will return null.
      Returns:
      the url of the image as a string
    • setImageString

      public void setImageString(String url) throws IOException
      Sets the current image using a string. This string must contain a valid URL.
      Parameters:
      url - string of a URL
      Throws:
      IOException - thrown if the URL does not parse