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(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 Summary
Constructors Constructor Description WarningNotifier()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
documentUpdated(DocumentPanelEvent event)
Called when anDocumentPanelEvent
is raisedvoid
initialize(PDFViewer viewer)
Called when the feature is first added to a viewerboolean
isEnabledByDefault()
Return true if this feature is enabled by default (the default).void
register(Thread source, JComponent destination)
Register aThread
with this object.void
register(PDFReader source, JComponent destination)
Register aPDFReader
with this object.void
register(PDF source, JComponent destination)
Register a PDF with this object.void
unregister(Thread source)
Unregister a previously registered Threadvoid
unregister(PDF source)
Unregister a previously registered PDFvoid
unregister(PDFReader source)
Unregister a previously registered PDFReadervoid
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
-
-
-
-
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 byViewerFeature.getAllEnabledFeatures()
and byPDFTool
- Overrides:
isEnabledByDefault
in classViewerFeature
-
initialize
public void initialize(PDFViewer viewer)
Description copied from class:ViewerFeature
Called when the feature is first added to a viewer- Overrides:
initialize
in classViewerFeature
-
documentUpdated
public void documentUpdated(DocumentPanelEvent event)
Description copied from interface:DocumentPanelListener
Called when anDocumentPanelEvent
is raised- Specified by:
documentUpdated
in interfaceDocumentPanelListener
-
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 warningdestination
- the JComponent interested in those warnings - typically aPDFViewer
orDocumentPanel
-
register
public void register(PDFReader source, JComponent destination)
Register aPDFReader
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 warningdestination
- the JComponent interested in those warnings - typically aPDFViewer
orDocumentPanel
-
register
public void register(Thread source, JComponent destination)
Register aThread
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 warningdestination
- the JComponent interested in those warnings - typically aPDFViewer
orDocumentPanel
-
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 warningsource
- 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 codemessage
- the warning messagethrowable
- the stack trace associated with that warning, if applicable.thread
- the Thread on which the warning originated
-
-