Class 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
    • Constructor Detail

      • AbstractItem

        public AbstractItem()
    • 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.
        Specified by:
        paint in interface PageItem
        Parameters:
        g - the graphics context to paint to
        target - the type of destination being drawn to
        renderResolutionHint - a source resolution hint
      • getWidth

        public abstract double getWidth()
        Description copied from interface: PageItem
        Return the width of this item, in points.
        Specified by:
        getWidth in interface PageItem
        Returns:
        the item's width
      • getHeight

        public abstract double getHeight()
        Description copied from interface: PageItem
        Return the height of this item, in points.
        Specified by:
        getHeight in interface PageItem
        Returns:
        the item's height
      • setPage

        public void setPage​(Page parent)
        Description copied from interface: PageItem
        Set the page which is the parent of this card, or null to clear its parent. The Page class will set the parent automatically when a card is added or removed from it.
        Specified by:
        setPage in interface PageItem
      • getPage

        public Page getPage()
        Description copied from interface: PageItem
        Return the page that owns this item, or null if it has no parent.
        Specified by:
        getPage in interface PageItem
        Returns:
        the page that this item is on
      • 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 interface PageItem
        Returns:
        a bounding rectangle for the item
      • getOutline

        public java.awt.Shape getOutline()
        Description copied from interface: PageItem
        Return a Shape that corresponds to the outline of this item. In the simplest case, this can return the same result as PageItem.getRectangle(). If precise geometry is available for the item, then this should return a more accurate bounding shape.
        Specified by:
        getOutline in interface PageItem
        Returns:
        the outline of this object
      • hitTest

        public boolean hitTest​(java.awt.geom.Point2D p)
        Description copied from interface: PageItem
        Returns true if point is inside the visible bounds of this object.
        Specified by:
        hitTest in interface PageItem
        Parameters:
        p - a point in document coordinates (points from the upper-left corner of the page)
        Returns:
        true if the point lies inside the bounds of the object
      • getDragHandles

        public DragHandle[] getDragHandles()
        Returns an array of the custom DragHandles for this item. If the item has no handles, returns null.

        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 interface PageItem
        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 interface PageItem
        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 interface PageItem
        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 interface PageItem
        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 interface PageItem
        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 interface PageItem
        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 interface PageItem
        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 be ICON_SIZE pixels wide and high.
        Specified by:
        getThumbnailIcon in interface PageItem
      • getX

        public double getX()
        Description copied from interface: PageItem
        Returns the current x-position of this card.
        Specified by:
        getX in interface PageItem
      • getY

        public double getY()
        Description copied from interface: PageItem
        Returns the current y-position of this card.
        Specified by:
        getY in interface PageItem
      • setX

        public void setX​(double x)
        Description copied from interface: PageItem
        Set the x-location of this item.
        Specified by:
        setX in interface PageItem
        Parameters:
        x - the new x-location
      • setY

        public void setY​(double y)
        Description copied from interface: PageItem
        Set the y-location of this item.
        Specified by:
        setY in interface PageItem
        Parameters:
        y - the new y-location
      • setLocation

        public final void setLocation​(double x,
                                      double y)
        Description copied from interface: PageItem
        Set the location of this item.
        Specified by:
        setLocation in interface PageItem
        Parameters:
        x - the new x-location
        y - 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 interface PageItem
        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 a Point2D.
        Specified by:
        getLocation in interface PageItem
        Returns:
        the location of this item on the page
      • isSelectionLocked

        public boolean isSelectionLocked()
        Description copied from interface: PageItem
        Returns true if this item is locked against selection.
        Specified by:
        isSelectionLocked in interface PageItem
        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 interface PageItem
        Parameters:
        lock - if true, 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 of CardFace 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 interface PageItem
        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
        Returns true if this item should have crop marks added to it. The crop marks will be placed PageItem.getBleedMargin() points from the ends of each edge.
        Specified by:
        isBleedMarginMarked in interface PageItem
      • 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 interface PageItem
        Returns:
        the bleed margin for this item
      • isHorizontal

        public boolean isHorizontal()
        Description copied from interface: PageItem
        Returns true if this is in a horizontal orientation (turned 90 degrees from normal). If this is not a FlippablePageItem, it must return false.
        Specified by:
        isHorizontal in interface PageItem
      • isVertical

        public boolean isVertical()
        Description copied from interface: PageItem
        Returns true if card is in a vertical orientation. If this is not a FlippablePageItem, it must return true.
        Specified by:
        isVertical in interface PageItem
      • isMirrored

        public boolean isMirrored()
        Description copied from interface: PageItem
        Returns true if this item is mirror-imaged. If this is not a FlippablePageItem, it must return false.
        Specified by:
        isMirrored in interface PageItem
      • isTurned0DegreesFrom

        public boolean isTurned0DegreesFrom​(PageItem rhs)
        Description copied from interface: PageItem
        Returns true if this item has the same orientation rotation as another item.
        Specified by:
        isTurned0DegreesFrom in interface PageItem
      • 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 interface PageItem
      • 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 interface PageItem
      • getGroup

        public Group getGroup()
        Description copied from interface: PageItem
        Returns the Group that this item belongs to, or null.
        Specified by:
        getGroup in interface PageItem
        Returns:
        the group the object is in, or null if it isn't in a group
      • hasExteriorHandles

        public boolean hasExteriorHandles()
        Description copied from interface: PageItem
        Returns true 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 returns true then the item's handles are always tested.
        Specified by:
        hasExteriorHandles in interface PageItem
        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 interface PageItem
        Parameters:
        menu - the menu that will be displayed
        selection - the selected items; this should be considered read-only
        isSelectionFocus - if true, 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.)
        Specified by:
        clone in interface PageItem
        Overrides:
        clone in class java.lang.Object
        Returns:
        a new copy of this page item
      • 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 to null.
        Specified by:
        putClientProperty in interface PageItem
        Parameters:
        property - the property name
        value - 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, or null if the property is not defined.
        Specified by:
        getClientProperty in interface PageItem
        Parameters:
        property - the property name
        Returns:
        the value associated with the property, or null
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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