# Class JSViewer

java.lang.Object
jspecview.common.JSViewer

All Implemented Interfaces:
  `BytePoster, PlatformViewer`

public class JSViewer extends Object implements PlatformViewer, BytePoster
This class encapsulates all general functionality of applet and app. Most methods include ScriptInterface parameter, which will be JSVAppletPrivate, JSVAppletPrivatePro, or MainFrame.

Author:
  Bob Hanson hansonr@stolaf.edu

## Field Summary

Fields
Modifier and Type
Field
Description
`boolean`
`allowMenu`
`GenericPlatform`
`apiPlatform`
`String`
`appletName`
`boolean`
`autoIntegrate`
`boolean`
`autoShowLegend`
`JDXSource`
`currentSource`
`static final int`
`DEFAULT_HEIGHT`
`static final int`
`DEFAULT_WIDTH`
`Object`
`display`
`static final int`
`FILE_OPEN_ALREADY`
`static final int`
`FILE_OPEN_ERROR`
`static final int`
`FILE_OPEN_NO_DATA`
`static final int`
`FILE_OPEN_OK`
`JSVFileHelper`
`fileHelper`
`String`
`fullName`
`GenericGraphics`
`g2d`
`boolean`
`hasDisplay`
`JSVAppletObject`
`html5Applet`
`int`
`initialEndIndex`
`int`
`initialStartIndex`
`boolean`
`interfaceOverlaid`
`boolean`
`isApplet`
`boolean`
`isEmbedded`
`static boolean`
`isJS`
`boolean`
`isSigned`
`boolean`
`isSingleThreaded`
`static boolean`
`isSwingJS`
`static JSVToJSmolInterface`
`jsmolObject`
`JSVGenericPopup`
`jsvpPopupMenu`
`boolean`
`loadImaginary`
`JSVMainPanel`
`mainPanel`
`float`
`nmrMaxY`
`Boolean`
`obscureTitleFromUser`
`static final int`
`OVERLAY_DIALOG`
`static final int`
`OVERLAY_OFFSET`
`Lst<PanelNode>`
`panelNodes`
`ColorParameters`
`parameters`
`static final int`
`PDF_NO_SUCH_PAGE`
`static final int`
`PDF_PAGE_EXISTS`
`String`
`peakInfoModelSentToJmol`
`static final int`
`PORTRAIT`
`Properties`
`properties`
`String`
`recentSimulation`
`RepaintManager`
`repaintManager`
`Lst<String>`
`scriptQueue`
`JSVPanel`
`selectedPanel`
`ScriptInterface`
`si`
`static final String`
`sourceLabel`
`JSVTree`
`spectraTree`
`String`
`syncID`

## Constructor Summary

Constructors
Constructor
Description
`JSViewer(ScriptInterface si, boolean isApplet, boolean isJSApplet, boolean hasDisplay)`

## Method Summary

Modifier and Type
Method
Description
`void`
`advanceSpectrumBy(int n)`
`void`
`checkAutoIntegrate()`
`String`
`checkCommandLineForTip(char c, String cmd, boolean oneLineOnly)`
`boolean`
`checkOvelayInterface(String value)`
`void`
`checkOverlay()`
`String`
`checkScript(String script)`
`void`
`close(String value)`
`void`
`closeSource(JDXSource source)`
`void`
`combineSpectra(String name)`
`void`
`dispose()`
`void`
`execLoad(String value, String script)`
`void`
`execView(String value, boolean fromScript)`
`String`
`export(String type, int n)`
`JSVAppletObject`
`getApplet()`
`String`
`getCoordinate()`
`JSVDialog`
`getDialog(Annotation.AType type, Spectrum spec)`
`DialogManager`
`getDialogManager()`
`int`
`getHeight()`
`static Object`
`getInterface(String name)`
`int`
`getOptionFromDialog(String[] items, String title, String label)`
`OC`
`getOutputChannel(String fileName, boolean isBinary)`
`Object`
`getPlatformInterface(String type)`
`PrintLayout`
`getPrintLayout(boolean isJob)`
`Map<String,Object>`
`getPropertyAsJavaObject(String key)`
`int`
`getSolutionColor(boolean asFitted)`
`String`
`getSolutionColorStr(boolean asFit)`
`int`
`getWidth()`
`int`
`openDataOrFile(Object data, String name, Lst<Spectrum> specs, String strUrl, int firstSpec, int lastSpec, boolean isAppend, String id)`
`void`
`openFile(String fileName, boolean closeFirst)`
Opens and displays a file
`void`
`openFileAsyncSpecial(String fileName, int flags)`
`boolean`
`openFileFromDialog(boolean isAppend, boolean isURL, String simulationType, String script)`
`void`
`parseInitScript(String params)`
Parses the JavaScript call parameters and executes them accordingly
`PanelData`
`pd()`
`String`
`postByteArray(String fileName, byte[] bytes)`
`String`
`print(String fileName)`
`void`
`processKeyEvent(Object event)`
`boolean`
`processMouseEvent(int id, int x, int y, int modifiers, long time)`
called by JSmol.js mouse event
`void`
`processPeakPickEvent(Object eventObj, boolean isApp)`
this method is called as a result of the user clicking on a peak (eventObject instanceof PeakPickEvent) or from PEAK command execution
`void`
`processTwoPointGesture(float[][][] touches)`
`void`
`repaintDone()`
`void`
`requestRepaint()`
`void`
`runScript(String script)`
`boolean`
`runScriptNow(String script)`
`void`
`selectedTreeNode(JSVTreeNode node)`
`PanelNode`
`selectFrameNode(JSVPanel jsvp)`
`int`
`selectPanel(JSVPanel jsvp, Lst<PanelNode> panelNodes)`
From (AwtMainPanel or JsMainPanel).setSelectedPanel
`void`
`sendPanelChange()`
`void`
`setCreatingImage(boolean isSaving)`
`void`
`setDisplay(Object canvas)`
`void`
`setFrameAndTreeNode(int i)`
`void`
`setIRmode(String mode)`
`void`
`setNode(PanelNode node)`
`void`
`setParentFrame(JFrame parentFrame)`
`void`
`setPopupMenu(boolean allowMenu, boolean zoomEnabled)`
`void`
`setProperty(String key, String value)`
`void`
`setRecentSimulation(String name)`
`void`
`setScreenDimension(int width, int height)`
`void`
`showMenu(int x, int y)`
`void`
`showMessage(String msg)`
`void`
`splitSpectra()`
`void`
`syncScript(String peakScript)`
/ Jmol sychronization
`void`
`updateJS()`
for JavaScript only; this is the call to draw the spectrum

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### sourceLabel

