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 propertyChange(PropertyChangeEvent event) { String name = event.getPropertyName(); Object source = event.getSource(); boolean relayout = false; List<PDFPage> pages = pdf.getPages(); if (name.equals("pages") && source == pdf) { relayout = true; } else if ((name.endsWith("Box") || name.equals("orientation")) && source instanceof PDFPage) { relayout = true; } if (relayout) { int num = view.getPageNumber(); if (num >= pages.size()) { num = pages.size() - 1; } PDFPage page = pages.get(num); view.setPage(page, true); smoothScroll(0, 0, null, null); } }
public float getTargetZoom(int zoommode, PDFPage page) { float outzoom = zoom; if (page != null) { int pagenumber = page.getPageNumber() - 1; int pagecount = pdf.getNumberOfPages(); boolean isOdd = (pagenumber % 2) == 0; // even pages have odd numbers :) boolean onRight = handedness == ODD_PAGES_ON_RIGHT ? isOdd : !isOdd; PDFPage leftPage, rightPage; Rectangle2D.Float leftPageRect = null, rightPageRect = null; if (onRight) { leftPage = (pagenumber > 0) ? pdf.getPage(pagenumber - 1) : null; rightPage = page; } else { leftPage = page; rightPage = (pagenumber < (pagecount - 1)) ? pdf.getPage(pagenumber + 1) : null; } if (leftPage != null) { leftPageRect = (Rectangle2D.Float) PagePanel.getFullPageView(leftPage); } if (rightPage != null) { rightPageRect = (Rectangle2D.Float) PagePanel.getFullPageView(rightPage); } if (leftPageRect == null) { leftPageRect = (Rectangle2D.Float) rightPageRect.clone(); } if (rightPageRect == null) { rightPageRect = (Rectangle2D.Float) leftPageRect.clone(); } JScrollBar hsb = scrollPane.getHorizontalScrollBar(); JScrollBar vsb = scrollPane.getVerticalScrollBar(); float prw = leftPageRect.width + rightPageRect.width; float prh = Math.max(leftPageRect.height, rightPageRect.height); Dimension size = getSize(); float w = (float) Math.ceil(prw * Util.getScreenResolution(this) / 72) + (margin * 4) + interpagemargin + vsb.getWidth(); float h = (float) Math.ceil(prh * Util.getScreenResolution(this) / 72) + (margin * 2) + hsb.getHeight(); switch (zoommode) { case ZOOM_FITWIDTH: outzoom = (float) size.width / w; break; case ZOOM_FITHEIGHT: outzoom = (float) size.height / h; break; case ZOOM_FIT: float zw = (float) size.width / w; float zh = (float) size.height / h; outzoom = zw < zh ? zw : zh; break; default: outzoom = zoom == 0 ? 1 : zoom; } } return outzoom; }