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[]dragHandlesprotected Groupgroupprotected Pageparentprotected booleanselectionLockprotected PageItem.SnapClasssnapClassprotected PageItem.SnapTargetsnapTargetprotected java.util.EnumSet<PageItem.SnapClass>snapToClassesprotected doublexOffprotected doubleyOff-
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 PageItemclone()Returns a new page item, using this item as a template.voidcustomizePopupMenu(javax.swing.JPopupMenu menu, PageItem[] selection, boolean isSelectionFocus)Allows a page item the opportunity to customize the popup menu before it is displayed.doublegetBleedMargin()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.StringgetClientProperty(java.lang.String property)Returns the value of a client property of this page item, ornullif the property is not defined.DragHandle[]getDragHandles()Returns an array of the customDragHandles for this item.double[]getFoldMarks()Return an array of the relative positions and directions of extra fold marks for this item.GroupgetGroup()Returns theGroupthat this item belongs to, ornull.abstract doublegetHeight()Return the height of this item, in points.java.awt.geom.Point2DgetLocation()Returns the location of this item as aPoint2D.intgetOrientation()Return an the item's current orientation.java.awt.ShapegetOutline()Return aShapethat corresponds to the outline of this item.PagegetPage()Return the page that owns this item, ornullif it has no parent.java.awt.geom.Rectangle2D.DoublegetRectangle()Return a rectangle of the bounds of this item.PageItem.SnapClassgetSnapClass()Get the class this item counts as for snapping.PageItem.SnapTargetgetSnapTarget()Get the snap target rule for this item.abstract javax.swing.IcongetThumbnailIcon()Returns a small representative icon for this item.abstract doublegetWidth()Return the width of this item, in points.doublegetX()Returns the current x-position of this card.doublegetY()Returns the current y-position of this card.booleanhasExteriorHandles()Returnstrueif this item has one or more drag handles that may lie outside of the item's bounding box.booleanhitTest(java.awt.geom.Point2D p)Returnstrueifpointis inside the visible bounds of this object.booleanisBleedMarginMarked()Returnstrueif this item should have crop marks added to it.booleanisHorizontal()Returnstrueif this is in a horizontal orientation (turned 90 degrees from normal).booleanisMirrored()Returnstrueif this item is mirror-imaged.booleanisSelectionLocked()Returnstrueif this item is locked against selection.booleanisTurned0DegreesFrom(PageItem rhs)Returnstrueif this item has the same orientation rotation as another item.booleanisTurned180DegreesFrom(PageItem rhs)Returns true if this item's orientation is turned 180 degrees relative to another item.booleanisTurned90DegreesFrom(PageItem rhs)Returns true if this item's orientation is turned 90 degrees relative to another item.booleanisVertical()Returnstrueif card is in a vertical orientation.protected voiditemChanged()Called by subclasses when the item's visual representation, location, or size changes.protected voiditemChanging()Called by subclasses when the item's visual representation, location, or size is about to change.abstract voidpaint(java.awt.Graphics2D g, RenderTarget target, double renderResolutionHint)Paint this item at its current location.voidprepareToPaint(RenderTarget target, double renderResolutionHint)Update any cached representations needed to paint this item at the specified settings.voidputClientProperty(java.lang.String property, java.lang.String value)Sets a client property on this page item.protected voidreadImpl(java.io.ObjectInputStream in)voidsetClassesSnappedTo(java.util.EnumSet<PageItem.SnapClass> snapClasses)Set the set of classes this card snaps against.voidsetGroup(Group g)Sets theGroupfor this item.voidsetLocation(double x, double y)Set the location of this item.voidsetLocation(java.awt.geom.Point2D loc)Set the location of this item.voidsetPage(Page parent)Set the page which is the parent of this card, ornullto clear its parent.voidsetSelectionLocked(boolean lock)Set the state of the item's selection lock.voidsetSnapClass(PageItem.SnapClass snapClass)Set the class this item counts as for snapping.voidsetSnapTarget(PageItem.SnapTarget target)Set the snap target rule for this item.voidsetX(double x)Set the x-location of this item.voidsetY(double y)Set the y-location of this item.java.lang.StringtoString()protected voidwriteImpl(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:PageItemPaint 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:PageItemUpdate 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
PageItemdoes not require rendering to a buffer, then this method may do nothing.- Specified by:
prepareToPaintin 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:PageItemReturn the width of this item, in points.
-
getHeight
public abstract double getHeight()
Description copied from interface:PageItemReturn the height of this item, in points.
-
setPage
public void setPage(Page parent)
Description copied from interface:PageItemSet the page which is the parent of this card, ornullto clear its parent. ThePageclass will set the parent automatically when a card is added or removed from it.
-
getPage
public Page getPage()
Description copied from interface:PageItemReturn the page that owns this item, ornullif it has no parent.
-
getRectangle
public java.awt.geom.Rectangle2D.Double getRectangle()
Description copied from interface:PageItemReturn a rectangle of the bounds of this item.- Specified by:
getRectanglein interfacePageItem- Returns:
- a bounding rectangle for the item
-
getOutline
public java.awt.Shape getOutline()
Description copied from interface:PageItemReturn aShapethat 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:
getOutlinein interfacePageItem- Returns:
- the outline of this object
-
hitTest
public boolean hitTest(java.awt.geom.Point2D p)
Description copied from interface:PageItemReturnstrueifpointis inside the visible bounds of this object.
-
getDragHandles
public DragHandle[] getDragHandles()
Returns an array of the customDragHandles 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
dragHandlesfield 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:
getDragHandlesin 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:PageItemGet the class this item counts as for snapping.- Specified by:
getSnapClassin interfacePageItem- Returns:
- the snap class of this item
-
setSnapClass
public void setSnapClass(PageItem.SnapClass snapClass)
Description copied from interface:PageItemSet the class this item counts as for snapping.- Specified by:
setSnapClassin interfacePageItem- Parameters:
snapClass- the new snap class for this item
-
getClassesSnappedTo
public java.util.EnumSet<PageItem.SnapClass> getClassesSnappedTo()
Description copied from interface:PageItemGet 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:
getClassesSnappedToin 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:PageItemSet the set of classes this card snaps against.- Specified by:
setClassesSnappedToin 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:PageItemGet the snap target rule for this item.- Specified by:
getSnapTargetin interfacePageItem- Returns:
- the rule describing how this object snaps to other objects
-
setSnapTarget
public void setSnapTarget(PageItem.SnapTarget target)
Description copied from interface:PageItemSet the snap target rule for this item.- Specified by:
setSnapTargetin interfacePageItem- Parameters:
target- the rule describing how this object snaps to other objects
-
getThumbnailIcon
public abstract javax.swing.Icon getThumbnailIcon()
Description copied from interface:PageItemReturns a small representative icon for this item. The icon should beICON_SIZEpixels wide and high.- Specified by:
getThumbnailIconin interfacePageItem
-
getX
public double getX()
Description copied from interface:PageItemReturns the current x-position of this card.
-
getY
public double getY()
Description copied from interface:PageItemReturns the current y-position of this card.
-
setX
public void setX(double x)
Description copied from interface:PageItemSet the x-location of this item.
-
setY
public void setY(double y)
Description copied from interface:PageItemSet the y-location of this item.
-
setLocation
public final void setLocation(double x, double y)Description copied from interface:PageItemSet the location of this item.- Specified by:
setLocationin 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:PageItemSet the location of this item.- Specified by:
setLocationin interfacePageItem- Parameters:
loc- the new location
-
getLocation
public final java.awt.geom.Point2D getLocation()
Description copied from interface:PageItemReturns the location of this item as aPoint2D.- Specified by:
getLocationin interfacePageItem- Returns:
- the location of this item on the page
-
isSelectionLocked
public boolean isSelectionLocked()
Description copied from interface:PageItemReturnstrueif this item is locked against selection.- Specified by:
isSelectionLockedin interfacePageItem- Returns:
trueif the object is locked
-
setSelectionLocked
public void setSelectionLocked(boolean lock)
Description copied from interface:PageItemSet the state of the item's selection lock. Locked items cannot be selected or dragged.- Specified by:
setSelectionLockedin interfacePageItem- Parameters:
lock- iftrue, prevent selecting or moving the item
-
getFoldMarks
public double[] getFoldMarks()
Description copied from interface:PageItemReturn 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 ofCardFaceitems. 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
nullif there are no extra fold marks for this sheet.- Specified by:
getFoldMarksin interfacePageItem- Returns:
- an array of fold mark data in the format described above, or
nullif there are no extra fold marks
-
isBleedMarginMarked
public boolean isBleedMarginMarked()
Description copied from interface:PageItemReturnstrueif 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:
isBleedMarginMarkedin interfacePageItem
-
getBleedMargin
public double getBleedMargin()
Description copied from interface:PageItemReturns the bleed margin used for any automatic crop marks, in points.- Specified by:
getBleedMarginin interfacePageItem- Returns:
- the bleed margin for this item
-
getOrientation
public int getOrientation()
Description copied from interface:PageItemReturn an the item's current orientation. If the item does not implementFlippablePageItem, it should always returnPageItem.ORIENT_UPRIGHT.- Specified by:
getOrientationin interfacePageItem- Returns:
- the item's orientation value
-
isHorizontal
public boolean isHorizontal()
Description copied from interface:PageItemReturnstrueif this is in a horizontal orientation (turned 90 degrees from normal). If this is not aFlippablePageItem, it must returnfalse.- Specified by:
isHorizontalin interfacePageItem
-
isVertical
public boolean isVertical()
Description copied from interface:PageItemReturnstrueif card is in a vertical orientation. If this is not aFlippablePageItem, it must returntrue.- Specified by:
isVerticalin interfacePageItem
-
isMirrored
public boolean isMirrored()
Description copied from interface:PageItemReturnstrueif this item is mirror-imaged. If this is not aFlippablePageItem, it must returnfalse.- Specified by:
isMirroredin interfacePageItem
-
isTurned0DegreesFrom
public boolean isTurned0DegreesFrom(PageItem rhs)
Description copied from interface:PageItemReturnstrueif this item has the same orientation rotation as another item.- Specified by:
isTurned0DegreesFromin interfacePageItem
-
isTurned180DegreesFrom
public boolean isTurned180DegreesFrom(PageItem rhs)
Description copied from interface:PageItemReturns true if this item's orientation is turned 180 degrees relative to another item.- Specified by:
isTurned180DegreesFromin interfacePageItem
-
isTurned90DegreesFrom
public boolean isTurned90DegreesFrom(PageItem rhs)
Description copied from interface:PageItemReturns true if this item's orientation is turned 90 degrees relative to another item.- Specified by:
isTurned90DegreesFromin interfacePageItem
-
getGroup
public Group getGroup()
Description copied from interface:PageItemReturns theGroupthat this item belongs to, ornull.
-
setGroup
public void setGroup(Group g)
Description copied from interface:PageItemSets theGroupfor 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:PageItemReturnstrueif 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 returnstruethen the item's handles are always tested.- Specified by:
hasExteriorHandlesin interfacePageItem- Returns:
trueif 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:PageItemAllows 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:
customizePopupMenuin 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:PageItemReturns 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:PageItemSets 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:
putClientPropertyin 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:PageItemReturns the value of a client property of this page item, ornullif the property is not defined.- Specified by:
getClientPropertyin interfacePageItem- Parameters:
property- the property name- Returns:
- the value associated with the property, or
null
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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.IOExceptionjava.lang.ClassNotFoundException
-
-