public static final String sourceLabel

See Also:
  - Constant Field Values

### FILE_OPEN_OK

public static final int FILE_OPEN_OK

See Also:
  - Constant Field Values

### FILE_OPEN_ALREADY

public static final int FILE_OPEN_ALREADY

See Also:
  - Constant Field Values

### FILE_OPEN_ERROR

public static final int FILE_OPEN_ERROR

See Also:
  - Constant Field Values

### FILE_OPEN_NO_DATA

public static final int FILE_OPEN_NO_DATA

See Also:
  - Constant Field Values

### OVERLAY_DIALOG

public static final int OVERLAY_DIALOG

See Also:
  - Constant Field Values

### OVERLAY_OFFSET

public static final int OVERLAY_OFFSET

See Also:
  - Constant Field Values

### PORTRAIT

public static final int PORTRAIT

See Also:
  - Constant Field Values

### PDF_PAGE_EXISTS

public static final int PDF_PAGE_EXISTS

See Also:
  - Constant Field Values

### PDF_NO_SUCH_PAGE

public static final int PDF_NO_SUCH_PAGE

See Also:
  - Constant Field Values

### DEFAULT_WIDTH

public static final int DEFAULT_WIDTH

See Also:
  - Constant Field Values

### DEFAULT_HEIGHT

public static final int DEFAULT_HEIGHT

See Also:
  - Constant Field Values

### si

public ScriptInterface si

### g2d

public GenericGraphics g2d

### spectraTree

public JSVTree spectraTree

### currentSource

public JDXSource currentSource

### panelNodes

public Lst<PanelNode> panelNodes

### parameters

public ColorParameters parameters

### repaintManager

public RepaintManager repaintManager

### selectedPanel

public JSVPanel selectedPanel

### mainPanel

public JSVMainPanel mainPanel

### properties

public Properties properties

### scriptQueue

public Lst<String> scriptQueue

### fileHelper

public JSVFileHelper fileHelper

### jsvpPopupMenu

public JSVGenericPopup jsvpPopupMenu

### isEmbedded

public boolean isEmbedded

### loadImaginary

public boolean loadImaginary

### interfaceOverlaid

public boolean interfaceOverlaid

### autoIntegrate

public boolean autoIntegrate

### autoShowLegend

public boolean autoShowLegend

### obscureTitleFromUser

public Boolean obscureTitleFromUser

### allowMenu

public boolean allowMenu

### initialStartIndex

public int initialStartIndex

### initialEndIndex

public int initialEndIndex

### isSingleThreaded

public boolean isSingleThreaded

### isApplet

public boolean isApplet

### isJS

public static boolean isJS

### isSwingJS

public static boolean isSwingJS

### isSigned

public boolean isSigned

### appletName

public String appletName

### fullName

public String fullName

### syncID

public String syncID

### html5Applet

public JSVAppletObject html5Applet

### display

public Object display

### apiPlatform

public GenericPlatform apiPlatform

### hasDisplay

public boolean hasDisplay

### jsmolObject

public static JSVToJSmolInterface jsmolObject

### peakInfoModelSentToJmol

public String peakInfoModelSentToJmol

### nmrMaxY

public float nmrMaxY

### recentSimulation

public String recentSimulation

## Constructor Details

### JSViewer

public JSViewer(ScriptInterface si, boolean isApplet, boolean isJSApplet, boolean hasDisplay)

Parameters:
  `si` -
  `isApplet` -
  `isJSApplet` -
  `hasDisplay` -

