ICEpdf
  1. ICEpdf
  2. PDF-1109

NullPointerException on SwingController

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.2
    • Fix Version/s: 6.2.1_P01
    • Component/s: Viewer RI
    • Labels:
      None
    • Environment:
      Linux RedHat
    • Workaround Exists:
      Yes
    • Workaround Description:
      Hide
      Setting the utilityTabbedPane to something different of null seems ok.
      <CODE>
      viewerController.setUtilityTabbedPane(new JTabbedPane() {
            @Override
            public void setEnabledAt(int index, boolean enabled) {
              // FAKE TABBED PANE
            }
          });
      </CODE>

      Or you can patch the SwingController#commonNewDocumentHandling by replacing this code :
      <CODE>
       // check if there are any attachments and enable/disable the tab as needed
              if (layersPanel != null && utilityTabbedPane != null && catalog.getEmbeddedFilesNameTree() != null) {
                  NameTree embeddedFilesNameTree = catalog.getEmbeddedFilesNameTree();
                  if (embeddedFilesNameTree != null &&
                          embeddedFilesNameTree.getRoot() != null) {
                      utilityTabbedPane.setEnabledAt(
                              utilityTabbedPane.indexOfComponent(attachmentPanel),
                              true);
                  }
              }else {
                  utilityTabbedPane.setEnabledAt(
                          utilityTabbedPane.indexOfComponent(attachmentPanel),
                          false);
              }
      </CODE>

      by
      <CODE> // check if there are any attachments and enable/disable the tab as needed
      if (utilityTabbedPane != null) {
              if (layersPanel != null && catalog.getEmbeddedFilesNameTree() != null) {
                  NameTree embeddedFilesNameTree = catalog.getEmbeddedFilesNameTree();
                  if (embeddedFilesNameTree != null &&
                          embeddedFilesNameTree.getRoot() != null) {
                      utilityTabbedPane.setEnabledAt(
                              utilityTabbedPane.indexOfComponent(attachmentPanel),
                              true);
                  }
              }else {
                  utilityTabbedPane.setEnabledAt(
                          utilityTabbedPane.indexOfComponent(attachmentPanel),
                          false);
              }
      }
      </CODE>
      Show
      Setting the utilityTabbedPane to something different of null seems ok. <CODE> viewerController.setUtilityTabbedPane(new JTabbedPane() {       @Override       public void setEnabledAt(int index, boolean enabled) {         // FAKE TABBED PANE       }     }); </CODE> Or you can patch the SwingController#commonNewDocumentHandling by replacing this code : <CODE>  // check if there are any attachments and enable/disable the tab as needed         if (layersPanel != null && utilityTabbedPane != null && catalog.getEmbeddedFilesNameTree() != null) {             NameTree embeddedFilesNameTree = catalog.getEmbeddedFilesNameTree();             if (embeddedFilesNameTree != null &&                     embeddedFilesNameTree.getRoot() != null) {                 utilityTabbedPane.setEnabledAt(                         utilityTabbedPane.indexOfComponent(attachmentPanel),                         true);             }         }else {             utilityTabbedPane.setEnabledAt(                     utilityTabbedPane.indexOfComponent(attachmentPanel),                     false);         } </CODE> by <CODE> // check if there are any attachments and enable/disable the tab as needed if (utilityTabbedPane != null) {         if (layersPanel != null && catalog.getEmbeddedFilesNameTree() != null) {             NameTree embeddedFilesNameTree = catalog.getEmbeddedFilesNameTree();             if (embeddedFilesNameTree != null &&                     embeddedFilesNameTree.getRoot() != null) {                 utilityTabbedPane.setEnabledAt(                         utilityTabbedPane.indexOfComponent(attachmentPanel),                         true);             }         }else {             utilityTabbedPane.setEnabledAt(                     utilityTabbedPane.indexOfComponent(attachmentPanel),                     false);         } } </CODE>

      Description

      I use the folowing code to display the PDF viewer into a panel :
      <CODE>
      public class PDFViewerPanel extends JPanel {

        SwingController viewerController = new SwingController();

        public PDFViewerPanel() {

          DocumentViewController viewController = viewerController.getDocumentViewController();
          viewerController.setIsEmbeddedComponent(true);
          
          JComponent viewerComponentPanel = (JComponent) viewController.getViewContainer();
          // add copy keyboard command
          ComponentKeyBinding.install(viewerController, viewerComponentPanel);

          // add interactive mouse link annotation support via callback
          viewController.setAnnotationCallback(
              new org.icepdf.ri.common.MyAnnotationCallback(viewController));

          removeAll();
          add(viewerComponentPanel);
        }
        
        public boolean openFile(String filePath) {
          viewerController.openDocument(filePath);
          revalidate();
          return true;
        }
      }
      </CODE>

      I get a NPE at SwingController line 2356 because the utilityTabbedPane is null.

      THANKS FOR YOUR WORK.

        Activity

        Hide
        Patrick Corless added a comment -

        Marking as fixed.

        Show
        Patrick Corless added a comment - Marking as fixed.

          People

          • Assignee:
            Patrick Corless
            Reporter:
            Didier Broca
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: