Holger's Java API

## com.antelmann.image
Class JImagePanel

    java.lang.Object
      java.awt.Component
          java.awt.Container
              javax.swing.JComponent
                  com.antelmann.image.JImagePanel

All Implemented Interfaces:
  EditableComponent, ValueRetriever<Image>, ValueSetter<Image>, ImageObserver, MenuContainer, Serializable

    public class JImagePanel

extends JComponent
implements ValueRetriever<Image>, ValueSetter<Image>, EditableComponent

a special panel for images that allows drag/drop as well as copy/paste. This component fires `PropertyChangeEvent` objects with key 'image' upon changing the image. By default, the component is editable. All image changes fire a property change event with key 'image'. `JComponent.setEnabled(boolean)` is effectively the same as `setEditable(boolean)`.

Since:
  10/23/08
Author:
  Holger Antelmann
See Also:
  Serialized Form

Nested Class Summary

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
`accessibleContext, 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
`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
`JImagePanel()` uses 200 x 200 as dimension
`JImagePanel(Dimension d)`
`JImagePanel(Image image)` takes height and width from the given image
`JImagePanel(Image image, Dimension d)`
`JImagePanel(Image image, Dimension d, boolean enableDelete)`
`JImagePanel(Image image, int width, int height)`
`JImagePanel(int width, int height)`

Method Summary
`void` `addContextMenuFactory(Factory<JMenuItem> factory)` allows to register an additional context menu option by providing a factory that can conditionally return a JMenuItem.
`void` `clearContextMenuFactory()`
`protected JPopupMenu` `createContextMenu()` creates the pop-up menu that is enabled on the component.
`protected File` `createFileForDrop()` creates and returns a temp file with some generated name using 'unnamed_file' as a prefix
`protected void` `crop(Point cp, Point dp)`
`Image` `getImage()`
`String` `getImageFileSaveFormat()`
`Filter<Image>` `getImageImportFilter()`
`Image` `getRelevantValue()` returns the relevant value for this instance at the time of calling
`Filter<URL>` `getUrlImportFilter()`
`protected boolean` `importTransferable(Transferable t)`
`boolean` `isCroppingEnabled()`
`boolean` `isEditable()`
`boolean` `isScaleUpToFit()` determines whether the image is to be scaled if it is smaller than the panel (false by default)
`protected boolean` `isSupported(DataFlavor[] flavors)`
`protected boolean` `isSupported(Transferable t)`
`protected void` `paintComponent(Graphics g)`
`protected void` `rotate(double degrees)`
`void` `setCroppingEnabled(boolean flag)`
`void` `setEditable(boolean flag)`
`void` `setImage(Image image)` fires a property change event with key 'image'.
`void` `setImageFile(File file)` simply calls the `setImageURL(URL)` method
`void` `setImageFileSaveFormat(String imageFileSaveFormat)`
`void` `setImageImportFilter(Filter<Image> imageFilter)` allows to set a filter that is applied when importing an image through either drag and drop or pasting
`void` `setImageProcessor(Processor<Image,? extends RuntimeException> imageProcessor)` allows to alter the image before it's set by `setImage(Image)` (for instance by scaling it)
`void` `setImageURL(URL url)` calls `setImage(Image)` on the InputStream read
`void` `setRelevantValue(Image image)` sets the relevant value for this instance with the given value
`void` `setScaleUpToFit(boolean scaleUpToFilt)` allows to specify whether the image is to be scaled if it is smaller than the panel
`void` `setUrlImportFilter(Filter<URL> urlImportFilter)`
`void` `showInSeparateFrame()` called from the popup menu when the image is to be shown in a separate frame
`protected Point` `toImagePoint(Point componentPoint)`

Methods inherited from class javax.swing.JComponent

`addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, update, 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, transferFocusBackward, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, transferFocusUpCycle`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### JImagePanel

    public JImagePanel()

  uses 200 x 200 as dimension

### JImagePanel

    public JImagePanel(int width,
                       int height)

### JImagePanel

    public JImagePanel(Dimension d)

### JImagePanel

    public JImagePanel(Image image,
                       int width,
                       int height)

