org.faceless.pdf2.viewer2
Class JSManager

java.lang.Object
  extended by JSCoreMethods
      extended by org.faceless.pdf2.viewer2.JSManager

public class JSManager
extends JSCoreMethods

Handles the Events - 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.

Since:
2.9

Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 the App.beep JavaScript method


consoleShow

public void consoleShow()
An implementation of the Console.show JavaScript method


consoleHide

public void consoleHide()
An implementation of the Console.hide JavaScript method


consolePrintln

public void consolePrintln(String message)
An implementation of the Console.println JavaScript method


consoleClear

public void consoleClear()
An implementation of the Console.clear JavaScript method


appAlert

public int appAlert(String message,
                    int nIcon,
                    int nType,
                    String cTitle,
                    Object oDoc,
                    Object oCheckbox)
An implementation of the App.alert JavaScript method


appResponse

public String appResponse(String message,
                          String cTitle,
                          String cDefault,
                          boolean bPassword,
                          String cLabel)
An implementation of the App.response JavaScript method


runEventAppInit

public void runEventAppInit()
Raise the App/Init JavaScript method


runEventBatchExec

public JSEvent runEventBatchExec(DocumentPanel panel,
                                 PDF pdf,
                                 String javascript)
Raise the Batch/Exec JavaScript method


runEventBookmarkMouseUp

public JSEvent runEventBookmarkMouseUp(DocumentPanel panel,
                                       PDFBookmark bookmark)
Raise the Bookmark/MouseUp JavaScript method


runEventConsoleExec

public JSEvent runEventConsoleExec(DocumentPanel panel,
                                   String javascript)
Raise the Console/Exec JavaScript method


runEventDocDidPrint

public JSEvent runEventDocDidPrint(DocumentPanel panel)
Raise the Doc/DidPrint JavaScript method


runEventDocDidSave

public JSEvent runEventDocDidSave(DocumentPanel panel)
Raise the Doc/DidSave JavaScript method


runEventDocOpen

public JSEvent runEventDocOpen(DocumentPanel panel,
                               String targetName)
Raise the Doc/Open JavaScript method


runEventDocWillClose

public JSEvent runEventDocWillClose(DocumentPanel panel)
Raise the Doc/WillClose JavaScript method


runEventDocWillPrint

public JSEvent runEventDocWillPrint(DocumentPanel panel)
Raise the Doc/WillPrint JavaScript method


runEventDocWillSave

public JSEvent runEventDocWillSave(DocumentPanel panel)
Raise the Doc/WillSave JavaScript method


runEventExternalExec

public JSEvent runEventExternalExec(DocumentPanel panel,
                                    String javascript)
Raise the External/Exec JavaScript method


runEventFieldBlur

public JSEvent runEventFieldBlur(DocumentPanel panel,
                                 WidgetAnnotation annot,
                                 boolean shift,
                                 boolean modifier)
Raise the Field/Blur JavaScript method


runEventFieldCalculate

public JSEvent runEventFieldCalculate(DocumentPanel panel,
                                      WidgetAnnotation target,
                                      WidgetAnnotation source)
Raise the Field/Calculate JavaScript method


runEventFieldFocus

public JSEvent runEventFieldFocus(DocumentPanel panel,
                                  WidgetAnnotation annot,
                                  boolean shift,
                                  boolean modifier)
Raise the Field/Focus JavaScript method


runEventFieldFormat

public JSEvent runEventFieldFormat(DocumentPanel panel,
                                   WidgetAnnotation annot,
                                   int commitKey,
                                   boolean willCommit)
Raise the Field/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 the Field/Keystroke JavaScript method


runEventFieldMouseDown

public JSEvent runEventFieldMouseDown(DocumentPanel panel,
                                      WidgetAnnotation annot,
                                      MouseEvent mevent)
Raise the Field/Mouse Down JavaScript method


runEventFieldMouseEnter

public JSEvent runEventFieldMouseEnter(DocumentPanel panel,
                                       WidgetAnnotation annot,
                                       MouseEvent mevent)
Raise the Field/Mouse Enter JavaScript method


runEventFieldMouseExit

public JSEvent runEventFieldMouseExit(DocumentPanel panel,
                                      WidgetAnnotation annot,
                                      MouseEvent mevent)
Raise the Field/Mouse Exit JavaScript method


runEventFieldMouseUp

public JSEvent runEventFieldMouseUp(DocumentPanel panel,
                                    WidgetAnnotation annot,
                                    MouseEvent mevent)
Raise the Field/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 the Field/Validate JavaScript method


runEventLinkMouseUp

public JSEvent runEventLinkMouseUp(DocumentPanel panel,
                                   AnnotationLink annot)
Raise the Link/Mouse Up JavaScript method


runEventPageOpen

public JSEvent runEventPageOpen(DocumentPanel panel,
                                PDFPage page)
Raise the Page/Open JavaScript method


runEventPageClose

public JSEvent runEventPageClose(DocumentPanel panel,
                                 PDFPage page)
Raise the Page/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 the Features in the PDFViewer for custom JavaScript, and returns the concatenation of all of them.

See Also:
ViewerFeature.getCustomJavaScript(java.lang.String, java.lang.String)

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 from getAppRuntimeHighlightColor(). The default value can be set by the JavaScript.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 by setAppRuntimeHighlight(boolean)

Since:
2.11.12

setAppRuntimeHighlightColor

public void setAppRuntimeHighlightColor(Color c)
Sets the color to highlight form fields if 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").

Parameters:
c - the highlight color
Since:
2.11.12

getAppRuntimeHighlightColor

public Color getAppRuntimeHighlightColor()
Return the value set by setAppRuntimeHighlightColor(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 the JavaScript.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 by setAppFocusRect(boolean)

Since:
2.11.12


Copyright © 2001-2010 Big Faceless Organization