Exemplo n.º 1
0
  public CurrentPageChanger(
      JScrollPane scrollpane,
      AbstractDocumentView documentView,
      List<AbstractPageViewComponent> pageComponents,
      boolean addWheelMouseListener) {

    this.pageComponents = pageComponents;
    this.scrollpane = scrollpane;
    this.documentView = documentView;
    documentViewModel = documentView.getViewModel();

    // listen for scroll bar manaipulators
    this.documentView.addMouseListener(this);
    this.scrollpane.getHorizontalScrollBar().addAdjustmentListener(this);
    this.scrollpane.getHorizontalScrollBar().addMouseListener(this);

    this.scrollpane.getVerticalScrollBar().addAdjustmentListener(this);
    this.scrollpane.getVerticalScrollBar().addMouseListener(this);

    //        addMouseListenerToAnyButtonsIn(scrollpane.getHorizontalScrollBar());
    //        addMouseListenerToAnyButtonsIn(scrollpane.getVerticalScrollBar());

    // load wheel mouse listener
    mouseWheelCurrentPageListener = MouseWheelCurrentPageListener.install(scrollpane, this);
  }
Exemplo n.º 2
0
 public void paintComponent(Graphics g) {
   Rectangle clipBounds = g.getClipBounds();
   // paint background gray
   g.setColor(backgroundColor);
   g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
   // paint selection box
   super.paintComponent(g);
 }
Exemplo n.º 3
0
  public void calculateCurrentPage() {
    if (pageComponents != null) {
      Rectangle viewport = scrollpane.getViewport().getViewRect();
      // find visible pages
      ArrayList<PageViewComponent> visiblePages = new ArrayList<PageViewComponent>(10);
      Rectangle pageBounds;
      int pageCount = 0;
      for (AbstractPageViewComponent pageComponent : pageComponents) {
        if (pageComponent != null) {
          pageBounds = documentViewModel.getPageBounds(pageCount);
          if (pageBounds != null && pageComponent.isShowing()) {
            visiblePages.add(pageComponent);
          }
        }
        pageCount++;
      }

      // find center point of view port
      int x = viewport.x + (viewport.width / 2);
      int y = viewport.y + (viewport.height / 2);
      Point centerView = new Point(x, y);

      // find out which page center is closest to center and thus the new current page
      double minLength = Double.MAX_VALUE;
      int minPage = -1;
      double tmpDistance;

      for (PageViewComponent pageComponent : visiblePages) {
        if (pageComponent != null) {
          pageBounds = documentViewModel.getPageBounds(pageComponent.getPageIndex());
          x = pageBounds.x + (pageBounds.width / 2);
          y = pageBounds.y + (pageBounds.height / 2);
          // find minimum page.
          tmpDistance = centerView.distance(x, y);
          if (tmpDistance < minLength) {
            minLength = tmpDistance;
            minPage = pageComponent.getPageIndex();
          }
        }
      }

      // clean up
      visiblePages.clear();
      visiblePages.trimToSize();

      // finally send out event to update page number
      int oldCurrentPage = documentViewModel.getViewCurrentPageIndex();
      documentViewModel.setViewCurrentPageIndex(minPage);
      DocumentViewControllerImpl documentViewController =
          (DocumentViewControllerImpl) documentView.getParentViewController();
      documentViewController.firePropertyChange(
          PropertyConstants.DOCUMENT_CURRENT_PAGE, oldCurrentPage, minPage);
    }
  }
Exemplo n.º 4
0
  public void dispose() {
    // remove standard mouse listeners
    documentView.removeMouseListener(this);
    scrollpane.getHorizontalScrollBar().removeAdjustmentListener(this);
    scrollpane.getHorizontalScrollBar().removeMouseListener(this);
    scrollpane.getVerticalScrollBar().removeAdjustmentListener(this);
    scrollpane.getVerticalScrollBar().removeMouseListener(this);

    // Remove wheel mouse listener
    MouseWheelCurrentPageListener.uninstall(scrollpane, mouseWheelCurrentPageListener);
  }
Exemplo n.º 5
0
  public void dispose() {
    disposing = true;
    // remove utilities
    if (currentPageChanger != null) {
      currentPageChanger.dispose();
    }
    if (keyListenerPageChanger != null) {
      keyListenerPageChanger.uninstall();
    }

    // trigger a re-layout
    pagesPanel.removeAll();
    pagesPanel.invalidate();

    // make sure we call super.
    super.dispose();
  }