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
method.addErrorListener(org.jdesktop.swingx.error.ErrorListener)
()
Modifier and Type | Class and Description |
---|---|
private class |
JXImageView.DnDHandler |
private class |
JXImageView.ImageTransferable |
private class |
JXImageView.MoveHandler |
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private boolean |
dragEnabled |
private boolean |
editable |
private ErrorSupport |
errorSupport |
private String |
exportFormat |
private String |
exportName |
private Image |
image |
private Point2D |
imageLocation |
private URL |
imageURL |
private Logger |
log |
private JXImageView.MoveHandler |
moveHandler |
private double |
scale |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JXImageView()
Creates a new instance of JXImageView
|
Modifier and Type | Method and Description |
---|---|
void |
addErrorListener(ErrorListener el)
Adds an ErrorListener to the list of listeners to be notified
of ErrorEvents
|
protected void |
fireError(Throwable throwable)
Send a new ErrorEvent to all registered ErrorListeners
|
String |
getExportFormat() |
String |
getExportName() |
Image |
getImage()
Gets the currently set image, or null if no image is set.
|
Point2D |
getImageLocation()
Gets the current image location.
|
String |
getImageString()
Returns the current image's URL (if available) as a string.
|
URL |
getImageURL() |
Action |
getOpenAction()
Deprecated.
see SwingX issue 990
|
Action |
getRotateClockwiseAction()
Deprecated.
see SwingX issue 990
|
Action |
getRotateCounterClockwiseAction()
Deprecated.
see SwingX issue 990
|
private static FileDialog |
getSafeFileDialog(Component comp) |
Action |
getSaveAction()
Deprecated.
see SwingX issue 990
|
double |
getScale()
Gets the current image scale .
|
Action |
getZoomInAction()
Deprecated.
see SwingX issue 990
|
Action |
getZoomOutAction()
Deprecated.
see SwingX issue 990
|
boolean |
isDragEnabled()
Gets the current value of the
dragEnabled property. |
boolean |
isEditable()
Returns whether or not the user can drag images.
|
protected void |
paintComponent(Graphics g)
Implementation detail.
|
void |
removeErrorListener(ErrorListener el)
Remove an ErrorListener from the list of listeners to be notified of ErrorEvents.
|
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. |
void |
setEditable(boolean editable)
Sets whether or not the user can drag images.
|
void |
setExportFormat(String exportFormat) |
void |
setExportName(String exportName) |
void |
setImage(File file)
Set the current image to an image pointed to by this File.
|
void |
setImage(Image image)
Sets the current image.
|
void |
setImage(URL url)
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 .
|
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, installRepaintManager, isInheritAlpha, isPaintBorderInsets, paint, setAlpha, setBackground, setBackgroundPainter, setInheritAlpha, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint, uninstallRepaintManager
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
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
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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private ErrorSupport errorSupport
private Point2D imageLocation
private double scale
private boolean editable
private JXImageView.MoveHandler moveHandler
private boolean dragEnabled
private String exportName
private String exportFormat
public JXImageView()
public Point2D getImageLocation()
public void setImageLocation(Point2D imageLocation)
imageLocation
- The new image location.public Image getImage()
public void setImage(Image image)
image
- the new image to set, or null.public void setImage(URL url) throws IOException
url
- a URL pointing to an image, or nullIOException
- thrown if the image cannot be loadedpublic void setImage(File file) throws IOException
file
- a File pointing to an imageIOException
- thrown if the image cannot be loadedpublic double getScale()
public void setScale(double scale)
scale
- the new image scalepublic boolean isEditable()
public void setEditable(boolean editable)
editable
- whether or not the user can drag imagespublic void setDragEnabled(boolean dragEnabled)
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.dragEnabled
- the value to set the dragEnabled property to.public boolean isDragEnabled()
dragEnabled
property.dragEnabled
propertypublic void addErrorListener(ErrorListener el)
el
- an ErrorListener to addpublic void removeErrorListener(ErrorListener el)
el
- an ErrorListener to removeprotected void fireError(Throwable throwable)
throwable
- the Error or Exception which was thrownprivate static FileDialog getSafeFileDialog(Component comp)
@Deprecated public Action getOpenAction()
ErrorListener
@Deprecated public Action getSaveAction()
@Deprecated public Action getRotateClockwiseAction()
@Deprecated public Action getRotateCounterClockwiseAction()
@Deprecated public Action getZoomOutAction()
@Deprecated public Action getZoomInAction()
protected void paintComponent(Graphics g)
paintComponent
in class JXPanel
g
- public String getExportName()
public void setExportName(String exportName)
public String getExportFormat()
public void setExportFormat(String exportFormat)
public URL getImageURL()
public void setImageURL(URL imageURL) throws IOException
IOException
public String getImageString()
public void setImageString(String url) throws IOException
url
- string of a URLIOException
- thrown if the URL does not parseWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses