Class PDFReaderPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class PDFReaderPanel extends JPanel
PDFReaderUtilityPanel is a reusable Swing JPanel component for viewing and navigating PDF documents.

This utility leverages the Apache PDFBox library to render each page of a PDF document as an image. Users can scroll through pages and use zoom controls (zoom in, zoom out, and reset zoom) to adjust the viewing scale. All rendering and file I/O operations that might block the Event Dispatch Thread are performed asynchronously using SwingWorker, ensuring UI responsiveness even for large documents.

Features

  • Open and display multipage PDF files in a dedicated panel
  • Render each page as a Swing image component for fast display and scrolling
  • Zoom in and out with predefined DPI steps and boundaries
  • Reset zoom to the default DPI value
  • Progress dialog for time-consuming operations
  • Thread-safe UI updates using SwingWorker
  • Automatic resource cleanup

Typical usage:

PDFReaderUtilityPanel pdfViewer = new PDFReaderUtilityPanel(ownerWindow, "/path/to/File.pdf");
Since:
0.50.07
See Also:
  • Constructor Details

    • PDFReaderPanel

      public PDFReaderPanel(Window ownerWindow, String pdfPath)
      Constructs and initializes a JPanel for viewing a PDF file.

      The panel is initialized with zoom controls and begins rendering the pages of the provided PDF document path. Operations that may block the UI, such as rendering or file IO, are performed off the Event Dispatch Thread. The panel can be embedded inside dialogs, frames, or other containers.

      Parameters:
      ownerWindow - the owner Window for dialogs (can be null)
      pdfPath - file system path of the PDF document to display
      Since:
      0.50.07
  • Method Details

    • getCustomBorder

      protected Border getCustomBorder()
      Supplies the default border style for the page display area.

      This provides a simple visual separation for the PDF viewing content, relying on a theme-tolerant gray line.

      Usage: This is a protected method that can be called with @Override to allow for adjustments so that the border matches the 'look and feel' of the client it is called in. For example, MekHQ should replace this with RoundedLineBorder.createRoundedLineBorder().

      Returns:
      a Border instance for content panels
      Since:
      0.50.07
    • getCustomButton

      protected JButton getCustomButton(String buttonLabel)
      Utility method to create a JButton with the given localized text label.

      Usage: This is a protected method that can be called with @Override to allow for adjustments so that the button matches the 'look and feel' of the client it is called in. For example, MekHQ should replace this with RoundedJButton.

      Parameters:
      buttonLabel - the localized text to display on the button
      Returns:
      a new JButton instance with the specified text
      Since:
      0.50.07