Class AbstractItem
- java.lang.Object
-
- ca.cgjennings.apps.arkham.deck.item.AbstractItem
-
- All Implemented Interfaces:
PageItem
,java.io.Serializable
,java.lang.Cloneable
- Direct Known Subclasses:
AbstractFlippableItem
,Line
public abstract class AbstractItem extends java.lang.Object implements PageItem
A base implementation of a non-resizeable, non-flippable page item.- Author:
- Chris Jennings
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ca.cgjennings.apps.arkham.deck.item.PageItem
PageItem.SnapClass, PageItem.SnapTarget
-
-
Field Summary
Fields Modifier and Type Field Description protected DragHandle[]
dragHandles
protected Group
group
protected Page
parent
protected boolean
selectionLock
protected PageItem.SnapClass
snapClass
protected PageItem.SnapTarget
snapTarget
protected java.util.EnumSet<PageItem.SnapClass>
snapToClasses
protected double
xOff
protected double
yOff
-
Fields inherited from interface ca.cgjennings.apps.arkham.deck.item.PageItem
ICON_SIZE, ORIENT_MIRROR_TURN_LEFT, ORIENT_MIRROR_TURN_RIGHT, ORIENT_MIRROR_UPRIGHT, ORIENT_MIRROR_UPSIDEDOWN, ORIENT_TURN_LEFT, ORIENT_TURN_RIGHT, ORIENT_UPRIGHT, ORIENT_UPSIDEDOWN
-
-
Constructor Summary
Constructors Constructor Description AbstractItem()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description PageItem
clone()
Returns a new page item, using this item as a template.void
customizePopupMenu(javax.swing.JPopupMenu menu, PageItem[] selection, boolean isSelectionFocus)
Allows a page item the opportunity to customize the popup menu before it is displayed.double
getBleedMargin()
Returns the bleed margin used for any automatic crop marks, in points.java.util.EnumSet<PageItem.SnapClass>
getClassesSnappedTo()
Get the set of classes this card snaps against.java.lang.String
getClientProperty(java.lang.String property)
Returns the value of a client property of this page item, ornull
if the property is not defined.DragHandle[]
getDragHandles()
Returns an array of the customDragHandle
s for this item.double[]
getFoldMarks()
Return an array of the relative positions and directions of extra fold marks for this item.Group
getGroup()
Returns theGroup
that this item belongs to, ornull
.abstract double
getHeight()
Return the height of this item, in points.java.awt.geom.Point2D
getLocation()
Returns the location of this item as aPoint2D
.int
getOrientation()
Return an the item's current orientation.java.awt.Shape
getOutline()
Return aShape
that corresponds to the outline of this item.Page
getPage()
Return the page that owns this item, ornull
if it has no parent.java.awt.geom.Rectangle2D.Double
getRectangle()
Return a rectangle of the bounds of this item.PageItem.SnapClass
getSnapClass()
Get the class this item counts as for snapping.PageItem.SnapTarget
getSnapTarget()
Get the snap target rule for this item.abstract javax.swing.Icon
getThumbnailIcon()
Returns a small representative icon for this item.abstract double
getWidth()
Return the width of this item, in points.double
getX()
Returns the current x-position of this card.double
getY()
Returns the current y-position of this card.boolean
hasExteriorHandles()
Returnstrue
if this item has one or more drag handles that may lie outside of the item's bounding box.boolean
hitTest(java.awt.geom.Point2D p)
Returnstrue
ifpoint
is inside the visible bounds of this object.boolean
isBleedMarginMarked()
Returnstrue
if this item should have crop marks added to it.boolean
isHorizontal()
Returnstrue
if this is in a horizontal orientation (turned 90 degrees from normal).boolean
isMirrored()
Returnstrue
if this item is mirror-imaged.boolean
isSelectionLocked()
Returnstrue
if this item is locked against selection.boolean
isTurned0DegreesFrom(PageItem rhs)
Returnstrue
if this item has the same orientation rotation as another item.boolean
isTurned180DegreesFrom(PageItem rhs)
Returns true if this item's orientation is turned 180 degrees relative to another item.boolean
isTurned90DegreesFrom(PageItem rhs)
Returns true if this item's orientation is turned 90 degrees relative to another item.boolean
isVertical()
Returnstrue
if card is in a vertical orientation.protected void
itemChanged()
Called by subclasses when the item's visual representation, location, or size changes.protected void
itemChanging()
Called by subclasses when the item's visual representation, location, or size is about to change.abstract void
paint(java.awt.Graphics2D g, RenderTarget target, double renderResolutionHint)
Paint this item at its current location.void
prepareToPaint(RenderTarget target, double renderResolutionHint)
Update any cached representations needed to paint this item at the specified settings.void
putClientProperty(java.lang.String property, java.lang.String value)
Sets a client property on this page item.protected void
readImpl(java.io.ObjectInputStream in)
void
setClassesSnappedTo(java.util.EnumSet<PageItem.SnapClass> snapClasses)
Set the set of classes this card snaps against.void
setGroup(Group g)
Sets theGroup
for this item.void
setLocation(double x, double y)
Set the location of this item.void
setLocation(java.awt.geom.Point2D loc)
Set the location of this item.void
setPage(Page parent)
Set the page which is the parent of this card, ornull
to clear its parent.void
setSelectionLocked(boolean lock)
Set the state of the item's selection lock.void
setSnapClass(PageItem.SnapClass snapClass)
Set the class this item counts as for snapping.void
setSnapTarget(PageItem.SnapTarget target)
Set the snap target rule for this item.void
setX(double x)
Set the x-location of this item.void
setY(double y)
Set the y-location of this item.java.lang.String
toString()
protected void
writeImpl(java.io.ObjectOutputStream out)
-
-
-
Field Detail
-
xOff
protected double xOff
-
yOff
protected double yOff
-
parent
protected Page parent
-
snapToClasses
protected java.util.EnumSet<PageItem.SnapClass> snapToClasses
-
snapTarget
protected PageItem.SnapTarget snapTarget
-
snapClass
protected PageItem.SnapClass snapClass
-
selectionLock
protected boolean selectionLock
-
group
protected Group group
-
dragHandles
protected transient DragHandle[] dragHandles
-
-
Method Detail
-
paint
public abstract void paint(java.awt.Graphics2D g, RenderTarget target, double renderResolutionHint)
Description copied from interface:PageItem
Paint this item at its current location. The graphics context will be scaled so that 1 unit represents 1 point. The resolution hint is a suggestion as to the resolution the item should be rendered at if it must be converted to a bitmap before being drawn. It may or may not represent the actual resolution of the output target.
-
prepareToPaint
public void prepareToPaint(RenderTarget target, double renderResolutionHint)
Description copied from interface:PageItem
Update any cached representations needed to paint this item at the specified settings. It is not required that this be called prior to callingPageItem.paint(java.awt.Graphics2D, ca.cgjennings.apps.arkham.sheet.RenderTarget, double)
. Rather, the intent is that if this method returns without throwing any exceptions (such asOutOfMemoryError
), then a call toPageItem.paint(java.awt.Graphics2D, ca.cgjennings.apps.arkham.sheet.RenderTarget, double)
with the same settings is also expected to succeed. Thus, this method may be called prior to rendering at high resolution and if it throws anOutOfMemoryError
, the application can attempt to recover by freeing up resources before trying to paint again.If this
PageItem
does not require rendering to a buffer, then this method may do nothing.- Specified by:
prepareToPaint
in interfacePageItem
- Parameters:
target
- the rendering targetrenderResolutionHint
- a hint regarding output resolution- See Also:
PageItem.paint(java.awt.Graphics2D, ca.cgjennings.apps.arkham.sheet.RenderTarget, double)
-
getWidth
public abstract double getWidth()
Description copied from interface:PageItem
Return the width of this item, in points.
-
getHeight
public abstract double getHeight()
Description copied from interface:PageItem
Return the height of this item, in points.
-
setPage
public void setPage(Page parent)
Description copied from interface:PageItem
Set the page which is the parent of this card, ornull
to clear its parent. ThePage
class will set the parent automatically when a card is added or removed from it.
-
getPage
public Page getPage()
Description copied from interface:PageItem
Return the page that owns this item, ornull
if it has no parent.
-
getRectangle
public java.awt.geom.Rectangle2D.Double getRectangle()
Description copied from interface:PageItem
Return a rectangle of the bounds of this item.- Specified by:
getRectangle
in interfacePageItem
- Returns:
- a bounding rectangle for the item
-
getOutline
public java.awt.Shape getOutline()
Description copied from interface:PageItem
Return aShape
that corresponds to the outline of this item. In the simplest case, this can return the same result asPageItem.getRectangle()
. If precise geometry is available for the item, then this should return a more accurate bounding shape.- Specified by:
getOutline
in interfacePageItem
- Returns:
- the outline of this object
-
hitTest
public boolean hitTest(java.awt.geom.Point2D p)
Description copied from interface:PageItem
Returnstrue
ifpoint
is inside the visible bounds of this object.
-
getDragHandles
public DragHandle[] getDragHandles()
Returns an array of the customDragHandle
s for this item. If the item has no handles, returnsnull
.Concrete subclasses should create an array of handles on demand and cache them in the
dragHandles
field in order to ensure that handles are not shared between copies of the item. Example:public DragHandle[] getDragHandles() { if( dragHandles == null ) { dragHandles = new DragHandle[] { ... }; } return dragHandles; }
- Specified by:
getDragHandles
in interfacePageItem
- Returns:
- an array of drag handles that can be used to manipulate the item,
or
null
-
getSnapClass
public PageItem.SnapClass getSnapClass()
Description copied from interface:PageItem
Get the class this item counts as for snapping.- Specified by:
getSnapClass
in interfacePageItem
- Returns:
- the snap class of this item
-
setSnapClass
public void setSnapClass(PageItem.SnapClass snapClass)
Description copied from interface:PageItem
Set the class this item counts as for snapping.- Specified by:
setSnapClass
in interfacePageItem
- Parameters:
snapClass
- the new snap class for this item
-
getClassesSnappedTo
public java.util.EnumSet<PageItem.SnapClass> getClassesSnappedTo()
Description copied from interface:PageItem
Get the set of classes this card snaps against. The item will only snap to the kinds of objects that are included in this class.- Specified by:
getClassesSnappedTo
in interfacePageItem
- Returns:
- the snap classes that determine the objects that this item will snap against
-
setClassesSnappedTo
public void setClassesSnappedTo(java.util.EnumSet<PageItem.SnapClass> snapClasses)
Description copied from interface:PageItem
Set the set of classes this card snaps against.- Specified by:
setClassesSnappedTo
in interfacePageItem
- Parameters:
snapClasses
- the snap classes that determine the objects that this item will snap against
-
getSnapTarget
public PageItem.SnapTarget getSnapTarget()
Description copied from interface:PageItem
Get the snap target rule for this item.- Specified by:
getSnapTarget
in interfacePageItem
- Returns:
- the rule describing how this object snaps to other objects
-
setSnapTarget
public void setSnapTarget(PageItem.SnapTarget target)
Description copied from interface:PageItem
Set the snap target rule for this item.- Specified by:
setSnapTarget
in interfacePageItem
- Parameters:
target
- the rule describing how this object snaps to other objects
-
getThumbnailIcon
public abstract javax.swing.Icon getThumbnailIcon()
Description copied from interface:PageItem
Returns a small representative icon for this item. The icon should beICON_SIZE
pixels wide and high.- Specified by:
getThumbnailIcon
in interfacePageItem
-
getX
public double getX()
Description copied from interface:PageItem
Returns the current x-position of this card.
-
getY
public double getY()
Description copied from interface:PageItem
Returns the current y-position of this card.
-
setX
public void setX(double x)
Description copied from interface:PageItem
Set the x-location of this item.
-
setY
public void setY(double y)
Description copied from interface:PageItem
Set the y-location of this item.
-
setLocation
public final void setLocation(double x, double y)
Description copied from interface:PageItem
Set the location of this item.- Specified by:
setLocation
in interfacePageItem
- Parameters:
x
- the new x-locationy
- the new y-location
-
setLocation
public final void setLocation(java.awt.geom.Point2D loc)
Description copied from interface:PageItem
Set the location of this item.- Specified by:
setLocation
in interfacePageItem
- Parameters:
loc
- the new location
-
getLocation
public final java.awt.geom.Point2D getLocation()
Description copied from interface:PageItem
Returns the location of this item as aPoint2D
.- Specified by:
getLocation
in interfacePageItem
- Returns:
- the location of this item on the page
-
isSelectionLocked
public boolean isSelectionLocked()
Description copied from interface:PageItem
Returnstrue
if this item is locked against selection.- Specified by:
isSelectionLocked
in interfacePageItem
- Returns:
true
if the object is locked
-
setSelectionLocked
public void setSelectionLocked(boolean lock)
Description copied from interface:PageItem
Set the state of the item's selection lock. Locked items cannot be selected or dragged.- Specified by:
setSelectionLocked
in interfacePageItem
- Parameters:
lock
- iftrue
, prevent selecting or moving the item
-
getFoldMarks
public double[] getFoldMarks()
Description copied from interface:PageItem
Return an array of the relative positions and directions of extra fold marks for this item. These fold marks are in addition to any fold marks that are generated automatically based on the juxtaposition ofCardFace
items. They are intraitem fold marks that are added along the edges of some objects. For example, foldable tome leaves always have a fold mark along their spine, which runs vertically down the centre of the face.The returned array consists of two points for each mark in (x1,y1),(x2,y2) order. (x1,y1) is a point relative to the width and height of the card, e.g. 0.5, 0 is the center of the top edge. (x2,y2) is a unit vector that indicates the direction of the line that should be drawn from the first point. (This means that the direction of the fold mark line will be the same as that of the line segment from (0,0) to (x2, y2) and that
Math.sqrt( x2*x2 + y2*y2 ) = 1
.Returns
null
if there are no extra fold marks for this sheet.- Specified by:
getFoldMarks
in interfacePageItem
- Returns:
- an array of fold mark data in the format described above, or
null
if there are no extra fold marks
-
isBleedMarginMarked
public boolean isBleedMarginMarked()
Description copied from interface:PageItem
Returnstrue
if this item should have crop marks added to it. The crop marks will be placedPageItem.getBleedMargin()
points from the ends of each edge.- Specified by:
isBleedMarginMarked
in interfacePageItem
-
getBleedMargin
public double getBleedMargin()
Description copied from interface:PageItem
Returns the bleed margin used for any automatic crop marks, in points.- Specified by:
getBleedMargin
in interfacePageItem
- Returns:
- the bleed margin for this item
-
getOrientation
public int getOrientation()
Description copied from interface:PageItem
Return an the item's current orientation. If the item does not implementFlippablePageItem
, it should always returnPageItem.ORIENT_UPRIGHT
.- Specified by:
getOrientation
in interfacePageItem
- Returns:
- the item's orientation value
-
isHorizontal
public boolean isHorizontal()
Description copied from interface:PageItem
Returnstrue
if this is in a horizontal orientation (turned 90 degrees from normal). If this is not aFlippablePageItem
, it must returnfalse
.- Specified by:
isHorizontal
in interfacePageItem
-
isVertical
public boolean isVertical()
Description copied from interface:PageItem
Returnstrue
if card is in a vertical orientation. If this is not aFlippablePageItem
, it must returntrue
.- Specified by:
isVertical
in interfacePageItem
-
isMirrored
public boolean isMirrored()
Description copied from interface:PageItem
Returnstrue
if this item is mirror-imaged. If this is not aFlippablePageItem
, it must returnfalse
.- Specified by:
isMirrored
in interfacePageItem
-
isTurned0DegreesFrom
public boolean isTurned0DegreesFrom(PageItem rhs)
Description copied from interface:PageItem
Returnstrue
if this item has the same orientation rotation as another item.- Specified by:
isTurned0DegreesFrom
in interfacePageItem
-
isTurned180DegreesFrom
public boolean isTurned180DegreesFrom(PageItem rhs)
Description copied from interface:PageItem
Returns true if this item's orientation is turned 180 degrees relative to another item.- Specified by:
isTurned180DegreesFrom
in interfacePageItem
-
isTurned90DegreesFrom
public boolean isTurned90DegreesFrom(PageItem rhs)
Description copied from interface:PageItem
Returns true if this item's orientation is turned 90 degrees relative to another item.- Specified by:
isTurned90DegreesFrom
in interfacePageItem
-
getGroup
public Group getGroup()
Description copied from interface:PageItem
Returns theGroup
that this item belongs to, ornull
.
-
setGroup
public void setGroup(Group g)
Description copied from interface:PageItem
Sets theGroup
for this item. This should not be called directly, but rather the item should be added to a group usingGroup.add(ca.cgjennings.apps.arkham.deck.item.PageItem)
.
-
hasExteriorHandles
public boolean hasExteriorHandles()
Description copied from interface:PageItem
Returnstrue
if this item has one or more drag handles that may lie outside of the item's bounding box. The editor normally only tests handles that lie within the bounding box to see if the user has pointed at them; if this method returnstrue
then the item's handles are always tested.- Specified by:
hasExteriorHandles
in interfacePageItem
- Returns:
true
if some handles may be outside the bounding box
-
itemChanging
protected void itemChanging()
Called by subclasses when the item's visual representation, location, or size is about to change. Marks the area currently covered by the item as in need of repainting.
-
itemChanged
protected void itemChanged()
Called by subclasses when the item's visual representation, location, or size changes. This method will cause the page that the item is on (if any) to be repainted, and marks the deck as having unsaved changes.
-
customizePopupMenu
public void customizePopupMenu(javax.swing.JPopupMenu menu, PageItem[] selection, boolean isSelectionFocus)
Description copied from interface:PageItem
Allows a page item the opportunity to customize the popup menu before it is displayed. When a popup menu is constructed for a page view, the items in the selection will be offered the opportunity to customize the menu. Generally, only the last item (if any) makes any changes.- Specified by:
customizePopupMenu
in interfacePageItem
- Parameters:
menu
- the menu that will be displayedselection
- the selected items; this should be considered read-onlyisSelectionFocus
- iftrue
, this is the last item in the selection
-
clone
public PageItem clone()
Description copied from interface:PageItem
Returns a new page item, using this item as a template. The new item should generally be a deep copy, not sharing any objects with the original unless those objects are immutable. The deck editor absolutely relies on this method being implemented correctly! (For example, drag-and-drop and clipboard operations use clones to create copies of existing items.)
-
putClientProperty
public void putClientProperty(java.lang.String property, java.lang.String value)
Description copied from interface:PageItem
Sets a client property on this page item. Client properties can be used by plug-ins to tag page items with plug-in specific data. Client properties are saved as part a deck save file. To delete a client property, use this method to set its value tonull
.- Specified by:
putClientProperty
in interfacePageItem
- Parameters:
property
- the property namevalue
- the value to associate with the property
-
getClientProperty
public java.lang.String getClientProperty(java.lang.String property)
Description copied from interface:PageItem
Returns the value of a client property of this page item, ornull
if the property is not defined.- Specified by:
getClientProperty
in interfacePageItem
- Parameters:
property
- the property name- Returns:
- the value associated with the property, or
null
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
writeImpl
protected void writeImpl(java.io.ObjectOutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
readImpl
protected void readImpl(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
-