Class PickSupport

    • Field Detail

      • pickableObjects

        protected java.util.Map<java.lang.Integer,​PickedObject> pickableObjects
        The picked objects currently registered with this PickSupport, represented as a map of color codes to picked objects. This maps provides constant time access to a picked object when its color code is known.
      • pickableObjectRanges

        protected java.util.Map<Range,​PickedObjectFactory> pickableObjectRanges
        The picked object color code ranges currently registered with this PickSupport, represented as a map of color code ranges to picked object factories. PickSupport uses these factories to delay PickedObject construction until a matching pick color is identified.
      • minAndMaxColorCodes

        protected int[] minAndMaxColorCodes
        Indicates the minimum and maximum color code associated with the picked objects in the pickableObjects map. Initially null, indicating that the minimum and maximum color codes are unknown.
    • Constructor Detail

      • PickSupport

        public PickSupport()
    • Method Detail

      • clearPickList

        public void clearPickList()
      • addPickableObject

        public void addPickableObject​(int colorCode,
                                      java.lang.Object o,
                                      Position position,
                                      boolean isTerrain)
      • addPickableObject

        public void addPickableObject​(int colorCode,
                                      java.lang.Object o,
                                      Position position)
      • addPickableObject

        public void addPickableObject​(int colorCode,
                                      java.lang.Object o)
      • addPickableObject

        public void addPickableObject​(PickedObject po)
      • addPickableObjectRange

        public void addPickableObjectRange​(int colorCode,
                                           int count,
                                           PickedObjectFactory factory)
        Associates a collection of picked objects with a range of pick colors. PickSupport uses the factory to delay PickedObject construction until a matching pick color is identified by getTopObject or resolvePick. This eliminates the overhead of creating and managing a large collection of PickedObject instances when only a few may actually be picked.
        Parameters:
        colorCode - the first color code associated with the range of sequential color codes.
        count - the number of sequential color codes in the range of sequential color codes.
        factory - the PickedObjectFactory to use when creating a PickedObject for a color in the specified range.
      • resolvePick

        public PickedObject resolvePick​(DrawContext dc,
                                        java.awt.Point pickPoint,
                                        Layer layer)
        Adds picked object registered with this PickSupport that are drawn at the specified pick point or intersect the draw context's pick rectangle to the draw context's list of picked objects. This clears any registered picked objects upon returning.

        If this pick point is null, this ignores the pick point and does not attempt to determine which picked objects are drawn there. If the draw context's pick rectangle is null, this ignores the pick rectangle and does not attempt to determine which picked objects intersect it. This does nothing if no picked objects are currently registered with this PickSupport.

        Parameters:
        dc - the draw context which receives the picked object.
        pickPoint - the point in AWT screen coordinates.
        layer - the layer associated with the picked object.
        Returns:
        the picked object added to the draw context, or null if no picked object is drawn at the specified point.
      • doResolvePick

        protected PickedObject doResolvePick​(DrawContext dc,
                                             java.awt.Point pickPoint,
                                             Layer layer)
        Adds a picked object registered with this PickSupport that is drawn at the specified point in AWT screen coordinates (if one exists) to the draw context's list of picked objects.
        Parameters:
        dc - the draw context which receives the picked object.
        pickPoint - the point in AWT screen coordinates.
        layer - the layer associated with the picked object.
        Returns:
        the picked object added to the draw context, or null if no picked object is drawn at the specified point.
      • doResolvePick

        protected void doResolvePick​(DrawContext dc,
                                     java.awt.Rectangle pickRect,
                                     Layer layer)
        Adds all picked objects that are registered with this PickSupport and intersect the specified rectangle in AWT screen coordinates (if any) to the draw context's list of picked objects.
        Parameters:
        dc - the draw context which receives the picked objects.
        pickRect - the rectangle in AWT screen coordinates.
        layer - the layer associated with the picked objects.
      • getTopColor

        public int getTopColor​(DrawContext dc,
                               java.awt.Point pickPoint)
        Returns the framebuffer RGB color for a point in AWT screen coordinates, formatted as a pick color code. The red, green, and blue components are each stored as an 8-bit unsigned integer, and packed into bits 0-23 of the returned integer as follows: bits 16-23 are red, bits 8-15 are green, and bits 0-7 are blue. This format is consistent with the RGB integers used to create the pick colors.

        This returns 0 if the point is null, if the point contains the clear color, or if the point is outside the draw context's drawable area.

        Parameters:
        dc - the draw context to return a color for.
        pickPoint - the point to return a color for, in AWT screen coordinates.
        Returns:
        the RGB color corresponding to the specified point.
      • beginPicking

        public void beginPicking​(DrawContext dc)
      • endPicking

        public void endPicking​(DrawContext dc)
      • getPickableObjects

        protected java.util.Map<java.lang.Integer,​PickedObject> getPickableObjects()
      • hasPickableObjects

        protected boolean hasPickableObjects()
      • lookupPickableObject

        protected PickedObject lookupPickableObject​(int colorCode)
      • adjustExtremeColorCodes

        protected void adjustExtremeColorCodes​(int colorCode)
        Adjust this PickSupport's minimum and maximum color codes by decreasing and increasing each extreme, respectively, according to the specified code. If the minimum and maximum color codes are unknown, both the minimum and maximum color codes are set to the specified code.
        Parameters:
        colorCode - the code used to adjust the current min and max codes.
      • areSelectionsTheSame

        public static boolean areSelectionsTheSame​(PickedObject a,
                                                   PickedObject b)
        Indicates whether two picked objects refer to the same user object.
        Parameters:
        a - the first picked object.
        b - the second picked object.
        Returns:
        true if both objects are not null and they refer to the same user object, otherwise false.