# Class MPJmolApp

java.lang.Object
org.molecularplayground.MPJmolApp

All Implemented Interfaces:
  `JsonNioClient`

public class MPJmolApp extends Object implements JsonNioClient

See Also:
  - Listens over a port on the local host for instructions on what to display. Instructions come in over the port as JSON strings. This class uses the Naga asynchronous socket network I/O package (NIO), the JSON.org JSON package and Jmol. http://code.google.com/p/naga/ Initial versions of this code, including the JSON-base protocol were created by Adam Williams, U-Mass Amherst see http://MolecularPlayground.org and org.openscience.jmol.molecularplayground.MPJmolApp.java Sent from Jmol (via outSocket): version 1: {"magic" : "JmolApp", "role" : "out"} (socket initialization for messages TO jmol) {"magic" : "JmolApp", "role" : "in"} (socket initialization for messages FROM jmol) version 2 (not implemented?: {"type" : "login", "source" : "Jmol"} (socket initialization for messages TO/FROM jmol) both versions: {"type" : "script", "event" : "done"} (script completed) Sent to Jmol (via inSocket): {"type" : "banner", "mode" : "ON" or "OFF" } (set banner for kiosk) {"type" : "banner", "text" : bannerText } (set banner for kiosk) {"type" : "command", "command" : command, "var": vname, "data":vdata} (script command request, with optional definition of a Jmol user variable prior to execution) {"type" : "content", "id" : id } (load content request) {"type" : "move", "style" : (see below) } (mouse command request) {"type" : "quit" } (shut down request) {"type" : "sync", "sync" : (see below) } (sync command request) {"type" : "touch", (a raw touch event) "eventType" : eventType, "touchID" : touchID, "iData" : idata, "time" : time, "x" : x, "y" : y, "z" : z } For details on the "touch" type, see org.jmol.viewer.ActionManagerMT::processEvent Content is assumed to be in a location determined by the Jmol variable nioContentPath, with %ID% being replaced by some sort of ID number of tag provided by the other half of the system. That file contains more JSON code: {"startup_script" : scriptFileName, "banner_text" : text } An additional option "banner" : "off" turns off the title banner. The startup script must be in the same directory as the .json file, typically as a .spt file Move commands include: {"type" : "move", "style" : "rotate", "x" : deltaX, "y" : deltaY } {"type" : "move", "style" : "translate", "x" : deltaX, "y" : deltaY } {"type" : "move", "style" : "zoom", "scale" : scale } (1.0 = 100%) {"type" : "sync", "sync" : syncText } Note that all these moves utilize the Jmol sync functionality originally intended for applets. So any valid sync command may be used with the "sync" style. These include essentially all the actions that a user can make with a mouse, including the following, where the notation invalid input: '<'....> represents a number of a given type. These events interrupt any currently running script, just as with typical mouse actions. "centerAt invalid input: '<'int:x> invalid input: '<'int:y> invalid input: '<'float:ptx> invalid input: '<'float:pty> invalid input: '<'float:ptz>" -- set {ptx,pty,ptz} at screen (x,y) "rotateMolecule invalid input: '<'float:deltaX> invalid input: '<'float:deltaY>" "rotateXYBy invalid input: '<'float:deltaX> invalid input: '<'float:deltaY>" "rotateZBy invalid input: '<'int:degrees>" "rotateZBy invalid input: '<'int:degrees> invalid input: '<'int:x> invalid input: '<'int:y>" (with center reset) "rotateArcBall invalid input: '<'int:x> invalid input: '<'int:y> invalid input: '<'float:factor>" "spinXYBy invalid input: '<'int:x> invalid input: '<'int:y> invalid input: '<'float:speed>" -- a "flick" gesture "translateXYBy invalid input: '<'float:deltaX, float:deltaY>" "zoomBy invalid input: '<'int:pixels>" "zoomByFactor invalid input: '<'float:factor>" "zoomByFactor invalid input: '<'float:factor> invalid input: '<'int:x> invalid input: '<'int:y>" (with center reset)

## Nested Class Summary

### Nested classes/interfaces inherited from interface JsonNioClient

`JsonNioClient.TouchHandler`

## Field Summary

Fields
Modifier and Type
Field
Description
`boolean`
`contentDisabled`
`boolean`
`motionDisabled`
`protected JsonNioServer`
`service`
`protected Viewer`
`vwr`

### Fields inherited from interface JsonNioClient

`TYPES`

## Constructor Summary

Constructors
Constructor
Description
`MPJmolApp()`
`MPJmolApp(int port)`

## Method Summary

Modifier and Type
Method
Description
`double`
`getDouble(Map<String,Object> map, String key)`
`int`
`getInt(Map<String,Object> map, String key)`
`static String`
`getJmolValueAsString(Viewer vwr, String var)`
`long`
`getLong(Map<String,Object> map, String key)`
`static void`
`main(String[] args)`
`void`
`nioClosed(JsonNioServer jns)`
`void`
`processNioMessage(byte[] packet)`
`void`
`scriptCallback(String msg)`
`void`
`serverCycle()`
`void`
`setBannerLabel(String label)`

### Methods inherited from class Object

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

## Field Details

### vwr

protected Viewer vwr

### motionDisabled

public boolean motionDisabled

### contentDisabled

public boolean contentDisabled

### service

protected JsonNioServer service

## Constructor Details

### MPJmolApp

public MPJmolApp()

### MPJmolApp

public MPJmolApp(int port)

## Method Details

### main

public static void main(String[] args)

### setBannerLabel

public void setBannerLabel(String label)

### nioClosed

public void nioClosed(JsonNioServer jns)

Specified by:
  `nioClosed` in interface `JsonNioClient`

### processNioMessage

public void processNioMessage(byte[] packet) throws Exception

Specified by:
  `processNioMessage` in interface `JsonNioClient`
Throws:
  `Exception`

### getJmolValueAsString

public static String getJmolValueAsString(Viewer vwr, String var)

### scriptCallback

public void scriptCallback(String msg)

### serverCycle

public void serverCycle()

Specified by:
  `serverCycle` in interface `JsonNioClient`

### getLong

public long getLong(Map<String,Object> map, String key) throws Exception

Throws:
  `Exception`

### getInt

public int getInt(Map<String,Object> map, String key) throws Exception

Throws:
  `Exception`

### getDouble

public double getDouble(Map<String,Object> map, String key) throws Exception

Throws:
  `Exception`