/** Implementation note: Sorting can not be done for orphaned children. */
 public java.util.List<Figure> sort(Collection<Figure> c) {
   ensureSorted();
   ArrayList<Figure> sorted = new ArrayList<Figure>(c.size());
   for (Figure f : children) {
     if (c.contains(f)) {
       sorted.add(f);
     }
   }
   return sorted;
 }
 @Override
 public Figure findFigureInside(Point2D.Double p) {
   Collection<Figure> c = quadTree.findContains(p);
   for (Figure f : getFiguresFrontToBack()) {
     if (c.contains(f) && f.contains(p)) {
       return f.findFigureInside(p);
     }
   }
   return null;
 }
 public Figure findFigureBehind(Point2D.Double p, Collection<Figure> figures) {
   int inFrontOf = figures.size();
   for (Figure f : getFiguresFrontToBack()) {
     if (inFrontOf == 0) {
       if (f.isVisible() && f.contains(p)) {
         return f;
       }
     } else {
       if (figures.contains(f)) {
         inFrontOf--;
       }
     }
   }
   return null;
 }
 public Figure findFigure(Point2D.Double p) {
   Collection<Figure> c = quadTree.findContains(p);
   switch (c.size()) {
     case 0:
       return null;
     case 1:
       {
         Figure f = c.iterator().next();
         return (f.contains(p)) ? f : null;
       }
     default:
       {
         for (Figure f : getFiguresFrontToBack()) {
           if (c.contains(f) && f.contains(p)) return f;
         }
         return null;
       }
   }
 }
 public Figure findFigureExcept(Point2D.Double p, Collection ignore) {
   Collection<Figure> c = quadTree.findContains(p);
   switch (c.size()) {
     case 0:
       {
         return null;
       }
     case 1:
       {
         Figure f = c.iterator().next();
         return (!ignore.contains(f) || !f.contains(p)) ? null : f;
       }
     default:
       {
         for (Figure f : getFiguresFrontToBack()) {
           if (!ignore.contains(f) && f.contains(p)) return f;
         }
         return null;
       }
   }
 }