public void adjustmentValueChanged(AdjustmentEvent e) {
   if (enabled) {
     view.revalidate(); // NB this is required for Windows to actually call doLayout
     view.repaint();
     DocumentPanel docpanel = getDocumentPanel();
     if (docpanel != null && !isSmoothScrolling()) {
       docpanel.raiseDocumentPanelEvent(DocumentPanelEvent.createPagePositionChanged(docpanel));
     }
   }
 }
  /**
   * @param x x coordinate in PDF units
   * @param y y coordinate in PDF units
   * @param centre if true, centre this location in the viewport, otherwise cause it to be displayed
   *     at the top left of the viewport.
   */
  private void ensureVisible(PDFPage page, double x, double y, boolean centre) {
    PDFPage oldPage = view.getPage();
    Collection<PagePanel> oldPagePanels = view.getPagePanels();
    view.setPage(page, false);
    Rectangle pageRect = view.getPageRectangle(page);

    if (pageRect != null) {
      Rectangle2D crop = PagePanel.getFullPageView(page);
      int xoffset = pageRect.x, yoffset = pageRect.y;
      if (x > crop.getMinX()) { // Also confirms !NaN
        xoffset += pointsToPixels((float) (Math.min(crop.getMaxX(), x) - crop.getMinX()));
      }
      if (y < crop.getMaxY()) { // Also confirms !NaN
        yoffset += pointsToPixels((float) (crop.getHeight() - Math.max(0, y - crop.getMinY())));
      }

      JScrollBar hsb = scrollPane.getHorizontalScrollBar();
      JScrollBar vsb = scrollPane.getVerticalScrollBar();
      if (centre) {
        xoffset -= hsb.getVisibleAmount() / 2;
        yoffset -= vsb.getVisibleAmount() / 2;
      }
      if (getPagePanel() != null && getPagePanel().getClip() != null) {
        hsb.setValue(xoffset); // Don't want to smooth scroll if we're clipping
        vsb.setValue(yoffset); // the page rectangles.
      } else {
        smoothScroll(xoffset, yoffset, hsb, vsb);
      }
    }
    if (page != oldPage) {
      DocumentPanel docpanel = getDocumentPanel();
      if (docpanel != null) {
        DocumentPanelEvent dpe = DocumentPanelEvent.createPageChanged(docpanel);
        dpe.setPreviousPage(oldPage);
        docpanel.raiseDocumentPanelEvent(dpe);
      }
      Collection<PagePanel> newPagePanels = view.getPagePanels();
      for (Iterator<PagePanel> i = oldPagePanels.iterator(); i.hasNext(); ) {
        PagePanel oldPagePanel = i.next();
        if (!newPagePanels.contains(oldPagePanel)) {
          oldPagePanel.raisePagePanelEvent(PagePanelEvent.createPageHidden(oldPagePanel, oldPage));
        }
      }
      for (Iterator<PagePanel> i = newPagePanels.iterator(); i.hasNext(); ) {
        PagePanel newPagePanel = i.next();
        if (!oldPagePanels.contains(newPagePanel)) {
          newPagePanel.raisePagePanelEvent(PagePanelEvent.createPageVisible(newPagePanel, page));
        }
      }
    }
  }