Package org.eclipse.rap.rwt.remote
Class JsonMapping
- java.lang.Object
-
- org.eclipse.rap.rwt.remote.JsonMapping
-
public class JsonMapping extends java.lang.Object
Provides utility methods that map common SWT types to their JSON representations used in the RAP protocol and back.- Since:
- 2.3
- See Also:
- http://wiki.eclipse.org/RAP/Protocol
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Point
readPoint(JsonValue value)
Returns an instance of Point for the given JSON representation.static Rectangle
readRectangle(JsonValue value)
Returns an instance of Rectangle for the given JSON representation.static RGB
readRGB(JsonValue value)
Returns an instance of RGB for the given JSON representation.static JsonValue
toJson(Color color)
Returns the JSON representation for the given Color.static JsonValue
toJson(Color color, int alpha)
Returns the JSON representation for the given Color with an additional alpha (opacity) value.static JsonValue
toJson(Cursor cursor)
Returns the JSON representation for the given Cursor.static JsonValue
toJson(Font font)
Returns the JSON representation for the given Font.static JsonValue
toJson(FontData fontData)
Returns the JSON representation for the given FontData.static JsonValue
toJson(Image image)
Returns the JSON representation for the given Image.static JsonValue
toJson(Point point)
Returns the JSON representation for the given Point.static JsonValue
toJson(Point[] points)
Returns the JSON representation for the given array Point.static JsonValue
toJson(Rectangle rect)
Returns the JSON representation for the given Rectangle.static JsonValue
toJson(RGB rgb)
Returns the JSON representation for the given RGB.static JsonValue
toJson(RGB rgb, int alpha)
Returns the JSON representation for the given RGB with an additional alpha (opacity) value.static JsonValue
toJson(Widget widget)
Returns the JSON representation for the given Widget.static JsonValue
toJson(Widget[] widgets)
Returns the JSON representation for the given array of widgets.
-
-
-
Method Detail
-
toJson
public static JsonValue toJson(Widget widget)
Returns the JSON representation for the given Widget. This method acceptsnull
, which will be mapped toJsonValue.NULL
. Disposed widgets cannot be mapped to JSON.- Parameters:
widget
- the widget to encode ornull
, must not be disposed- Returns:
- a JSON value that represents the given widget
-
toJson
public static JsonValue toJson(Widget[] widgets)
Returns the JSON representation for the given array of widgets. The array must not contain disposed widgets, as those cannot be mapped to JSON.- Parameters:
widgets
- the array of widgets to encode, must not benull
- Returns:
- a JSON value that represents the given widget array
- Since:
- 3.1
-
toJson
public static JsonValue toJson(Point point)
Returns the JSON representation for the given Point. This method acceptsnull
, which will be mapped toJsonValue.NULL
.- Parameters:
point
- the Point to encode ornull
- Returns:
- a JSON value that represents the given point
-
toJson
public static JsonValue toJson(Point[] points)
Returns the JSON representation for the given array Point. This method acceptsnull
, which will be mapped toJsonValue.NULL
.- Parameters:
points
- the array Point to encode ornull
- Returns:
- a JSON value that represents the given point
- Since:
- 3.13
-
toJson
public static JsonValue toJson(Rectangle rect)
Returns the JSON representation for the given Rectangle. This method acceptsnull
, which will be mapped toJsonValue.NULL
.- Parameters:
rect
- the Rectangle to encode ornull
- Returns:
- a JSON value that represents the given rectangle
-
toJson
public static JsonValue toJson(Color color)
Returns the JSON representation for the given Color. This method acceptsnull
, which will be mapped toJsonValue.NULL
. Disposed colors cannot be mapped to JSON.- Parameters:
color
- the Color to encode ornull
, must not be disposed- Returns:
- a JSON value that represents the given color
-
toJson
public static JsonValue toJson(Color color, int alpha)
Returns the JSON representation for the given Color with an additional alpha (opacity) value. This method acceptsnull
, which will be mapped toJsonValue.NULL
regardless of the given alpha value. Disposed colors cannot be mapped to JSON.- Parameters:
color
- the Color to encode ornull
, must not be disposedalpha
- a value in the range of 0 (transparent) to 255 (opaque)- Returns:
- a JSON value that represents the given color
-
toJson
public static JsonValue toJson(RGB rgb)
Returns the JSON representation for the given RGB. This method acceptsnull
, which will be mapped toJsonValue.NULL
.- Parameters:
rgb
- the Color to encode ornull
- Returns:
- a JSON value that represents the given color
-
toJson
public static JsonValue toJson(RGB rgb, int alpha)
Returns the JSON representation for the given RGB with an additional alpha (opacity) value. This method acceptsnull
, which will be mapped toJsonValue.NULL
regardless of the given alpha value.- Parameters:
rgb
- the RGB to encode ornull
alpha
- a value in the range of 0 (transparent) to 255 (opaque)- Returns:
- a JSON value that represents the given rgb
-
toJson
public static JsonValue toJson(Image image)
Returns the JSON representation for the given Image. This method acceptsnull
, which will be mapped toJsonValue.NULL
. Disposed images cannot be mapped to JSON.- Parameters:
image
- the Image to encode ornull
, must not be disposed- Returns:
- a JSON value that represents the given rgb
-
toJson
public static JsonValue toJson(Font font)
Returns the JSON representation for the given Font. This method acceptsnull
, which will be mapped toJsonValue.NULL
. Disposed fonts cannot be mapped to JSON.- Parameters:
font
- the Font to encode ornull
, must not be disposed- Returns:
- a JSON value that represents the given font
-
toJson
public static JsonValue toJson(FontData fontData)
Returns the JSON representation for the given FontData. This method acceptsnull
, which will be mapped toJsonValue.NULL
.- Parameters:
fontData
- the FontData to encode ornull
- Returns:
- a JSON value that represents the given font data
-
toJson
public static JsonValue toJson(Cursor cursor)
Returns the JSON representation for the given Cursor. This method acceptsnull
, which will be mapped toJsonValue.NULL
.- Parameters:
cursor
- the Cursor to encode ornull
- Returns:
- a JSON value that represents the given cursor
- Since:
- 3.1
-
readPoint
public static Point readPoint(JsonValue value)
Returns an instance of Point for the given JSON representation. This method returnsnull
if the given JSON value isJsonValue.NULL
.- Parameters:
value
- a JsonValue that represents a point orJsonValue.NULL
- Returns:
- a Point that corresponds to the given JSON value or
null
-
readRectangle
public static Rectangle readRectangle(JsonValue value)
Returns an instance of Rectangle for the given JSON representation. This method returnsnull
if the given JSON value isJsonValue.NULL
.- Parameters:
value
- a JsonValue that represents a rectangle orJsonValue.NULL
- Returns:
- a Rectangle that corresponds to the given JSON value or
null
-
readRGB
public static RGB readRGB(JsonValue value)
Returns an instance of RGB for the given JSON representation. This method returnsnull
if the given JSON value isJsonValue.NULL
.- Parameters:
value
- a JsonValue that represents a color orJsonValue.NULL
- Returns:
- an RGB that corresponds to the given JSON value or
null
-
-