Class JSManager
- java.lang.Object
-
- JSCoreMethods
-
- org.faceless.pdf2.viewer2.JSManager
-
public class JSManager extends JSCoreMethods
Handles the Event - 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 theDocumentPanelEvent
,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:java -Dorg.faceless.pdf2.viewer2.JSManager.AppInit=myscripts/appinit.js \ -Dorg.faceless.pdf2.viewer2.JSManager.DocOpen=myscripts/docopen.js \ org.faceless.pdf2.viewer2.PDFViewer
The
value
attribute is the path to a JavaScript file, the contents of which will be executed on the specified eventWith 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.
- Since:
- 2.9
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theApp.alert
JavaScript methodvoid
appBeep()
An implementation of theApp.beep
JavaScript methodvoid
appOpenDoc(String cPath, PDF pdf, String cFS, Boolean bHidden, Boolean bUseConv, String cDest)
An implementation of theApp.openDoc
JavaScript methodString
appResponse(String message, String cTitle, String cDefault, Boolean bPassword, String cLabel)
An implementation of theApp.response
JavaScript methodvoid
consoleClear()
An implementation of theConsole.clear
JavaScript methodvoid
consoleHide()
An implementation of theConsole.hide
JavaScript methodvoid
consolePrintln(String message)
An implementation of theConsole.println
JavaScript methodvoid
consoleShow()
An implementation of theConsole.show
JavaScript methodString
docExportAsXFDFStr(PDF pdf, Boolean bAllFields, Boolean bNoPassword, FormElement[] fields, Boolean bAnnotations, String cHRef)
boolean
getAppFocusRect()
Return the value set bysetAppFocusRect(boolean)
boolean
getAppRuntimeHighlight()
Return the value set bysetAppRuntimeHighlight(boolean)
Color
getAppRuntimeHighlightColor()
Return the value set bysetAppRuntimeHighlightColor(java.awt.Color)
Object
getComponent(PDFAnnotation annot)
Return the JComponent matchin the specified PDFAnnotationString
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 PDFString
getImplementationDescription()
Return a description of the JavaScript implementation in usePoint2D
getLastMousePosition(PDF pdf)
Get the point in PDF space where the last mouse event (MouseEnter, MouseExit, MouseUp, MouseDown) occurredPDFViewer
getViewer()
Return the PDFViewer this JSManager is a part ofvoid
runEventAppInit()
Raise theApp/Init
JavaScript methodJSEvent
runEventBatchExec(DocumentPanel panel, PDF pdf, String javascript)
Raise theBatch/Exec
JavaScript methodJSEvent
runEventBookmarkMouseUp(DocumentPanel panel, PDFBookmark bookmark)
Raise theBookmark/MouseUp
JavaScript methodJSEvent
runEventConsoleExec(DocumentPanel panel, String javascript)
Raise theConsole/Exec
JavaScript methodJSEvent
runEventDocDidPrint(DocumentPanel panel)
Raise theDoc/DidPrint
JavaScript methodJSEvent
runEventDocDidSave(DocumentPanel panel)
Raise theDoc/DidSave
JavaScript methodJSEvent
runEventDocOpen(DocumentPanel panel, String targetName)
Raise theDoc/Open
JavaScript methodJSEvent
runEventDocWillClose(DocumentPanel panel)
Raise theDoc/WillClose
JavaScript methodJSEvent
runEventDocWillPrint(DocumentPanel panel)
Raise theDoc/WillPrint
JavaScript methodJSEvent
runEventDocWillSave(DocumentPanel panel)
Raise theDoc/WillSave
JavaScript methodJSEvent
runEventExternalExec(DocumentPanel panel, String javascript)
Raise theExternal/Exec
JavaScript methodJSEvent
runEventFieldBlur(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Raise theField/Blur
JavaScript methodJSEvent
runEventFieldCalculate(DocumentPanel panel, WidgetAnnotation target, WidgetAnnotation source)
Raise theField/Calculate
JavaScript methodJSEvent
runEventFieldFocus(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Raise theField/Focus
JavaScript methodJSEvent
runEventFieldFormat(DocumentPanel panel, WidgetAnnotation annot, int commitKey, boolean willCommit)
Raise theField/Format
JavaScript methodJSEvent
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 theField/Keystroke
JavaScript methodJSEvent
runEventFieldMouseDown(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Down
JavaScript methodJSEvent
runEventFieldMouseEnter(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Enter
JavaScript methodJSEvent
runEventFieldMouseExit(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Exit
JavaScript methodJSEvent
runEventFieldMouseUp(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Up
JavaScript methodJSEvent
runEventFieldValidate(DocumentPanel panel, WidgetAnnotation annot, String value, boolean shift, boolean modifier, String change, String changeEx, boolean keyDown)
Raise theField/Validate
JavaScript methodJSEvent
runEventLinkMouseUp(DocumentPanel panel, AnnotationLink annot)
Raise theLink/Mouse Up
JavaScript methodJSEvent
runEventPageClose(DocumentPanel panel, PDFPage page)
Raise thePage/Close
JavaScript methodJSEvent
runEventPageOpen(DocumentPanel panel, PDFPage page)
Raise thePage/Open
JavaScript methodvoid
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 fromgetAppRuntimeHighlightColor()
.void
setAppRuntimeHighlightColor(Color c)
Sets the color to highlight form fields ifsetAppRuntimeHighlight(boolean)
returns true.
-
-
-
Method Detail
-
getViewer
public final PDFViewer getViewer()
Return the PDFViewer this JSManager is a part of- Since:
- 2.11
-
getDocumentPanel
public final DocumentPanel getDocumentPanel(PDF pdf)
Return the DocumentPanel that contains the specified PDF- Since:
- 2.11
-
getImplementationDescription
public String getImplementationDescription()
Return a description of the JavaScript implementation in use
-
getComponent
public final Object getComponent(PDFAnnotation annot)
Return the JComponent matchin the specified PDFAnnotation
-
getLastMousePosition
public Point2D getLastMousePosition(PDF pdf)
Get the point in PDF space where the last mouse event (MouseEnter, MouseExit, MouseUp, MouseDown) occurred
-
appBeep
public void appBeep()
An implementation of theApp.beep
JavaScript method
-
consoleShow
public void consoleShow()
An implementation of theConsole.show
JavaScript method
-
consoleHide
public void consoleHide()
An implementation of theConsole.hide
JavaScript method
-
consolePrintln
public void consolePrintln(String message)
An implementation of theConsole.println
JavaScript method
-
consoleClear
public void consoleClear()
An implementation of theConsole.clear
JavaScript method
-
appAlert
public int appAlert(String message, int nIcon, int nType, String cTitle, Object oDoc, Object oCheckbox)
An implementation of theApp.alert
JavaScript method
-
appOpenDoc
public void appOpenDoc(String cPath, PDF pdf, String cFS, Boolean bHidden, Boolean bUseConv, String cDest)
An implementation of theApp.openDoc
JavaScript method
-
appResponse
public String appResponse(String message, String cTitle, String cDefault, Boolean bPassword, String cLabel)
An implementation of theApp.response
JavaScript method
-
docExportAsXFDFStr
public String docExportAsXFDFStr(PDF pdf, Boolean bAllFields, Boolean bNoPassword, FormElement[] fields, Boolean bAnnotations, String cHRef)
-
runEventAppInit
public void runEventAppInit()
Raise theApp/Init
JavaScript method
-
runEventBatchExec
public JSEvent runEventBatchExec(DocumentPanel panel, PDF pdf, String javascript)
Raise theBatch/Exec
JavaScript method
-
runEventBookmarkMouseUp
public JSEvent runEventBookmarkMouseUp(DocumentPanel panel, PDFBookmark bookmark)
Raise theBookmark/MouseUp
JavaScript method
-
runEventConsoleExec
public JSEvent runEventConsoleExec(DocumentPanel panel, String javascript)
Raise theConsole/Exec
JavaScript method
-
runEventDocDidPrint
public JSEvent runEventDocDidPrint(DocumentPanel panel)
Raise theDoc/DidPrint
JavaScript method
-
runEventDocDidSave
public JSEvent runEventDocDidSave(DocumentPanel panel)
Raise theDoc/DidSave
JavaScript method
-
runEventDocOpen
public JSEvent runEventDocOpen(DocumentPanel panel, String targetName)
Raise theDoc/Open
JavaScript method
-
runEventDocWillClose
public JSEvent runEventDocWillClose(DocumentPanel panel)
Raise theDoc/WillClose
JavaScript method
-
runEventDocWillPrint
public JSEvent runEventDocWillPrint(DocumentPanel panel)
Raise theDoc/WillPrint
JavaScript method
-
runEventDocWillSave
public JSEvent runEventDocWillSave(DocumentPanel panel)
Raise theDoc/WillSave
JavaScript method
-
runEventExternalExec
public JSEvent runEventExternalExec(DocumentPanel panel, String javascript)
Raise theExternal/Exec
JavaScript method
-
runEventFieldBlur
public JSEvent runEventFieldBlur(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Raise theField/Blur
JavaScript method
-
runEventFieldCalculate
public JSEvent runEventFieldCalculate(DocumentPanel panel, WidgetAnnotation target, WidgetAnnotation source)
Raise theField/Calculate
JavaScript method
-
runEventFieldFocus
public JSEvent runEventFieldFocus(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Raise theField/Focus
JavaScript method
-
runEventFieldFormat
public JSEvent runEventFieldFormat(DocumentPanel panel, WidgetAnnotation annot, int commitKey, boolean willCommit)
Raise theField/Format
JavaScript method
-
runEventFieldKeystroke
public 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 theField/Keystroke
JavaScript method
-
runEventFieldMouseDown
public JSEvent runEventFieldMouseDown(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Down
JavaScript method
-
runEventFieldMouseEnter
public JSEvent runEventFieldMouseEnter(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Enter
JavaScript method
-
runEventFieldMouseExit
public JSEvent runEventFieldMouseExit(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Exit
JavaScript method
-
runEventFieldMouseUp
public JSEvent runEventFieldMouseUp(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse Up
JavaScript method
-
runEventFieldValidate
public JSEvent runEventFieldValidate(DocumentPanel panel, WidgetAnnotation annot, String value, boolean shift, boolean modifier, String change, String changeEx, boolean keyDown)
Raise theField/Validate
JavaScript method
-
runEventLinkMouseUp
public JSEvent runEventLinkMouseUp(DocumentPanel panel, AnnotationLink annot)
Raise theLink/Mouse Up
JavaScript method
-
runEventPageOpen
public JSEvent runEventPageOpen(DocumentPanel panel, PDFPage page)
Raise thePage/Open
JavaScript method
-
runEventPageClose
public JSEvent runEventPageClose(DocumentPanel panel, PDFPage page)
Raise thePage/Close
JavaScript method
-
getCustomJavaScript
public String getCustomJavaScript(String type, String name)
Return any Custom JavaScript to be run when the specified event is received. This method checks each of theFeatures
in the PDFViewer for custom JavaScript, and returns the concatenation of all of them.
-
addCustomJavaScript
public void addCustomJavaScript(String event, URL url) throws IOException
Add some custom JavaScript to the viewer.- Parameters:
event
- the event type, eg "App/Init" or "Doc/Open"url
- the URL to load the JavaScript from- Throws:
IOException
- Since:
- 2.11.18
-
addCustomJavaScript
public void addCustomJavaScript(String event, String script)
Add some custom JavaScript to the viewer.- Parameters:
event
- the event type, eg "App/Init" or "Doc/Open"script
- the JavaScript to execute on that event- Since:
- 2.11.18
-
setAppRuntimeHighlight
public void setAppRuntimeHighlight(boolean highlight)
Sets whether to highlight form fields displayed in the viewer using the color fromgetAppRuntimeHighlightColor()
. The default value can be set by theJavaScript.app.runtimeHighlight
property, which can be set to "true" to enable this by default.- Parameters:
highlight
- true to highlight form fields- Since:
- 2.11.12
-
getAppRuntimeHighlight
public boolean getAppRuntimeHighlight()
Return the value set bysetAppRuntimeHighlight(boolean)
- Since:
- 2.11.12
-
setAppRuntimeHighlightColor
public void setAppRuntimeHighlightColor(Color c)
Sets the color to highlight form fields ifsetAppRuntimeHighlight(boolean)
returns true. The default value can be set by theJavaScript.app.runtimeHighlightColor
property, which may be an HTML-style color (eg "#FF0000").- Parameters:
c
- the highlight color- Since:
- 2.11.12
-
getAppRuntimeHighlightColor
public Color getAppRuntimeHighlightColor()
Return the value set bysetAppRuntimeHighlightColor(java.awt.Color)
- Since:
- 2.11.12
-
setAppFocusRect
public void setAppFocusRect(boolean value)
Sets whether to mark form fields with focus with a dotted rectangle. The default value can be set by theJavaScript.app.focusRect
property, which can be set to "false" to disable this by default.- Parameters:
value
- true to highlight form fields- Since:
- 2.11.12
-
getAppFocusRect
public boolean getAppFocusRect()
Return the value set bysetAppFocusRect(boolean)
- Since:
- 2.11.12
-
-