public class JSManager
extends JSCoreMethods
Handles the Event
s - primarily JavaScript events - raised during the lifetime of
the viewer. This class will raise the PDF lifetime events defined in the
Acrobat JavaScript Scripting Reference, which may have PDFAction
objects
associated with them. These are unrelated to Swing events and to the
DocumentPanelEvent
, PagePanelEvent
and similar.
Since 2.11.18 is it possible to configure custom JavaScript that will run on certain
events. This can be done by either calling the addCustomJavaScript(java.lang.String, java.net.URL)
method,
or by setting a System property. As an example, here's how to run one custom scripts
on App/Init and Doc/Open events:
from an applet;
<applet code="org.faceless.pdf2.viewer2.PDFViewerApplet" name="pdfapplet" archive="bfopdf.jar, bfopdf-cmap.jar" mayscript> <param name="JSManager.AppInit" value="myscripts/appinit.js" /> <param name="JSManager.DocOpen" value="myscripts/docopen.js" /> </applet>
The value
attribute is the path to a JavaScript file, the contents
of which will be executed on the specified event
With the exception of the above, we recommend developers and those working with the viewer steer well clear of calling into this class, as the API is subject to change without notice.
Modifier and Type | Method and Description |
---|---|
void |
addCustomJavaScript(String event,
String script)
Add some custom JavaScript to the viewer.
|
void |
addCustomJavaScript(String event,
URL url)
Add some custom JavaScript to the viewer.
|
int |
appAlert(String message,
int nIcon,
int nType,
String cTitle,
Object oDoc,
Object oCheckbox)
An implementation of the
App.alert JavaScript method |
void |
appBeep()
An implementation of the
App.beep JavaScript method |
String |
appResponse(String message,
String cTitle,
String cDefault,
boolean bPassword,
String cLabel)
An implementation of the
App.response JavaScript method |
void |
consoleClear()
An implementation of the
Console.clear JavaScript method |
void |
consoleHide()
An implementation of the
Console.hide JavaScript method |
void |
consolePrintln(String message)
An implementation of the
Console.println JavaScript method |
void |
consoleShow()
An implementation of the
Console.show JavaScript method |
boolean |
getAppFocusRect()
Return the value set by
setAppFocusRect(boolean) |
boolean |
getAppRuntimeHighlight()
Return the value set by
setAppRuntimeHighlight(boolean) |
Color |
getAppRuntimeHighlightColor()
Return the value set by
setAppRuntimeHighlightColor(java.awt.Color) |
Object |
getComponent(PDFAnnotation annot)
Return the JComponent matchin the specified PDFAnnotation
|
String |
getCustomJavaScript(String type,
String name)
Return any Custom JavaScript to be run when the specified event is
received.
|
DocumentPanel |
getDocumentPanel(PDF pdf)
Return the DocumentPanel that contains the specified PDF
|
String |
getImplementationDescription()
Return a description of the JavaScript implementation in use
|
Point2D |
getLastMousePosition(PDF pdf)
Get the point in PDF space where the last mouse event (MouseEnter, MouseExit, MouseUp, MouseDown) occurred
|
PDFViewer |
getViewer()
Return the PDFViewer this JSManager is a part of
|
void |
runEventAppInit()
Raise the
App/Init JavaScript method |
JSEvent |
runEventBatchExec(DocumentPanel panel,
PDF pdf,
String javascript)
Raise the
Batch/Exec JavaScript method |
JSEvent |
runEventBookmarkMouseUp(DocumentPanel panel,
PDFBookmark bookmark)
Raise the
Bookmark/MouseUp JavaScript method |
JSEvent |
runEventConsoleExec(DocumentPanel panel,
String javascript)
Raise the
Console/Exec JavaScript method |
JSEvent |
runEventDocDidPrint(DocumentPanel panel)
Raise the
Doc/DidPrint JavaScript method |
JSEvent |
runEventDocDidSave(DocumentPanel panel)
Raise the
Doc/DidSave JavaScript method |
JSEvent |
runEventDocOpen(DocumentPanel panel,
String targetName)
Raise the
Doc/Open JavaScript method |
JSEvent |
runEventDocWillClose(DocumentPanel panel)
Raise the
Doc/WillClose JavaScript method |
JSEvent |
runEventDocWillPrint(DocumentPanel panel)
Raise the
Doc/WillPrint JavaScript method |
JSEvent |
runEventDocWillSave(DocumentPanel panel)
Raise the
Doc/WillSave JavaScript method |
JSEvent |
runEventExternalExec(DocumentPanel panel,
String javascript)
Raise the
External/Exec JavaScript method |
JSEvent |
runEventFieldBlur(DocumentPanel panel,
WidgetAnnotation annot,
boolean shift,
boolean modifier)
Raise the
Field/Blur JavaScript method |
JSEvent |
runEventFieldCalculate(DocumentPanel panel,
WidgetAnnotation target,
WidgetAnnotation source)
Raise the
Field/Calculate JavaScript method |
JSEvent |
runEventFieldFocus(DocumentPanel panel,
WidgetAnnotation annot,
boolean shift,
boolean modifier)
Raise the
Field/Focus JavaScript method |
JSEvent |
runEventFieldFormat(DocumentPanel panel,
WidgetAnnotation annot,
int commitKey,
boolean willCommit)
Raise the
Field/Format JavaScript method |
JSEvent |
runEventFieldKeystroke(DocumentPanel panel,
WidgetAnnotation annot,
int commitKey,
String change,
String changeEx,
boolean fieldFull,
boolean keyDown,
boolean modifier,
int selStart,
int selEnd,
boolean shift,
String value,
boolean willCommit)
Raise the
Field/Keystroke JavaScript method |
JSEvent |
runEventFieldMouseDown(DocumentPanel panel,
WidgetAnnotation annot,
MouseEvent mevent)
Raise the
Field/Mouse Down JavaScript method |
JSEvent |
runEventFieldMouseEnter(DocumentPanel panel,
WidgetAnnotation annot,
MouseEvent mevent)
Raise the
Field/Mouse Enter JavaScript method |
JSEvent |
runEventFieldMouseExit(DocumentPanel panel,
WidgetAnnotation annot,
MouseEvent mevent)
Raise the
Field/Mouse Exit JavaScript method |
JSEvent |
runEventFieldMouseUp(DocumentPanel panel,
WidgetAnnotation annot,
MouseEvent mevent)
Raise the
Field/Mouse Up JavaScript method |
JSEvent |
runEventFieldValidate(DocumentPanel panel,
WidgetAnnotation annot,
String value,
boolean shift,
boolean modifier,
String change,
String changeEx,
boolean keyDown)
Raise the
Field/Validate JavaScript method |
JSEvent |
runEventLinkMouseUp(DocumentPanel panel,
AnnotationLink annot)
Raise the
Link/Mouse Up JavaScript method |
JSEvent |
runEventPageClose(DocumentPanel panel,
PDFPage page)
Raise the
Page/Close JavaScript method |
JSEvent |
runEventPageOpen(DocumentPanel panel,
PDFPage page)
Raise the
Page/Open JavaScript method |
void |
setAppFocusRect(boolean value)
Sets whether to mark form fields with focus with a dotted rectangle.
|
void |
setAppRuntimeHighlight(boolean highlight)
Sets whether to highlight form fields displayed in the viewer
using the color from
getAppRuntimeHighlightColor() . |
void |
setAppRuntimeHighlightColor(Color c)
Sets the color to highlight form fields if
setAppRuntimeHighlight(boolean)
returns true. |
public final PDFViewer getViewer()
public final DocumentPanel getDocumentPanel(PDF pdf)
public String getImplementationDescription()
public final Object getComponent(PDFAnnotation annot)
public Point2D getLastMousePosition(PDF pdf)
public void appBeep()
App.beep
JavaScript methodpublic void consoleShow()
Console.show
JavaScript methodpublic void consoleHide()
Console.hide
JavaScript methodpublic void consolePrintln(String message)
Console.println
JavaScript methodpublic void consoleClear()
Console.clear
JavaScript methodpublic int appAlert(String message, int nIcon, int nType, String cTitle, Object oDoc, Object oCheckbox)
App.alert
JavaScript methodpublic String appResponse(String message, String cTitle, String cDefault, boolean bPassword, String cLabel)
App.response
JavaScript methodpublic void runEventAppInit()
App/Init
JavaScript methodpublic JSEvent runEventBatchExec(DocumentPanel panel, PDF pdf, String javascript)
Batch/Exec
JavaScript methodpublic JSEvent runEventBookmarkMouseUp(DocumentPanel panel, PDFBookmark bookmark)
Bookmark/MouseUp
JavaScript methodpublic JSEvent runEventConsoleExec(DocumentPanel panel, String javascript)
Console/Exec
JavaScript methodpublic JSEvent runEventDocDidPrint(DocumentPanel panel)
Doc/DidPrint
JavaScript methodpublic JSEvent runEventDocDidSave(DocumentPanel panel)
Doc/DidSave
JavaScript methodpublic JSEvent runEventDocOpen(DocumentPanel panel, String targetName)
Doc/Open
JavaScript methodpublic JSEvent runEventDocWillClose(DocumentPanel panel)
Doc/WillClose
JavaScript methodpublic JSEvent runEventDocWillPrint(DocumentPanel panel)
Doc/WillPrint
JavaScript methodpublic JSEvent runEventDocWillSave(DocumentPanel panel)
Doc/WillSave
JavaScript methodpublic JSEvent runEventExternalExec(DocumentPanel panel, String javascript)
External/Exec
JavaScript methodpublic JSEvent runEventFieldBlur(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Field/Blur
JavaScript methodpublic JSEvent runEventFieldCalculate(DocumentPanel panel, WidgetAnnotation target, WidgetAnnotation source)
Field/Calculate
JavaScript methodpublic JSEvent runEventFieldFocus(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Field/Focus
JavaScript methodpublic JSEvent runEventFieldFormat(DocumentPanel panel, WidgetAnnotation annot, int commitKey, boolean willCommit)
Field/Format
JavaScript methodpublic JSEvent runEventFieldKeystroke(DocumentPanel panel, WidgetAnnotation annot, int commitKey, String change, String changeEx, boolean fieldFull, boolean keyDown, boolean modifier, int selStart, int selEnd, boolean shift, String value, boolean willCommit)
Field/Keystroke
JavaScript methodpublic JSEvent runEventFieldMouseDown(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Field/Mouse Down
JavaScript methodpublic JSEvent runEventFieldMouseEnter(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Field/Mouse Enter
JavaScript methodpublic JSEvent runEventFieldMouseExit(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Field/Mouse Exit
JavaScript methodpublic JSEvent runEventFieldMouseUp(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Field/Mouse Up
JavaScript methodpublic JSEvent runEventFieldValidate(DocumentPanel panel, WidgetAnnotation annot, String value, boolean shift, boolean modifier, String change, String changeEx, boolean keyDown)
Field/Validate
JavaScript methodpublic JSEvent runEventLinkMouseUp(DocumentPanel panel, AnnotationLink annot)
Link/Mouse Up
JavaScript methodpublic JSEvent runEventPageOpen(DocumentPanel panel, PDFPage page)
Page/Open
JavaScript methodpublic JSEvent runEventPageClose(DocumentPanel panel, PDFPage page)
Page/Close
JavaScript methodpublic String getCustomJavaScript(String type, String name)
Features
in the PDFViewer for custom JavaScript, and returns the concatenation
of all of them.public void addCustomJavaScript(String event, URL url) throws IOException
event
- the event type, eg "App/Init" or "Doc/Open"url
- the URL to load the JavaScript fromIOException
public void addCustomJavaScript(String event, String script)
event
- the event type, eg "App/Init" or "Doc/Open"script
- the JavaScript to execute on that eventpublic void setAppRuntimeHighlight(boolean highlight)
getAppRuntimeHighlightColor()
.
The default value can be set by the JavaScript.app.runtimeHighlight
property, which can be set to "true" to enable this by default.highlight
- true to highlight form fieldspublic boolean getAppRuntimeHighlight()
setAppRuntimeHighlight(boolean)
public void setAppRuntimeHighlightColor(Color c)
setAppRuntimeHighlight(boolean)
returns true.
The default value can be set by the JavaScript.app.runtimeHighlightColor
property, which may be an HTML-style color (eg "#FF0000").c
- the highlight colorpublic Color getAppRuntimeHighlightColor()
setAppRuntimeHighlightColor(java.awt.Color)
public void setAppFocusRect(boolean value)
JavaScript.app.focusRect
property, which can be set to "false" to disable this by default.value
- true to highlight form fieldspublic boolean getAppFocusRect()
setAppFocusRect(boolean)
Copyright © 2001-2017 Big Faceless Organization