cdox.edit
Class Cover

java.lang.Object
  extended bycdox.edit.Cover
All Implemented Interfaces:
CDCoverStandards, java.awt.print.Printable

public class Cover
extends java.lang.Object
implements CDCoverStandards, java.awt.print.Printable

This class is the real implementation for the off-screen CDover. All elements are added here, and the printing is done in this class also. Which means it implements the Printable interface, and is called from cdox.print.PrintCover. The upperclass (the class containing this class) is CDDrawingPane.

Version:
Nov 11th 2002
Author:
Rutger Bezema, Andreas Schmitz
See Also:
print(java.awt.Graphics, java.awt.print.PageFormat, int), PrintCover, CDDrawingPane

Field Summary
protected  int[] size
          Size of this cover (inherited of CDCoverStandards).
 
Fields inherited from interface cdox.edit.CDCoverStandards
ALL, CDBACK_SIDE, CDBACK_SIDE_SIZE, CDBACK_SIZE, CDBOOKLET, CDBOOKLET_SIZE, CDFRONT, CDFRONT_SIZE, CDSIDE_SIZE, CDX, GIF, JPG, PNG
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
Cover(int type)
          Creates a new cover with no elements.
 
Method Summary
 void addElement(Element e)
          Adds an element to the cover.
 void deleteBackgroundImage()
          Deletes the backgroundImage, and all of its sources.
 void destroyMe()
          This method can be invoked to indicate that this Cover is no longer needed.
 void drawMyself(java.awt.Graphics gr)
          Draws the whole thing onto the given graphics.
 void exportMySelf(java.io.File f)
          This method exports this Cover to an image.
protected  void fireChanged()
          Causes the internal image to be repainted.
 java.awt.Color getBackgroundColor()
          Returns the background color.
 java.awt.image.BufferedImage getBackgroundImage()
          Returns the backgroundimage or null im no backgroundImage is present.
 java.awt.image.BufferedImage getBufferedImage()
          Returns an image with all elements painted.
 boolean getDragging()
          Determines whether the top element is dragged or not.
 Element getElementAtPosition(java.awt.Point p)
          Returns the element that is at the top of the specified position.
 boolean getGrayscale()
          Returns the current gray value, gray is true if the Cover is drawn in gray.
 java.lang.String getKey()
          Returns the currentKey which loads the image of disk.
 java.awt.RenderingHints getRenderingHints()
          This method sets a couple of rendering hints depending on the quality set.
 Element getSelectedElement()
          Returns the selected Element.
 int[] getSize()
          Returns the size in an int array, size[0] = width, size[1] = height.
 int getType()
          Returns the type of this cover.
 boolean hasBackgroundImage()
          Returns whether this cover has a backgroundImage set.
 boolean hasElements()
          Returns true if this cover has any elements.
 void moveToBack(Element e)
          Moves an element to the bottom of the list.
 void moveToTop(Element e)
          Moves an element to the top of the list.
 int print(java.awt.Graphics gr, java.awt.print.PageFormat p, int index)
          Here the printing is done.
 void removeAllElements()
          Removes all elements from this cover, and destroys them properly.
 void removeElement(Element e)
          Removes an element from this cover.
 void resetBackgroundImage(java.lang.String key)
          Resets the backgroundImage to the image represented by the given key.
 void saveMemory()
          Sets the origBackImage to null and runs the GarbageCollector.
 void saveMyself(org.w3c.dom.Document doc, java.util.zip.ZipOutputStream out)
          Writes his properties into the DOM document and causes the elements to write their files into the ZipOutputStream, if any.
 void setBackground(java.awt.image.BufferedImage bi, java.lang.String source, boolean fit)
          Sets the background image.
 void setBackground(java.awt.Color c)
          Sets the background color for this cover.
 void setBackground(java.lang.String source, boolean fit)
          Sets the background image.
 void setDragging(boolean dragging)
          Sets whether the top element is being dragged.
 void setFilteredBackgroundImage(java.awt.image.BufferedImage bi)
          Sets the backgroundImage anew, with the (filtered) bufferedImage.
 void setGrayscale(boolean gray)
          Sets whether the image should be drawn gray or not.
 void setPrintCompanion(Cover[] c)
          Sets which covers will be printed together with this Cover on the same page.
 void setQuality(boolean q)
          Sets the quality of the cover.
