コード例 #1
0
        /**
         * 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.
         *
         * @param dc       the draw context which receives the picked objects.
         * @param pickRect the rectangle in AWT screen coordinates.
         * @param layer    the layer associated with the picked objects.
         */
        protected void doResolvePick(DrawContext dc, Rectangle pickRect, Layer layer)
        {
            // Get the unique pick colors in the specified screen rectangle. Use the minimum and maximum color codes to cull
            // the number of colors that the draw context must consider with identifying the unique pick colors in the
            // specified rectangle.
            int[] colorCodes = dc.getPickColorsInRectangle(pickRect, this.minAndMaxColorCodes);
            if (colorCodes == null || colorCodes.length == 0)
            {
                return;
            }

            // Lookup the pickable object (if any) for each unique color code appearing in the pick rectangle. Each picked
            // object that corresponds to a picked color is added to the draw context.
            foreach (int colorCode in colorCodes)
            {
                if (colorCode == 0) // This should never happen, but we check anyway.
                {
                    continue;
                }

                PickedObject po = this.lookupPickableObject(colorCode);
                if (po == null)
                {
                    continue;
                }

                if (layer != null)
                {
                    po.setParentLayer(layer);
                }

                dc.addObjectInPickRectangle(po);
            }
        }
コード例 #2
0
        /**
         * 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.
         * <p/>
         * If this pick point is <code>null</code>, 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 <code>null</code>, 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.
         *
         * @param dc        the draw context which receives the picked object.
         * @param pickPoint the point in AWT screen coordinates.
         * @param layer     the layer associated with the picked object.
         *
         * @return the picked object added to the draw context, or <code>null</code> if no picked object is drawn at the
         *         specified point.
         */
        public PickedObject resolvePick(DrawContext dc, Point pickPoint, Layer layer)
        {
            if (!this.hasPickableObjects()) // avoid reading the current GL color when no pickable objects are registered
            {
                return(null);
            }

            PickedObject po = null;

            // Resolve the object at the pick point, if any, adding it to the draw context's list of objects at the pick
            // point. If any object is at the pick point we return it. Note that the pick point can be null when the pick
            // rectangle is specified but the pick point is not.
            if (pickPoint != null)
            {
                po = this.doResolvePick(dc, pickPoint, layer);
            }

            // Resolve the objects in the pick rectangle, if any, adding them to the draw context's list of objects
            // intersecting the pick rectangle. Note that the pick rectangle can be null when the pick point is specified
            // but the pick rectangle is not.
            if (dc.getPickRectangle() != null && !dc.getPickRectangle().isEmpty())
            {
                this.doResolvePick(dc, dc.getPickRectangle(), layer);
            }

            this.clearPickList();

            return(po);
        }
コード例 #3
0
        public override bool Equals(Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            PickedObject that = (PickedObject)o;

            if (colorCode != that.colorCode)
            {
                return(false);
            }
            if (isOnTop != that.isOnTop)
            {
                return(false);
            }
            //noinspection RedundantIfStatement
            if (userObject != null ? !userObject.Equals(that.userObject) : that.userObject != null)
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        /**
         * 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.
         *
         * @param dc        the draw context which receives the picked object.
         * @param pickPoint the point in AWT screen coordinates.
         * @param layer     the layer associated with the picked object.
         *
         * @return the picked object added to the draw context, or <code>null</code> if no picked object is drawn at the
         *         specified point.
         */
        protected PickedObject doResolvePick(DrawContext dc, Point pickPoint, Layer layer)
        {
            PickedObject pickedObject = this.getTopObject(dc, pickPoint);

            if (pickedObject != null)
            {
                if (layer != null)
                {
                    pickedObject.setParentLayer(layer);
                }

                dc.addPickedObject(pickedObject);
            }

            return(pickedObject);
        }
コード例 #5
0
        public PickedObject getTopObject(DrawContext dc, Point pickPoint)
        {
            if (!this.hasPickableObjects()) // avoid reading the current GL color when no pickable objects are registered
            {
                return(null);
            }

            int colorCode = this.getTopColor(dc, pickPoint);

            if (colorCode == 0) // getTopColor returns 0 if the pick point selects the clear color.
            {
                return(null);
            }

            PickedObject pickedObject = this.lookupPickableObject(colorCode);

            if (pickedObject == null)
            {
                return(null);
            }

            return(pickedObject);
        }
コード例 #6
0
        protected PickedObject lookupPickableObject(int colorCode)
        {
            // Try looking up the color code in the pickable object map.
            PickedObject po = this.getPickableObjects().get(colorCode);

            if (po != null)
            {
                return(po);
            }

            // Try matching the color code to one of the pickable object ranges.
            foreach (Map.Entry <Range, PickedObjectFactory> entry in this.getPickableObjectRanges().entrySet())
            {
                Range range = entry.getKey();
                PickedObjectFactory factory = entry.getValue();

                if (range.contains(colorCode) && factory != null)
                {
                    return(factory.createPickedObject(colorCode));
                }
            }

            return(null);
        }
コード例 #7
0
 public void addPickableObject(PickedObject po)
 {
     this.getPickableObjects().put(po.getColorCode(), po);
     this.adjustExtremeColorCodes(po.getColorCode());
 }
コード例 #8
0
 /**
  * Indicates whether two picked objects refer to the same user object.
  *
  * @param a the first picked object.
  * @param b the second picked object.
  *
  * @return true if both objects are not null and they refer to the same user object, otherwise false.
  */
 public static bool areSelectionsTheSame(PickedObject a, PickedObject b)
 {
     return(a != null && b != null && a.getObject() == b.getObject());
 }