code: public static Shape mergeClip(Graphics g, Shape clip) {
          Shape oldClip = g.getClip();
          if (oldClip == null) {
              g.setClip(clip);
              return null;
          }
          Area area = new Area(oldClip);
          area.intersect(new Area(clip));// new Rectangle(0,0,width,height)));
          g.setClip(area);
          return oldClip;
      }
docs: Sets the clip on a graphics object by merging a supplied clip with the existing one. The new
  clip will be an intersection of the old clip and the supplied clip. The old clip shape will
  be returned. This is useful for resetting the old clip after an operation is performed.
  
  @param g
  the graphics object to update
  @param clip
  a new clipping region to add to the graphics clip.
  @return the current clipping region of the supplied graphics object. This may return
  {@code null} if the current clip is {@code null}.
  @throws NullPointerException
  if any parameter is {@code null}