Class PDFViewer

All Implemented Interfaces:
PageChangeListener, KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, TreeSelectionListener, RootPaneContainer, WindowConstants

public class PDFViewer extends JFrame implements KeyListener, TreeSelectionListener, PageChangeListener
A demo PDF Viewer application.
See Also:
  • Field Details

  • Constructor Details

    • PDFViewer

      public PDFViewer(boolean useThumbs)
      Create a new PDFViewer based on a user, with or without a thumbnail panel.
      Parameters:
      useThumbs - true if the thumb panel should exist, false if not.
  • Method Details

    • getIcon

      public Icon getIcon(String name)
      utility method to get an icon from the resources of this class
      Parameters:
      name - the name of the icon
      Returns:
      the icon, or null if the icon wasn't found.
    • init

      protected void init()
      Initialize this PDFViewer by creating the GUI.
    • gotoPage

      public void gotoPage(int pagenum)
      Changes the displayed page, desyncing if we're not on the same page as a presenter.
      Specified by:
      gotoPage in interface PageChangeListener
      Parameters:
      pagenum - the page to display
    • forceGotoPage

      public void forceGotoPage(int pagenum)
      Changes the displayed page.
      Parameters:
      pagenum - the page to display
    • setEnabling

      public void setEnabling()
      Enable or disable all of the actions based on the current state.
    • openFile

      public void openFile(URL url) throws IOException
      open a URL to a PDF file. The file is read in and processed with an in-memory buffer.
      Parameters:
      url -
      Throws:
      IOException
    • openFile

      public void openFile(File file) throws IOException

      Open a specific pdf file. Creates a DocumentInfo from the file, and opens that.

      Note: Mapping the file locks the file until the PDFFile is closed.

      Parameters:
      file - the file to open
      Throws:
      IOException
    • openFileUnMapped

      public void openFileUnMapped(File file) throws IOException

      Open a specific pdf file. Creates a DocumentInfo from the file, and opens that.

      Note: By not memory mapping the file its contents are not locked down while PDFFile is open.

      Parameters:
      file - the file to open
      Throws:
      IOException
    • openError

      public void openError(String message)
      Display a dialog indicating an error.
    • doOpen

      public void doOpen()
      Ask the user for a PDF file to open from the local file system
    • doOpen

      public void doOpen(String name)
      Open a local file, given a string filename
      Parameters:
      name - the name of the file to open
    • doPageSetup

      public void doPageSetup()
      Posts the Page Setup dialog
    • doPrint

      public void doPrint()
      Print the current document.
    • doClose

      public void doClose()
      Close the current document.
    • doQuit

      public void doQuit()
      Shuts down all known threads. This ought to cause the JVM to quit if the PDFViewer is the only application running.
    • doZoomTool

      public void doZoomTool()
      Turns on zooming
    • doFitInWindow

      public void doFitInWindow()
      Turns off zooming; makes the page fit in the window
    • doThumbs

      public void doThumbs(boolean show)
      Shows or hides the thumbnails by moving the split pane divider
    • doFullScreen

      public void doFullScreen(boolean force)
      Enter full screen mode
      Parameters:
      force - true if the user should be prompted for a screen to use in a multiple-monitor setup. If false, the user will only be prompted once.
    • doZoom

      public void doZoom(double factor)
    • doNext

      public void doNext()
      Goes to the next page
    • doPrev

      public void doPrev()
      Goes to the previous page
    • doFirst

      public void doFirst()
      Goes to the first page
    • doLast

      public void doLast()
      Goes to the last page
    • doPageTyped

      public void doPageTyped()
      Goes to the page that was typed in the page number text field
    • setFullScreenMode

      public void setFullScreenMode(boolean full, boolean force)
      Starts or ends full screen mode.
      Parameters:
      full - true to enter full screen mode, false to leave
      force - true if the user should be prompted for a screen to use the second time full screen mode is entered.
    • main

      public static void main(String[] args)
    • keyPressed

      public void keyPressed(KeyEvent evt)
      Handle a key press for navigation
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent evt)
      Specified by:
      keyReleased in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent evt)
      gets key presses and tries to build a page if they're numeric
      Specified by:
      keyTyped in interface KeyListener
    • valueChanged

      public void valueChanged(TreeSelectionEvent e)
      Someone changed the selection of the outline tree. Go to the new page.
      Specified by:
      valueChanged in interface TreeSelectionListener