cdox.edit
Class Element

java.lang.Object
  extended bycdox.edit.Element
All Implemented Interfaces:
java.awt.datatransfer.Transferable
Direct Known Subclasses:
GenericElement, ImageElement, TextElement

public abstract class Element
extends java.lang.Object
implements java.awt.datatransfer.Transferable

This class represents an element that is contained within a document.

Version:
Jun 10th 2002
Author:
Rutger Bezema, Andreas Schmitz

Field Summary
protected  java.awt.image.BufferedImage cachedImage
          The cached Element.
protected  Cover cover
          The Cover.
protected static java.awt.BasicStroke dashed
          This stroke is updated automatically by the timer.
protected  java.awt.Rectangle diagonalResizeRect
          Needed for the resizing position cursors.
protected  java.awt.Dimension elementSize
          The size of the element.
protected  boolean flipHorizontal
          If true, element is flipped horizontal.
protected  boolean flipVertical
          If true, element is flipped vertical.
protected  java.awt.Rectangle horizontalResizeRect
          Needed for the resizing position cursors.
protected  java.awt.Point position
          The position.
protected  boolean quality
          If true, the element will be transformed with highest quality.
protected  double ratioX
          The X ratio.
protected  double ratioY
          The Y ratio.
protected  double rotateBy
          Element will be rotated by this number as degrees.
protected  java.awt.Rectangle verticalResizeRect
          Needed for the resizing position cursors.
 
Constructor Summary
protected Element(java.awt.Dimension size, java.awt.Point pos)
          Some general initialization work is done here.
 
Method Summary
protected  org.w3c.dom.Element appendChild(org.w3c.dom.Element root, java.lang.String type)
          Appends an "element" element to the root-element with all required attributes set.
protected  void createCachedImage()
          Creates an image of the element.
 void destroyMe()
          This method can be invoked to indicate that this Element is no longer needed.
protected  void drawMyself(java.awt.Graphics2D g)
          Draws itself on the provided graphics object.
 void flipElementHorizontal()
          Flips the element horizontal.
 void flipElementVertical()
          Flips the element vertical.
protected abstract  java.awt.image.BufferedImage getBufferedImage()
          This method must return an untransformed image of the element.
 java.awt.Rectangle getDiagonalResizeRect()
          Returns the diagonal resize rectangle.
 boolean getHighlight()
          Returns whether this Element is highlighted or not.
 java.awt.Rectangle getHorizontalResizeRect()
          Returns the horizontal resize rectangle.
protected  java.awt.geom.AffineTransform getMatrix()
          This method creates the matrix that is needed to perform the various transformations such as rotating/flipping.
 java.awt.Point getPosition()
          Returns the upper left corner of the Element.
 java.awt.geom.AffineTransform getPrintableAffineTransform()
          Returns the affine transform used for printing.
 java.awt.Dimension getSize()
          Returns the size of this element.
 java.awt.Rectangle getVerticalResizeRect()
          Returns the vertical resize rectangle.
 boolean isInPlace(java.awt.Point p)
          Returns true if the element is at the specified position.
 boolean isMaintainingRatio()
          Returns whether this element does maintain its ratio.
static boolean isRotating()
          Returns whether we are rotating or not.
 boolean isSelected()
          This Methods returns true if the Element is selected.
 void moveToTop()
          Moves the element to the top of the list.
 void registerDoAction(DoAction da)
          Registers a doaction with this element.
 void rotateElement(double degrees)
          Rotates the element by the given degrees.
protected abstract  void saveMyself(org.w3c.dom.Element root, java.util.zip.ZipOutputStream out)
          This method saves its data in the given parameters.
protected  void setCover(Cover c)
          Sets the cover that owns this element.
 void setHighlight()
          Toggles highlighting of this element.
 void setMaintainRatio(boolean b)
          Sets whether the aspect ratio of this element should be maintained or not.
 void setPosition(java.awt.Point pos)
          Sets the new position of the element.
 void setQuality(boolean q)
          Sets the quality.
 void setRatio(double x, double y)
          Sets the ratio that should be used, if any.
