/** * 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. * * @param colorCode the first color code associated with the range of sequential color codes. * @param count the number of sequential color codes in the range of sequential color codes. * @param factory the PickedObjectFactory to use when creating a PickedObject for a color in the specified range. */ public void addPickableObjectRange(int colorCode, int count, PickedObjectFactory factory) { Range range = new Range(colorCode, count); this.pickableObjectRanges.put(range, factory); this.adjustExtremeColorCodes(colorCode); this.adjustExtremeColorCodes(colorCode + count - 1); // max code is last element in sequence of count codes }
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); }