protected  void setSelectedElement(Element e)
          Sets the currently selected Element.
 void setStrokeSize(float f)
          Set the stroke size to draw the coverBorders with.
 java.lang.String toString()
          Returns a string containing debug information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

size

protected int[] size
Size of this cover (inherited of CDCoverStandards).

Constructor Detail

Cover

public Cover(int type)
Creates a new cover with no elements. The type should be one of CDFRONT, CDCOVER, CDBOOKLET and CDBACK_SIDE.

Parameters:
type - the type of the new Cover.
See Also:
CDCoverStandards
Method Detail

toString

public java.lang.String toString()
Returns a string containing debug information.

Returns:
a String value.

getKey

public java.lang.String getKey()
Returns the currentKey which loads the image of disk.

Returns:
the key to load the image.

getSize

public int[] getSize()
Returns the size in an int array, size[0] = width, size[1] = height.


getType

public int getType()
Returns the type of this cover.

Returns:
the type.
See Also:
CDCoverStandards

addElement

public void addElement(Element e)
Adds an element to the cover.

Parameters:
e - the added element.

getSelectedElement

public Element getSelectedElement()
Returns the selected Element.

Returns:
the element.

setSelectedElement

protected void setSelectedElement(Element e)
Sets the currently selected Element.

Parameters:
e - the element.

getElementAtPosition

public Element getElementAtPosition(java.awt.Point p)
Returns the element that is at the top of the specified position.

Parameters:
p - the position.
Returns:
the element or null, if none was found.

removeElement

public void removeElement(Element e)
Removes an element from this cover.

Parameters:
e - the element to be removed.

hasElements

public boolean hasElements()
Returns true if this cover has any elements.

Returns:
true if has elements false otherwhise

removeAllElements

public void removeAllElements()
Removes all elements from this cover, and destroys them properly.


moveToTop

public void moveToTop(Element e)
Moves an element to the top of the list.

Parameters:
e - the element.

moveToBack

public void moveToBack(Element e)
Moves an element to the bottom of the list.

Parameters:
e - the element.

setBackground

public void setBackground(java.awt.Color c)
Sets the background color for this cover. This will delete a previously set background image.

Parameters:
c - the cover.

getBackgroundColor

public java.awt.Color getBackgroundColor()
Returns the background color.

Returns:
null, if no background was set or a background image has been set, the background color otherwise.

setBackground

public void setBackground(java.lang.String source,
                          boolean fit)
                   throws java.io.IOException
Sets the background image.

Parameters:
source - the TempFiles source id.
fit - if true, the background image will occupy the whole cover. If false, and the cover type is CDBACK_SIDE the side borders will be left free.
Throws:
java.io.IOException - if an error occurs.

setBackground

public void setBackground(java.awt.image.BufferedImage bi,
                          java.lang.String source,
                          boolean fit)
Sets the background image.

Parameters:
bi - the allready loaded backgroundImage
source - the TempFiles source id.
fit - if true, the background image will occupy the whole cover. If false, and the cover type is CDBACK_SIDE the side borders will be left free.
Throws:
java.io.IOException - if an error occurs.

deleteBackgroundImage

public void deleteBackgroundImage()
Deletes the backgroundImage, and all of its sources.


hasBackgroundImage

public boolean hasBackgroundImage()
Returns whether this cover has a backgroundImage set.

Returns:
true, if it has one.

getBackgroundImage

public java.awt.image.BufferedImage getBackgroundImage()
Returns the backgroundimage or null im no backgroundImage is present.

Returns:
the original backgroundImage or null if not present.

setFilteredBackgroundImage

public void setFilteredBackgroundImage(java.awt.image.BufferedImage bi)
Sets the backgroundImage anew, with the (filtered) bufferedImage. If the scaleFactors are smaller as 1f the scaled-backgroundimage is recalculated, if not it is just reseted to bi. The arrayList containing the correctors are for the case that the scaleFactors are smaller as 1f.

