Package it.tidalwave.image.render
Class EditableImageRenderer
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- it.tidalwave.image.render.EditableImageRenderer
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
public class EditableImageRenderer extends javax.swing.JComponent
This class is a pipe which adds to SimpleEditableImageRenderer scrolling capabilities and a fit-to-size feature.- Author:
- Fabrizio Giudici
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected double
angle
The current rotation.protected EditingTool
editingTool
The current EditingTool.protected EditableImage
image
The original image to be displayed.static double
MAX_SCALE
The maximum allowed value for scale.static double
MIN_SCALE
The maximum allowed value for scale.protected double
scale
The current scale.-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description EditableImageRenderer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addImageRendererListener(EditableImageRendererListener listener)
void
addOverlay(Overlay overlay)
Adds an overlay to be shown over the image.void
centerImage()
Centers the image on the renderer, keeping the current scale.protected java.awt.Point
computeOrigin(java.awt.Point imagePoint, java.awt.Point componentPoint, double scale)
Computes a new origin so that the given image point is shown at the given relative coordinates.java.awt.Point
convertImagePointToComponentPoint(java.awt.Point imagePoint)
Given a point in image coordinates, returns the coordinates of the component point which renders that image point.protected void
fireEditingToolActivated(EditingTool editingTool)
protected void
fireEditingToolDeactivated(EditingTool editingTool)
void
fitToDisplaySize()
void
flushAllCaches()
Flush all image caches.void
flushScaledImageCache()
Flush the cached scaled image.double
getAngle()
EditingTool
getEditingTool()
double
getFitScale()
EditableImage
getImage()
Returns the displayed image.javax.swing.border.Border
getImageBorder()
java.awt.Insets
getMargin()
Returns the maximum margin that can be shown around the image.double
getMaxScale()
double
getMinScale()
EditableImage
getOptimizedImage()
Returns a possibly optimized version of the image.java.awt.Point
getOrigin()
java.awt.Point
getPositionOverImage(java.awt.Point componentPoint)
Given a point in component coordinates, returns the coordinates of the image pixel rendered at that point.PreviewSettings
getPreviewSettings()
Gets the preview settings.Quality
getRotateQuality()
Returns the quality used for scale operations.double
getScale()
Quality
getScaleQuality()
Returns the quality used for scale operations.boolean
isOptimizedImageEnabled()
Returns the status of the rgb image caching feature.boolean
isRepaintEnabled()
Returns the state of repaint.boolean
isScaledImageCachingEnabled()
Returns the status of the caching of a scaled image for faster speed.boolean
isScrollBarsVisible()
Return true if the scrollbars are visible.void
moveOrigin(int deltaX, int deltaY)
void
paint(java.awt.Graphics g)
Renders this component.void
removeImageRendererListener(EditableImageRendererListener listener)
void
removeOverlay(Overlay overlay)
void
setAngle(double angle)
void
setClippingShape(java.awt.Shape clippingShape)
Sets a shape to clip rendering against.void
setFitToDisplaySize(boolean fitToDisplaySize)
Enables or disables the fit-to-display-size feature.void
setImage(EditableImage image)
Sets the image to display.void
setImageBorder(javax.swing.border.Border imageBorder)
void
setMargin(java.awt.Insets margin)
Sets the maximum margin that can be shown around the image.void
setMaxScale(double maxScale)
void
setMinScale(double minScale)
void
setOptimizedImageEnabled(boolean optimizedImageEnabled)
Enables or disables the use of an optimized copy of the image.void
setOrigin(java.awt.Point origin)
Sets the image point which is displayed in the top left corner (coordinates are in actual image pixels).void
setPositionOverImage(java.awt.Point imagePoint, java.awt.Point componentPoint)
Ensures that the given image pixel is shown at the given component coordinates.void
setPreviewSettings(PreviewSettings previewSettings)
Sets the preview settings.void
setRepaintEnabled(boolean repaintEnabled)
Turns on/off repaint.void
setRotateQuality(Quality rotateQuality)
Sets the quality used for rotate operations.void
setScale(double scale)
Sets the explicit scale for displaying the current image.void
setScale(double scale, java.awt.Point pivotPoint)
Sets the explicit scale for displaying the current image.void
setScaledImageCachingEnabled(boolean scaledImageCachingEnabled)
Enables or disables the caching of a scaled image for faster speed.void
setScaleQuality(Quality scaleQuality)
Sets the quality used for scale operations.void
setScrollBarsVisible(boolean scrollBarsVisible)
Sets the scrollbars visible or not.void
update(java.awt.Graphics g)
-
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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateUI
-
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, getAccessibleContext, 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
-
-
-
-
Field Detail
-
MAX_SCALE
public static final double MAX_SCALE
The maximum allowed value for scale.- See Also:
- Constant Field Values
-
MIN_SCALE
public static final double MIN_SCALE
The maximum allowed value for scale.- See Also:
- Constant Field Values
-
image
protected EditableImage image
The original image to be displayed.
-
scale
protected double scale
The current scale.
-
angle
protected double angle
The current rotation.
-
editingTool
protected EditingTool editingTool
The current EditingTool.
-
-
Method Detail
-
setImage
public void setImage(EditableImage image)
Sets the image to display. The image is internally cloned, so any further operation performed on the same source (that could cause a model switch) won't affect the rendering.- Parameters:
image
- the image
-
getImage
public EditableImage getImage()
Returns the displayed image.- Returns:
- the image
-
getOptimizedImage
public EditableImage getOptimizedImage()
Returns a possibly optimized version of the image. If useOptimizedImage is false, this method returns the original image.- Returns:
- the image
-
setRepaintEnabled
public void setRepaintEnabled(boolean repaintEnabled)
Turns on/off repaint. It's advisable to turn repainting off before a sequence of operations, and turning it on again only at the end of the sequence.- Parameters:
repaintEnabled
- the new setting
-
isRepaintEnabled
public boolean isRepaintEnabled()
Returns the state of repaint.- Returns:
- the repaint state
-
setOrigin
public void setOrigin(java.awt.Point origin)
Sets the image point which is displayed in the top left corner (coordinates are in actual image pixels).- Parameters:
origin
- the origin
-
getOrigin
public java.awt.Point getOrigin()
-
getScale
public double getScale()
-
setAngle
public void setAngle(double angle)
-
getAngle
public double getAngle()
-
getEditingTool
public EditingTool getEditingTool()
-
setImageBorder
public void setImageBorder(javax.swing.border.Border imageBorder)
-
getImageBorder
public javax.swing.border.Border getImageBorder()
-
getPositionOverImage
public java.awt.Point getPositionOverImage(java.awt.Point componentPoint)
Given a point in component coordinates, returns the coordinates of the image pixel rendered at that point. If the point is outside of the image rendering areas, returns null.- Parameters:
componentPoint
- the point in relative coordinates- Returns:
- the image pixel coordinates (null if none)
-
convertImagePointToComponentPoint
public java.awt.Point convertImagePointToComponentPoint(java.awt.Point imagePoint)
Given a point in image coordinates, returns the coordinates of the component point which renders that image point.- Parameters:
imagePoint
- the point in image coordinates- Returns:
- the point coordinates
-
setPositionOverImage
public void setPositionOverImage(java.awt.Point imagePoint, java.awt.Point componentPoint)
Ensures that the given image pixel is shown at the given component coordinates.- Parameters:
imagePoint
- the coordinates of the image pixelcomponentPoint
- the relative coordinates where to show imagePoint
-
setMargin
public void setMargin(java.awt.Insets margin)
Sets the maximum margin that can be shown around the image. The number of pixels is in image scale. Please note that the margin is ignored when the scroll bars are visible.- Parameters:
margin
- the new margin
-
getMargin
public java.awt.Insets getMargin()
Returns the maximum margin that can be shown around the image.- Returns:
- the margin
-
setScrollBarsVisible
public void setScrollBarsVisible(boolean scrollBarsVisible)
Sets the scrollbars visible or not.- Parameters:
scrollBarsVisible
- the new setting
-
isScrollBarsVisible
public boolean isScrollBarsVisible()
Return true if the scrollbars are visible.- Returns:
- true if the scrollbars are visible
-
computeOrigin
protected java.awt.Point computeOrigin(java.awt.Point imagePoint, java.awt.Point componentPoint, double scale)
Computes a new origin so that the given image point is shown at the given relative coordinates.- Parameters:
imagePoint
- the coordinates of the image pixelcomponentPoint
- the relative coordinates where to show imagePoint- Returns:
- the new origin
-
setScaleQuality
public void setScaleQuality(Quality scaleQuality)
Sets the quality used for scale operations. This operation doesn't force arepaint()
, so it must be explicitly invoked if you want to see immediately the quality change.- Parameters:
quality
- the quality
-
getScaleQuality
public Quality getScaleQuality()
Returns the quality used for scale operations.- Returns:
- the quality
-
setRotateQuality
public void setRotateQuality(Quality rotateQuality)
Sets the quality used for rotate operations. This operation doesn't force arepaint()
, so it must be explicitly invoked if you want to see immediately the quality change.- Parameters:
quality
- the quality
-
getRotateQuality
public Quality getRotateQuality()
Returns the quality used for scale operations.- Returns:
- the quality
-
setScaledImageCachingEnabled
public void setScaledImageCachingEnabled(boolean scaledImageCachingEnabled)
Enables or disables the caching of a scaled image for faster speed.- Parameters:
cacheScaleImageEnabled
- the switch for this property
-
isScaledImageCachingEnabled
public boolean isScaledImageCachingEnabled()
Returns the status of the caching of a scaled image for faster speed.- Returns:
- the status of this feature
-
setOptimizedImageEnabled
public void setOptimizedImageEnabled(boolean optimizedImageEnabled)
Enables or disables the use of an optimized copy of the image.- Parameters:
optimizedImageEnabled
- the switch for this property
-
isOptimizedImageEnabled
public boolean isOptimizedImageEnabled()
Returns the status of the rgb image caching feature.- Returns:
- the status of this feature
-
setClippingShape
public void setClippingShape(java.awt.Shape clippingShape)
Sets a shape to clip rendering against.- Parameters:
clippingShape
- the clipping shape
-
addOverlay
public void addOverlay(Overlay overlay)
Adds an overlay to be shown over the image.- Parameters:
overlay
- the overlay
-
removeOverlay
public void removeOverlay(Overlay overlay)
-
setPreviewSettings
public void setPreviewSettings(PreviewSettings previewSettings)
Sets the preview settings.
-
getPreviewSettings
public PreviewSettings getPreviewSettings()
Gets the preview settings.
-
update
public void update(java.awt.Graphics g)
- Overrides:
update
in classjavax.swing.JComponent
-
paint
public void paint(java.awt.Graphics g)
Renders this component.- Overrides:
paint
in classjavax.swing.JComponent
-
flushAllCaches
public void flushAllCaches()
Flush all image caches.
-
flushScaledImageCache
public void flushScaledImageCache()
Flush the cached scaled image.
-
moveOrigin
public void moveOrigin(int deltaX, int deltaY)
-
setScale
public void setScale(double scale)
Sets the explicit scale for displaying the current image. This disables the fit-to-display-size feature.- Parameters:
scale
- the new scale
-
setScale
public void setScale(double scale, java.awt.Point pivotPoint)
Sets the explicit scale for displaying the current image. This disables the fit-to-display-size feature. A pivot point is specified: the contents under the pivot point don't move during the zoom.- Parameters:
scale
- the new scalepivotPoint
- the pivot point (if null, the center of the renderer is used)
-
setMaxScale
public void setMaxScale(double maxScale)
-
getMaxScale
public double getMaxScale()
-
setMinScale
public void setMinScale(double minScale)
-
getMinScale
public double getMinScale()
-
getFitScale
public double getFitScale()
-
centerImage
public void centerImage()
Centers the image on the renderer, keeping the current scale.
-
fitToDisplaySize
public void fitToDisplaySize()
-
setFitToDisplaySize
public void setFitToDisplaySize(boolean fitToDisplaySize)
Enables or disables the fit-to-display-size feature.
-
addImageRendererListener
public void addImageRendererListener(EditableImageRendererListener listener)
-
removeImageRendererListener
public void removeImageRendererListener(EditableImageRendererListener listener)
-
fireEditingToolActivated
protected void fireEditingToolActivated(EditingTool editingTool)
-
fireEditingToolDeactivated
protected void fireEditingToolDeactivated(EditingTool editingTool)
-
-