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); } };
Constructor and Description |
---|
WarningNotifier() |
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.
|
getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, setFeatureName, teardown, toString
public boolean isEnabledByDefault()
ViewerFeature
ViewerFeature.getAllEnabledFeatures()
and by the PDFViewerApplet
and PDFTool
isEnabledByDefault
in class ViewerFeature
public void initialize(PDFViewer viewer)
ViewerFeature
initialize
in class ViewerFeature
public void documentUpdated(DocumentPanelEvent event)
DocumentPanelListener
DocumentPanelEvent
is raiseddocumentUpdated
in interface DocumentPanelListener
public void register(PDF source, JComponent destination)
source
- the PDF to look for as the source of a warningdestination
- the JComponent interested in those warnings - typically a PDFViewer
or DocumentPanel
public void register(PDFReader source, JComponent destination)
PDFReader
with this object. Any warning messages which
can be associated with this PDF will be sent to the specified
JComponent.source
- the PDF to look for as the source of a warningdestination
- the JComponent interested in those warnings - typically a PDFViewer
or DocumentPanel
public void register(Thread source, JComponent destination)
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.source
- the PDF to look for as the source of a warningdestination
- the JComponent interested in those warnings - typically a PDFViewer
or DocumentPanel
public void unregister(PDF source)
source
- the source object to unregisterpublic void unregister(PDFReader source)
source
- the source object to unregisterpublic void unregister(Thread source)
source
- the source object to unregisterpublic void warningEvent(JComponent component, Object source, String code, String message, Throwable throwable, Thread thread)
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 originatedCopyright © 2001-2017 Big Faceless Organization