### JImagePanel

    public JImagePanel(Image image)

  takes height and width from the given image

### JImagePanel

    public JImagePanel(Image image,
                       Dimension d)

### JImagePanel

    public JImagePanel(Image image,
                       Dimension d,
                       boolean enableDelete)

Method Detail

### addContextMenuFactory

    public void addContextMenuFactory(Factory<JMenuItem> factory)

  allows to register an additional context menu option by providing a factory that can conditionally return a JMenuItem. The given factory will be called with an EventObject that has this instance as a source.

### clearContextMenuFactory

    public void clearContextMenuFactory()

### isSupported

    protected boolean isSupported(Transferable t)

### isSupported

    protected boolean isSupported(DataFlavor[] flavors)

### importTransferable

    protected boolean importTransferable(Transferable t)
                                  throws UnsupportedFlavorException,
                                         IOException

  Throws:
    `UnsupportedFlavorException`
    `IOException`

### setCroppingEnabled

    public void setCroppingEnabled(boolean flag)

### isCroppingEnabled

    public boolean isCroppingEnabled()

### crop

    protected void crop(Point cp,
                        Point dp)

### toImagePoint

    protected Point toImagePoint(Point componentPoint)

### rotate

    protected void rotate(double degrees)

### createContextMenu

    protected JPopupMenu createContextMenu()

  creates the pop-up menu that is enabled on the component. This method gets called every time the context menu is activated, so that it is dynamically customized towards the current state.

### createFileForDrop

    protected File createFileForDrop()
                              throws IOException

  creates and returns a temp file with some generated name using 'unnamed_file' as a prefix

  Throws:
    `IOException`

### getImageImportFilter

    public Filter<Image> getImageImportFilter()

### setImageImportFilter

    public void setImageImportFilter(Filter<Image> imageFilter)

  allows to set a filter that is applied when importing an image through either drag and drop or pasting

### getUrlImportFilter

    public Filter<URL> getUrlImportFilter()

### setUrlImportFilter

    public void setUrlImportFilter(Filter<URL> urlImportFilter)

### getImageFileSaveFormat

    public String getImageFileSaveFormat()

### setImageFileSaveFormat

    public void setImageFileSaveFormat(String imageFileSaveFormat)

### setImageProcessor

    public void setImageProcessor(Processor<Image,? extends RuntimeException> imageProcessor)

  allows to alter the image before it's set by `setImage(Image)` (for instance by scaling it)

### showInSeparateFrame

    public void showInSeparateFrame()

  called from the popup menu when the image is to be shown in a separate frame

### setImageFile

    public void setImageFile(File file)
                      throws IOException

  simply calls the `setImageURL(URL)` method

  Throws:
    `IOException`

### setImageURL

    public void setImageURL(URL url)
                     throws IOException

  calls `setImage(Image)` on the InputStream read

  Throws:
    `IOException`

### setImage

    public void setImage(Image image)

  fires a property change event with key 'image'.

### getImage

    public Image getImage()

### getRelevantValue

    public Image getRelevantValue()

  Description copied from interface: `ValueRetriever`
  returns the relevant value for this instance at the time of calling

  Specified by:
    `getRelevantValue` in interface `ValueRetriever<Image>`

### setRelevantValue

    public void setRelevantValue(Image image)
                          throws Exception

  Description copied from interface: `ValueSetter`
  sets the relevant value for this instance with the given value

  Specified by:
    `setRelevantValue` in interface `ValueSetter<Image>`
  Throws:
    `Exception`

### isScaleUpToFit

    public boolean isScaleUpToFit()

  determines whether the image is to be scaled if it is smaller than the panel (false by default)

### setScaleUpToFit

    public void setScaleUpToFit(boolean scaleUpToFilt)

  allows to specify whether the image is to be scaled if it is smaller than the panel

### paintComponent

    protected void paintComponent(Graphics g)

  Overrides:
    `paintComponent` in class `JComponent`

### isEditable

    public boolean isEditable()

  Specified by:
    `isEditable` in interface `EditableComponent`

### setEditable

    public void setEditable(boolean flag)

  Specified by:
    `setEditable` in interface `EditableComponent`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads