Package org.jdesktop.swingx
Class JXImageView
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.jdesktop.swingx.JXPanel
org.jdesktop.swingx.JXImageView
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,Scrollable
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
method.addErrorListener(org.jdesktop.swingx.error.ErrorListener)
()
- Author:
- Joshua Marinacci joshua.marinacci@sun.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an ErrorListener to the list of listeners to be notified of ErrorEventsprotected void
Send a new ErrorEvent to all registered ErrorListenersgetImage()
Gets the currently set image, or null if no image is set.Gets the current image location.Returns the current image's URL (if available) as a string.Deprecated.see SwingX issue 990Deprecated.see SwingX issue 990Deprecated.see SwingX issue 990Deprecated.see SwingX issue 990double
getScale()
Gets the current image scale.Deprecated.see SwingX issue 990Deprecated.see SwingX issue 990boolean
Gets the current value of thedragEnabled
property.boolean
Returns whether or not the user can drag images.protected void
Implementation detail.void
Remove an ErrorListener from the list of listeners to be notified of ErrorEvents.void
setDragEnabled
(boolean dragEnabled) Sets thedragEnabled
property, which determines whether or not the user can drag images out of the image view and into other components or application.void
setEditable
(boolean editable) Sets whether or not the user can drag images.void
setExportFormat
(String exportFormat) void
setExportName
(String exportName) void
Sets the current image.void
Set the current image to an image pointed to by this File.void
Set the current image to an image pointed to by this URL.void
setImageLocation
(Point2D imageLocation) Set the current image location.void
setImageString
(String url) Sets the current image using a string.void
setImageURL
(URL imageURL) void
setScale
(double scale) Sets the current image scale.Methods inherited from class org.jdesktop.swingx.JXPanel
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, isAlpha, isInheritAlpha, isOpaque, isOpaquePatch, isPaintBorderInsets, isPaintingBackground, isPaintingOrigin, isPatch, isTransparentBackground, paint, paintComponentPatch, setAlpha, setBackgroundPainter, setInheritAlpha, setOpaque, setOpaquePatch, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods 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, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods 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, validateTree
Methods 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
-
Constructor Details
-
JXImageView
public JXImageView()Creates a new instance of JXImageView
-
-
Method Details
-
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
Set the current image location.- Parameters:
imageLocation
- The new image location.
-
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
Sets the current image. Can set null if there should be no image show.- Parameters:
image
- the new image to set, or null.
-
setImage
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
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 thedragEnabled
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 thedragEnabled
property.- Returns:
- the current value of the
dragEnabled
property
-
addErrorListener
Adds an ErrorListener to the list of listeners to be notified of ErrorEvents- Parameters:
el
- an ErrorListener to add
-
removeErrorListener
Remove an ErrorListener from the list of listeners to be notified of ErrorEvents.- Parameters:
el
- an ErrorListener to remove
-
fireError
Send a new ErrorEvent to all registered ErrorListeners- Parameters:
throwable
- the Error or Exception which was thrown
-
getOpenAction
Deprecated.see SwingX issue 990Returns 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.see SwingX issue 990Returns 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.see SwingX issue 990Get an action which will rotate the currently selected image clockwise.- Returns:
- an action
-
getRotateCounterClockwiseAction
Deprecated.see SwingX issue 990Gets an action which will rotate the current image counter clockwise.- Returns:
- an Action
-
getZoomOutAction
Deprecated.see SwingX issue 990Gets an action which will zoom the current image out by a factor of 2.- Returns:
- an action
-
getZoomInAction
Deprecated.see SwingX issue 990Gets an action which will zoom the current image in by a factor of 2- Returns:
- an action
-
paintComponent
Implementation detail.- Overrides:
paintComponent
in classJXPanel
- Parameters:
g
- Graphics
-
getExportName
- Returns:
- String exportName
-
setExportName
- Parameters:
exportName
- String
-
getExportFormat
- Returns:
- String exportFormat
-
setExportFormat
- Parameters:
exportFormat
- String
-
getImageURL
- Returns:
- URL imageURL
-
setImageURL
- Parameters:
imageURL
- URL- Throws:
IOException
- TODO explain
-
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
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
-