protected  void setResizeRects()
          Sets the resizing rectangles.
 void setSelected(boolean selected)
          Sets, if this element is selected.
 void setSize(java.awt.Dimension s)
          Sets the new size of the element.
static void startRotating(java.awt.Component c, Element element)
          Starts generating rotated borders of selected elements.
static void stopRotating()
          Stops the rotating border of selected elements.
 java.lang.String toString()
           
 void unregisterDoAction(DoAction da)
          Unregisters a doaction with this element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.datatransfer.Transferable
getTransferData, getTransferDataFlavors, isDataFlavorSupported
 

Field Detail

elementSize

protected java.awt.Dimension elementSize
The size of the element.


position

protected java.awt.Point position
The position.


cover

protected Cover cover
The Cover.


horizontalResizeRect

protected java.awt.Rectangle horizontalResizeRect
Needed for the resizing position cursors.


verticalResizeRect

protected java.awt.Rectangle verticalResizeRect
Needed for the resizing position cursors.


diagonalResizeRect

protected java.awt.Rectangle diagonalResizeRect
Needed for the resizing position cursors.


cachedImage

protected java.awt.image.BufferedImage cachedImage
The cached Element. If null, must be redrawn.


ratioX

protected double ratioX
The X ratio.


ratioY

protected double ratioY
The Y ratio.


quality

protected boolean quality
If true, the element will be transformed with highest quality.


rotateBy

protected double rotateBy
Element will be rotated by this number as degrees.


flipVertical

protected boolean flipVertical
If true, element is flipped vertical.


flipHorizontal

protected boolean flipHorizontal
If true, element is flipped horizontal.


dashed

protected static java.awt.BasicStroke dashed
This stroke is updated automatically by the timer.

Constructor Detail

Element

protected Element(java.awt.Dimension size,
                  java.awt.Point pos)
Some general initialization work is done here.

Parameters:
size - the size.
pos - the position.
Method Detail

startRotating

public static void startRotating(java.awt.Component c,
                                 Element element)
