Beispiel #1
0
  public long getParIdForGesture(long startParId, int y) {
    Paragraph startPar = lockManager.getParFromId(startParId);
    int startParY = documentPanel.getYValueFromOffset(startPar.getOffset());

    int offset = documentPanel.getOffsetFromPoint(new Point(25, startParY + y));
    return lockManager.getParFromOffset(offset).getID();
  }
 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));
        }
      }
    }
  }
Beispiel #4
0
  public synchronized void push(
      DocumentPanel documentpanel, DocumentFormatterRef documentformatterref) {
    init();
    DocumentFormatterRef documentformatterref1 = documentpanel.current;
    if (documentpanel.isLoadingNext()) documentformatterref1 = documentpanel.next;
    if (documentformatterref1 == null) return;
    Node node = new Node();
    node.target = documentpanel;
    node.newContents = new DocumentFormatterPresentation(documentformatterref);
    node.oldContents = new DocumentFormatterPresentation(documentformatterref1);
    node.extViewer = false;
    if (!(documentpanel instanceof HotJavaBrowserBean)) {
      Vector vector = new Vector();
      for (java.awt.Container container = documentpanel.getParent();
          container != null;
          container = container.getParent()) {
        if (!(container instanceof DocumentPanel)) continue;
        vector.addElement(((DocumentPanel) container).current);
        if (container instanceof HotJavaBrowserBean) break;
      }

      node.parents = new DocumentFormatterRef[vector.size()];
      for (int j = 0; j < vector.size(); j++) {
        node.parents[j] = (DocumentFormatterRef) vector.elementAt(j);
        node.parents[j].addClient();
      }
    }
    node.oldContents.setScrollPosition(documentpanel.getScrollPosition());
    node.oldContents.getFormatterRef().offsetStored = true;
    node.oldContents.getFormatterRef().getFormatter().dispatchDocumentEvent(1040, null);
    pruneCurrentToTop();
    nodes.addElement(node);
    currentPos++;
    enforceContentsThreshold(currentPos - purgeContentsThreshold);
    enforceURLThreshold(currentPos - purgeURLThreshold);
    for (int i = 0; i < nodes.size(); i++) {
      Node node1 = (Node) nodes.elementAt(i);
      if (node1.extViewer) {
        node.oldContents = node1.oldContents;
        nodes.removeElementAt(i);
        currentPos--;
      }
    }
  }
 LinearizedSupport(final DocumentPanel docpanel) {
   this.docpanel = docpanel;
   PDF pdf = docpanel.getPDF();
   supportmap = new HashMap<Integer, Support>();
   if (pdf != null) {
     int numpages = pdf.getNumberOfPages();
     for (int i = 0; i < numpages; i++) {
       LoadState state = pdf.getLoadState(i);
       if (state != null) {
         supportmap.put(Integer.valueOf(i), new Support(state));
       }
     }
     final LoadState state = pdf.getLoadState(-1);
     if (state != null) {
       supportmap.put(null, new Support(state));
       Thread t =
           new Thread() {
             public void run() {
               float oldprogress = (float) state.getBytesRemaining() / state.getBytes();
               while (state.getBytesRemaining() > 0) {
                 float progress = (float) state.getBytesRemaining() / state.getBytes();
                 if (progress != oldprogress) {
                   docpanel.firePropertyChange("loadProgress", oldprogress, progress);
                   oldprogress = progress;
                 }
                 try {
                   Thread.sleep(1000);
                 } catch (InterruptedException e) {
                 }
               }
               docpanel.firePropertyChange("loadProgress", oldprogress, 1);
             }
           };
       t.setDaemon(true);
       t.start();
     }
     pdf.addPropertyChangeListener(this);
     triggerqueue = new ArrayList<Runnable>();
   }
 }
 public void setDocumentPanel(DocumentPanel panel) {
   super.setDocumentPanel(panel);
   scrollPane.getHorizontalScrollBar().setUnitIncrement(mouseWheelUnit);
   scrollPane.getVerticalScrollBar().setUnitIncrement(mouseWheelUnit);
   PDF pdf = panel == null ? null : panel.getPDF();
   if (pdf != this.pdf) {
     view.cleanup();
     this.pdf = pdf;
     if (pdf != null) {
       SwingUtilities.invokeLater(
           new Runnable() {
             public void run() {
               PDFPage page = getDocumentPanel().getPage();
               if (page == null) {
                 page = getDocumentPanel().getPDF().getPage(0);
               }
               setPage(page, Double.NaN, Double.NaN, getZoom());
             }
           });
     }
   }
 }
Beispiel #7
0
  public synchronized void replace(
      DocumentPanel documentpanel, DocumentFormatterRef documentformatterref) {
    init();
    boolean flag = false;
    for (int i = currentPos - 1; !flag && i >= 0; i--) {
      Node node = (Node) nodes.elementAt(i);
      if (node.target == documentpanel) {
        node.newContents.flush();
        node.newContents = new DocumentFormatterPresentation(documentformatterref);
        for (i++; !flag && i < nodes.size(); i++) {
          Node node1 = (Node) nodes.elementAt(i);
          if (node1.target == documentpanel) {
            node1.oldContents.flush();
            node1.oldContents = new DocumentFormatterPresentation(documentformatterref);
            flag = true;
          }
        }

        flag = true;
      }
    }

    documentpanel.show(documentformatterref);
  }