## Method Details

### setParentFrame

public void setParentFrame(JFrame parentFrame)

### setProperty

public void setProperty(String key, String value)

### setNode

public void setNode(PanelNode node)

### setPopupMenu

public void setPopupMenu(boolean allowMenu, boolean zoomEnabled)

### showMenu

public void showMenu(int x, int y)

### runScriptNow

public boolean runScriptNow(String script)

### checkOvelayInterface

public boolean checkOvelayInterface(String value)

### pd

public PanelData pd()

### execView

public void execView(String value, boolean fromScript)

### sendPanelChange

public void sendPanelChange()

### getPropertyAsJavaObject

public Map<String,Object> getPropertyAsJavaObject(String key)

### getCoordinate

public String getCoordinate()

### getSolutionColor

public int getSolutionColor(boolean asFitted)

### openDataOrFile

public int openDataOrFile(Object data, String name, Lst<Spectrum> specs, String strUrl, int firstSpec, int lastSpec, boolean isAppend, String id)

### close

public void close(String value)

### execLoad

public void execLoad(String value, String script)

### combineSpectra

public void combineSpectra(String name)

### closeSource

public void closeSource(JDXSource source)

### setFrameAndTreeNode

public void setFrameAndTreeNode(int i)

### selectFrameNode

public PanelNode selectFrameNode(JSVPanel jsvp)

### splitSpectra

public void splitSpectra()

### selectedTreeNode

public void selectedTreeNode(JSVTreeNode node)

### dispose

public void dispose()

### runScript

public void runScript(String script)

### requestRepaint

public void requestRepaint()

### repaintDone

public void repaintDone()

### checkOverlay

public void checkOverlay()

### setDisplay

public void setDisplay(Object canvas)

### setScreenDimension

public void setScreenDimension(int width, int height)

### updateJS

public void updateJS()
for JavaScript only; this is the call to draw the spectrum

### processMouseEvent

public boolean processMouseEvent(int id, int x, int y, int modifiers, long time)
called by JSmol.js mouse event

Parameters:
  `id` -
  `x` -
  `y` -
  `modifiers` -
  `time` -
Returns:
  t/f

### processTwoPointGesture

public void processTwoPointGesture(float[][][] touches)

### processKeyEvent

public void processKeyEvent(Object event)

### getApplet

public JSVAppletObject getApplet()

### openFileAsyncSpecial

public void openFileAsyncSpecial(String fileName, int flags)

Parameters:
  `fileName` -
  `flags` -

### getHeight

public int getHeight()

### getWidth

public int getWidth()

### getPlatformInterface

public Object getPlatformInterface(String type)

### getDialogManager

public DialogManager getDialogManager()

### getDialog

public JSVDialog getDialog(Annotation.AType type, Spectrum spec)

### getPrintLayout

public PrintLayout getPrintLayout(boolean isJob)

### setIRmode

public void setIRmode(String mode)

### getOptionFromDialog

public int getOptionFromDialog(String[] items, String title, String label)

### print

public String print(String fileName)

### export

public String export(String type, int n)

### postByteArray

public String postByteArray(String fileName, byte[] bytes)

Specified by:
  `postByteArray` in interface `BytePoster`
Parameters:
  `fileName` -
  `bytes` -
Returns:
  null or a Java exception message if there is an error; otherwise "OK" and a message

### getOutputChannel

public OC getOutputChannel(String fileName, boolean isBinary) throws Exception

Throws:
  `Exception`

### getInterface

public static Object getInterface(String name)

### showMessage

public void showMessage(String msg)

### openFileFromDialog

public boolean openFileFromDialog(boolean isAppend, boolean isURL, String simulationType, String script)

### openFile

public void openFile(String fileName, boolean closeFirst)
Opens and displays a file

Parameters:
  `fileName` -
  `closeFirst` -

### selectPanel

public int selectPanel(JSVPanel jsvp, Lst<PanelNode> panelNodes)
From (AwtMainPanel or JsMainPanel).setSelectedPanel

Parameters:
  `jsvp` -
  `panelNodes` -
Returns:
  index of selected panel

### checkAutoIntegrate

public void checkAutoIntegrate()

### parseInitScript

public void parseInitScript(String params)
Parses the JavaScript call parameters and executes them accordingly

Parameters:
  `params` - String

### getSolutionColorStr

public String getSolutionColorStr(boolean asFit)

### checkCommandLineForTip

public String checkCommandLineForTip(char c, String cmd, boolean oneLineOnly)

### checkScript

public String checkScript(String script)

### setRecentSimulation

public void setRecentSimulation(String name)

### setCreatingImage

public void setCreatingImage(boolean isSaving)

### advanceSpectrumBy

public void advanceSpectrumBy(int n)

### processPeakPickEvent

public void processPeakPickEvent(Object eventObj, boolean isApp)
this method is called as a result of the user clicking on a peak (eventObject instanceof PeakPickEvent) or from PEAK command execution

Parameters:
  `eventObj` -
  `isApp` -

### syncScript

public void syncScript(String peakScript)
/ Jmol sychronization