cdox.edit
Class ImageElement

java.lang.Object
  extended bycdox.edit.Element
      extended bycdox.edit.ImageElement
All Implemented Interfaces:
java.awt.datatransfer.Transferable

public class ImageElement
extends Element

This class represents an element that is contained within a document. An ImageElement can contain an Image as data.

Author:
Rutger Bezema, Andreas Schmitz

Field Summary
 
Fields inherited from class cdox.edit.Element
cachedImage, cover, dashed, diagonalResizeRect, elementSize, flipHorizontal, flipVertical, horizontalResizeRect, position, quality, ratioX, ratioY, rotateBy, verticalResizeRect
 
Constructor Summary
ImageElement(java.awt.Point pos, java.awt.Dimension size, java.lang.String imageSource, Cover c)
          Constructs a new ImageElement with a scaledImage at position pos.
 
Method Summary
protected  java.awt.image.BufferedImage getBufferedImage()
          This method returns a bufferedImage.
 java.awt.image.BufferedImage getCurrentImage()
          Returns the Original image with applied filters etc.
 java.lang.String getKey()
          Returns the current key used to load the image of disk.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor f)
          Returns the scaled instance of the original Image.
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
           
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor f)
           
 void resetImage()
          This method can be called to set the original image to null, and than call the garbageCollector.
 void resetOldImage(java.lang.String key)
          Resets the oldImage to the image represented by the given key.
protected  void saveMyself(org.w3c.dom.Element root, java.util.zip.ZipOutputStream out)
          This method saves its data in the given parameters.
 void setPaintImage(java.awt.image.BufferedImage bi)
          This method sets the filteredImage to this ImageElement.
 
Methods inherited from class cdox.edit.Element
appendChild, createCachedImage, destroyMe, drawMyself, flipElementHorizontal, flipElementVertical, getDiagonalResizeRect, getHighlight, getHorizontalResizeRect, getMatrix, getPosition, getPrintableAffineTransform, getSize, getVerticalResizeRect, isInPlace, isMaintainingRatio, isRotating, isSelected, moveToTop, registerDoAction, rotateElement, setCover, setHighlight, setMaintainRatio, setPosition, setQuality, setRatio, setResizeRects, setSelected, setSize, startRotating, stopRotating, toString, unregisterDoAction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImageElement

public ImageElement(java.awt.Point pos,
                    java.awt.Dimension size,
                    java.lang.String imageSource,
                    Cover c)
             throws java.io.IOException
Constructs a new ImageElement with a scaledImage at position pos.

Parameters:
pos - the position.
size - the size.
imageSource - the ID that can be used to get the image from the TempFiles class.
c - the cover which contains this image (used for calculating acpect ratio)
Throws:
java.io.IOException - if an error occurs.
Method Detail

setPaintImage

public void setPaintImage(java.awt.image.BufferedImage bi)
This method sets the filteredImage to this ImageElement. If the scaleFactor is smaller as 1.0f (the original image doesn't fit in the cover) a scaled instance is calculated to fit in the cover, e.g. to work with.

Parameters:
bi - the filtered BufferedImage to be drawn
See Also:
ImageDialog.run()

getKey

public java.lang.String getKey()
Returns the current key used to load the image of disk.

Returns:
the String.

resetOldImage

public void resetOldImage(java.lang.String key)
Resets the oldImage to the image represented by the given key. This method is called when the user redo's Undo's an Imagecorrection.

Parameters:
key - the key of the oldFile.
See Also:
BackgroundEditAction.undo(), BackgroundEditAction.redo()

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor f)

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor f)
Returns the scaled instance of the original Image. To use this correctly also call the isZipFileUsed() method and the getBackgroundFile() or getZipFile()-getZipEntry() combination.

Parameters:
f - the kind of data which represent an image
Returns:
the scaled instance of the original image.
See Also:
EditAction.actionPerformed(java.awt.event.ActionEvent)

getCurrentImage

public java.awt.image.BufferedImage getCurrentImage()
Returns the Original image with applied filters etc.

Returns:
the original image with applied filters.
See Also:
getBufferedImage(), ImageDialog

getBufferedImage

protected java.awt.image.BufferedImage getBufferedImage()
This method returns a bufferedImage. If quality is set to true, which means we need to do some important things with the image, the image is read from disk anew, and given back. That is if it (the image) is in it's original state larger as the Cover it contains. Else the image will not occupy much memory and there is no use for "caching" it from disk. If the image was filtered by the user the filters are applied to the read-image. This is not nessecary for low quality Pictures, then the paintimage contains the filterdImage allready.

Specified by:
getBufferedImage in class Element
Returns:
the image representing this ImageElement.

resetImage

public void resetImage()
This method can be called to set the original image to null, and than call the garbageCollector. Memory savings I say.


saveMyself

protected void saveMyself(org.w3c.dom.Element root,
                          java.util.zip.ZipOutputStream out)
                   throws java.io.IOException
Description copied from class: Element
This method saves its data in the given parameters. It appends a child element ("element") to the given root element and saves its file(s), if any, to the ZipOutputStream. There exists a convenience method (appendChild()) which appends the child containing all required attributes to the root element, while returning the newly created child, so you can concentrate on the content (which must be appended to the "element" element).

Specified by:
saveMyself in class Element
Parameters:
root - the root element to append the child to.
out - the ZipOutputStream to write any files to.
Throws:
java.io.IOException - if writing into the ZipStream failed.
See Also:
Element.appendChild(org.w3c.dom.Element, java.lang.String)