Example #1
0
 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());
             }
           });
     }
   }
 }