Parameters:
bi - the new filteredImage
See Also:
getBackgroundImage()

resetBackgroundImage

public void resetBackgroundImage(java.lang.String key)
Resets the backgroundImage to the image represented by the given key. This method is called when the user redo's Undo's a backgroundImage correction.

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

getRenderingHints

public java.awt.RenderingHints getRenderingHints()
This method sets a couple of rendering hints depending on the quality set. It returns the quality-hints (containing: COLOR_RENDERING_ON, ANTIALIASING_ON, TEXT_ANTIALIASING_ON, FRACTIONALMETRICS_ON, DITHERING_ENABLE, STROKE_CONTROL_PURE and BICUBIC_INTERPOLATION) the not quality hints sets them all of resulting in quicker movement e.d.

Returns:
the brand new renderinghints.

setQuality

public void setQuality(boolean q)
Sets the quality of the cover.

Parameters:
q - if true, the quality will be high, but the performance will significantly slow down.

setGrayscale

public void setGrayscale(boolean gray)
Sets whether the image should be drawn gray or not.

Parameters:
gray - true, if it should be gray. Default is false.

getGrayscale

public boolean getGrayscale()
Returns the current gray value, gray is true if the Cover is drawn in gray.

Returns:
true if this cover is drawn in gray false otherwise.

fireChanged

protected void fireChanged()
Causes the internal image to be repainted.


setDragging

public void setDragging(boolean dragging)
Sets whether the top element is being dragged. This method can end up in a better performance while dragging a single element over thousands of others. Please note, that you should not change anything in the cover while dragging, at least most changes won't be drawn (only the dragged element will be drawn new). If no elements exist and the parameter is true, nothing happens.

Parameters:
dragging - whether we are dragging or not.

getDragging

public boolean getDragging()
Determines whether the top element is dragged or not.

Returns:
true, if we are dragging.

setStrokeSize

public void setStrokeSize(float f)
Set the stroke size to draw the coverBorders with.

Parameters:
f - the size of the stroke.

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Returns an image with all elements painted.

Returns:
the BufferedImage.

drawMyself

public void drawMyself(java.awt.Graphics gr)
Draws the whole thing onto the given graphics.

Parameters:
gr - the graphics to paint on.

saveMyself

public void saveMyself(org.w3c.dom.Document doc,
                       java.util.zip.ZipOutputStream out)
                throws java.io.IOException
Writes his properties into the DOM document and causes the elements to write their files into the ZipOutputStream, if any.

Parameters:
doc - the DOM document.
out - the ZipOutputStream.
Throws:
java.io.IOException - if writing to the zip failed.

exportMySelf

public void exportMySelf(java.io.File f)
This method exports this Cover to an image. It renders all this covers Objects on a buffered image, using the drawMySelfHighQuality-Method, and than writes the bufferedImage in the given file.

Parameters:
f - the file to export to
See Also:
FileAction.actionPerformed(java.awt.event.ActionEvent)

setPrintCompanion

public void setPrintCompanion(Cover[] c)
Sets which covers will be printed together with this Cover on the same page.

Parameters:
c - the other covers.

print

public int print(java.awt.Graphics gr,
                 java.awt.print.PageFormat p,
                 int index)
          throws java.awt.print.PrinterException
Here the printing is done. First the quality rendering hints are added to the Printer's graphics-object than the original background image is loaded out of a file (or zipFile) after that all the elements are drawn on the the printer's graphics object. Last of all if this cover has a print companinion and this is not a backside-cover the companion is called.

Specified by:
print in interface java.awt.print.Printable
Parameters:
gr - the graphics object of the printer
p - the pageformat,
index - the x-side to be printed (we only print one side at the time).
Returns:
the Printable standards NO_SUCH_PAGE or PAGE_EXISTS.
Throws:
java.awt.print.PrinterException - if an error occurs.
See Also:
PrintCover.run()

destroyMe

public void destroyMe()
This method can be invoked to indicate that this Cover is no longer needed. This does also destroy its elements.


saveMemory

public void saveMemory()
Sets the origBackImage to null and runs the GarbageCollector.