Starts generating rotated borders of selected elements. Please be sure to restart the rotating if the cover and/or the component are no longer used (otherwise you'll end up in offscreen rotating. You want that? Sure?).

Parameters:
c - the component whose repaint() method is frequently called.
element - the element whose cover will be notified frequently about changes.

isRotating

public static boolean isRotating()
Returns whether we are rotating or not.

Returns:
true, if we are.

stopRotating

public static void stopRotating()
Stops the rotating border of selected elements. Just invoke this method if the rotating is not needed any more.


setQuality

public void setQuality(boolean q)
Sets the quality.

Parameters:
q - if true, high quality will be used.

setSelected

public void setSelected(boolean selected)
Sets, if this element is selected. Selected elements get another rectangle drawed around them.

Parameters:
selected - whether this element should be selected.

isSelected

public boolean isSelected()
This Methods returns true if the Element is selected.

Returns:
true if the Element is selected.

setHighlight

public void setHighlight()
Toggles highlighting of this element. If true, causes a rectancle be drawn around this Element, default is false.


getHighlight

public boolean getHighlight()
Returns whether this Element is highlighted or not.

Returns:
true, if the element is highlighted.

setCover

protected void setCover(Cover c)
Sets the cover that owns this element.

Parameters:
c - the cover owning this element. Note that only one cover can use this element at the same time.

isInPlace

public boolean isInPlace(java.awt.Point p)
Returns true if the element is at the specified position.

Parameters:
p - the position.
Returns:
true, if d is a point within the elements position.

moveToTop

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


setMaintainRatio

public void setMaintainRatio(boolean b)
Sets whether the aspect ratio of this element should be maintained or not. Default is true.

Parameters:
b - if true, the ratio will be maintained.

isMaintainingRatio

public boolean isMaintainingRatio()
Returns whether this element does maintain its ratio.

Returns:
true, if it does.

setRatio

public void setRatio(double x,
                     double y)
Sets the ratio that should be used, if any.

Parameters:
x - the x aspect.
y - the y aspect.

setSize

public void setSize(java.awt.Dimension s)
Sets the new size of the element. This is the final size of the element, not of the image/text whatsoever. If the size won't fit into the cover, the size is made smaller.

Parameters:
s - the new size.

setPosition

public void setPosition(java.awt.Point pos)
Sets the new position of the element. Negative values will be counted as 0.

Parameters:
pos - the new position.

getSize

public java.awt.Dimension getSize()
Returns the size of this element.

Returns:
the size.

getPosition

public java.awt.Point getPosition()
Returns the upper left corner of the Element.

Returns:
the the upper left corner.

setResizeRects

protected void setResizeRects()
Sets the resizing rectangles.


getHorizontalResizeRect

public java.awt.Rectangle getHorizontalResizeRect()
Returns the horizontal resize rectangle.

Returns:
a Rectangle value.

getVerticalResizeRect

public java.awt.Rectangle getVerticalResizeRect()
Returns the vertical resize rectangle.

Returns:
a Rectangle value.

getDiagonalResizeRect

public java.awt.Rectangle getDiagonalResizeRect()
Returns the diagonal resize rectangle.

Returns:
a Rectangle value.

flipElementVertical

public void flipElementVertical()
Flips the element vertical.


flipElementHorizontal

public void flipElementHorizontal()
Flips the element horizontal.


registerDoAction

public void registerDoAction(DoAction da)
Registers a doaction with this element. Does currently nothing.

Parameters:
da - a DoAction value.

unregisterDoAction

public void unregisterDoAction(DoAction da)
Unregisters a doaction with this element. Does currently nothing.

Parameters:
da - a DoAction value.

rotateElement

public void rotateElement(double degrees)
Rotates the element by the given degrees.

Parameters:
degrees - the degrees (0-360).

getMatrix

protected java.awt.geom.AffineTransform getMatrix()
This method creates the matrix that is needed to perform the various transformations such as rotating/flipping. The returned does not do the position translating, this is done while drawing.

Returns:
the AffineTransform that contains the matrix.

drawMyself

protected void drawMyself(java.awt.Graphics2D g)
Draws itself on the provided graphics object.

Parameters:
g - where you like it to be drawn.

getBufferedImage

protected abstract java.awt.image.BufferedImage getBufferedImage()
This method must return an untransformed image of the element. The various transformations are done on this element, so it is a good idea to base the size of this image on the size of the element to achieve best quality.

Returns:
the BufferedImage.

createCachedImage

protected void createCachedImage()
Creates an image of the element. This performs all needed transformation in the following order: rotating, flipping, translating (to correct the rotating/flipping) and scaling. Position translation is a task of drawing and not done here.


getPrintableAffineTransform

public java.awt.geom.AffineTransform getPrintableAffineTransform()
Returns the affine transform used for printing.

Returns:
an AffineTransform value.

appendChild

protected org.w3c.dom.Element appendChild(org.w3c.dom.Element root,
                                          java.lang.String type)
Appends an "element" element to the root-element with all required attributes set.

Parameters:
root - the Element to which the child will be appended.
type - the type of the element which will be added (currently one of "text" or "image").
Returns:
the newly created element, to which the content element has to be added.

saveMyself

protected abstract void saveMyself(org.w3c.dom.Element root,
                                   java.util.zip.ZipOutputStream out)
                            throws java.io.IOException
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).

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:
appendChild(org.w3c.dom.Element, java.lang.String)

toString

public java.lang.String toString()

destroyMe

public void destroyMe()
This method can be invoked to indicate that this Element is no longer needed.