code: @Override
      public Rectangle shift(Rectangle screenBounds, Rectangle diagramBounds) {
          int screenMaxX = screenBounds.x + screenBounds.width;
          int screenMaxY = screenBounds.y + screenBounds.height;
          int diagramMaxX = diagramBounds.x + diagramBounds.width;
          int diagramMaxY = diagramBounds.y + diagramBounds.height;
  
          int leftOverlap = screenBounds.x - diagramBounds.x;
          int rightOverlap = diagramMaxX - screenMaxX;
          int topOverlap = screenBounds.y - diagramBounds.y;
          int bottomOverlap = diagramMaxY - screenMaxY;
  
          int diffx = 0;
          int diffy = 0;
          int width = screenBounds.width;
          int height = screenBounds.height;
  
          if (leftOverlap > 0) {
              diffx = leftOverlap;
          }
  
          if (rightOverlap > 0) {
              width += rightOverlap;
          }
  
          if (topOverlap > 0) {
              diffy = topOverlap;
          }
  
          if (bottomOverlap > 0) {
              height += bottomOverlap;
          }
  
          if (diffx != 0 || diffy != 0) {
              this.shiftDrawCenter(diffx, diffy);
          }
  
          return new Rectangle(diffx, diffy, width, height);
      }
docs: Determine the overlap of the diagram with the screen, and shift (if
  necessary) the diagram draw center. It returns a rectangle only because
  that is a convenient class to hold the four parameters calculated, but it
  is not a rectangle representing an area...
  
  @param screenBounds
  the bounds of the screen
  @param diagramBounds
  the bounds of the diagram
  @return the shape that the screen should be