Class WarningNotifier

  • All Implemented Interfaces:
    DocumentPanelListener

    public class WarningNotifier
    extends ViewerFeature
    implements DocumentPanelListener

    This feature can be used to hook into the logging subsystem and display warnings which would be sent to Log4J or the java.util.logging package.

    We'll be the first to admit this class is something of an afterthought and a slightly unusual fit with the rest of the API, due mainly to the difficulty in associating log messages (which are static, can emanate from any thread, and may not have a PDF object associated with them) to a particular JComponent for the notification. Consequently this class is referenced from various points in the API, particularly where background threads are started to process the PDF.

    This class will pop up a translucent window in the bottom-right corner of the viewer which contains the warning messages, and each message will expire after 5 seconds. We anticipate this display won't be to everyone's taste, in which case override this class and implement your own warningEvent(javax.swing.JComponent,java.lang.Object,java.lang.String,java.lang.String,java.lang.Throwable,java.lang.Thread) method. For example, to log messages to the JavaScript console instead:

     WarningNotifier notifier = new WarningNotifier() {
       public void warningEvent(JComponent component, Object source, String code, String message, Throwable throwable, Thread thread) {
         getViewer().getJSManager().consolePrintln("WARNING "+code+": "+message);
       }
     };
     
    Since:
    2.17.1
    • Constructor Detail

      • WarningNotifier

        public WarningNotifier()
    • Method Detail

      • register

        public void register​(PDF source,
                             JComponent destination)
        Register a PDF with this object. Any warning messages which can be associated with this PDF will be sent to the specified JComponent
        Parameters:
        source - the PDF to look for as the source of a warning
        destination - the JComponent interested in those warnings - typically a PDFViewer or DocumentPanel
      • register

        public void register​(PDFReader source,
                             JComponent destination)
        Register a PDFReader with this object. Any warning messages which can be associated with this PDF will be sent to the specified JComponent.
        Parameters:
        source - the PDF to look for as the source of a warning
        destination - the JComponent interested in those warnings - typically a PDFViewer or DocumentPanel
      • register

        public void register​(Thread source,
                             JComponent destination)
        Register a Thread with this object. Any warning messages which can be associated with this Thread will be sent to the specified JComponent. This method is called by the various background threads run in the viewer, e.g. thumbnail painting.
        Parameters:
        source - the PDF to look for as the source of a warning
        destination - the JComponent interested in those warnings - typically a PDFViewer or DocumentPanel
      • unregister

        public void unregister​(PDF source)
        Unregister a previously registered PDF
        Parameters:
        source - the source object to unregister
      • unregister

        public void unregister​(PDFReader source)
        Unregister a previously registered PDFReader
        Parameters:
        source - the source object to unregister
      • unregister

        public void unregister​(Thread source)
        Unregister a previously registered Thread
        Parameters:
        source - the source object to unregister
      • warningEvent

        public void warningEvent​(JComponent component,
                                 Object source,
                                 String code,
                                 String message,
                                 Throwable throwable,
                                 Thread thread)
        This method is called when a warning event can be associated with a JComponent. It is always be called on the Swing EventDispatchThread.
        Parameters:
        component - the component identified as interested in this warning
        source - the source object which triggered the warning for this JComponent by being registered. This may be any type of object, for example a PDF, a PDFReader or a Thread.
        code - the unique warning code
        message - the warning message
        throwable - the stack trace associated with that warning, if applicable.
        thread - the Thread on which the warning originated