org.faceless.pdf2.viewer2.feature

## Class WarningNotifier

- java.lang.Object
- - org.faceless.pdf2.viewer2.ViewerFeature
  - - org.faceless.pdf2.viewer2.feature.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` 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 Summary

    Constructors
    Constructor and Description
    `WarningNotifier()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `documentUpdated(DocumentPanelEvent event)` Called when an `DocumentPanelEvent` is raised
    `void` | `initialize(PDFViewer viewer)` Called when the feature is first added to a viewer
    `boolean` | `isEnabledByDefault()` Return true if this feature is enabled by default (the default).
    `void` | `register(PDF source, JComponent destination)` Register a PDF with this object.
    `void` | `register(PDFReader source, JComponent destination)` Register a `PDFReader` with this object.
    `void` | `register(Thread source, JComponent destination)` Register a `Thread` with this object.
    `void` | `unregister(PDF source)` Unregister a previously registered PDF
    `void` | `unregister(PDFReader source)` Unregister a previously registered PDFReader
    `void` | `unregister(Thread source)` Unregister a previously registered Thread
    `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.

    - ### Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature

      `getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, setFeatureName, teardown, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### WarningNotifier

          public WarningNotifier()

  - ### Method Detail

    - #### isEnabledByDefault

          public boolean isEnabledByDefault()

      Description copied from class: `ViewerFeature`
      Return true if this feature is enabled by default (the default). Disabled features are excluded from the list returned by `ViewerFeature.getAllEnabledFeatures()` and by the `PDFViewerApplet` and `PDFTool`
      Overrides:
        `isEnabledByDefault` in class `ViewerFeature`

    - #### initialize

          public void initialize(PDFViewer viewer)

      Description copied from class: `ViewerFeature`
      Called when the feature is first added to a viewer
      Overrides:
        `initialize` in class `ViewerFeature`

    - #### documentUpdated

          public void documentUpdated(DocumentPanelEvent event)

      Description copied from interface: `DocumentPanelListener`
      Called when an `DocumentPanelEvent` is raised
      Specified by:
        `documentUpdated` in interface `DocumentPanelListener`

    - #### 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

Copyright © 2001-2015 Big Faceless Organization