List of usage examples for com.google.gwt.json.client JSONObject getJavaScriptObject
public JavaScriptObject getJavaScriptObject()
From source file:client.ui.components.VectorMap.java
License:Open Source License
/** * Get a {@code JavaScriptObject} containing map information as * required by the library.//from w w w .j a va2 s. co m * * @param data {@code Map} of ISO codes and values. * @return {@code JavaScriptObject} as required by the library. */ private JavaScriptObject dataToJSObject(Map<String, Double> data) { if (data == null) { return null; } JSONObject dataObject = new JSONObject(); for (Map.Entry<String, Double> entry : data.entrySet()) { dataObject.put(entry.getKey(), new JSONNumber(entry.getValue())); } return dataObject.getJavaScriptObject(); }
From source file:com.ait.lienzo.client.core.image.filter.AbstractImageDataFilter.java
License:Open Source License
protected AbstractImageDataFilter(JSONObject node, ValidationContext ctx) throws ValidationException { m_type = ClassUtils.getSimpleName(getClass()); if (null == node) { m_attr = new Attributes(this); m_meta = new MetaData(); return;//from ww w .j a v a 2 s . co m } JSONValue aval = node.get("attributes"); if (null == aval) { m_attr = new Attributes(this); } else { JSONObject aobj = aval.isObject(); if (null == aobj) { m_attr = new Attributes(this); } else { JavaScriptObject ajso = aobj.getJavaScriptObject(); if (null == ajso) { m_attr = new Attributes(this); } else { m_attr = new Attributes(ajso, this); } } } JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { NFastStringMapMixedJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } }
From source file:com.ait.lienzo.client.core.palette.AbstractPaletteBase.java
License:Open Source License
protected AbstractPaletteBase(final PaletteType type, final JSONObject node, final ValidationContext ctx) throws ValidationException { m_type = type;// w ww.ja v a2 s . c o m if (null == node) { m_attr = new Attributes(this); m_meta = new MetaData(); return; } JSONValue aval = node.get("attributes"); if (null == aval) { m_attr = new Attributes(this); } else { JSONObject aobj = aval.isObject(); if (null == aobj) { m_attr = new Attributes(this); } else { JavaScriptObject ajso = aobj.getJavaScriptObject(); if (null == ajso) { m_attr = new Attributes(this); } else { m_attr = new Attributes(ajso, this); } } } JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { NObjectJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } }
From source file:com.ait.lienzo.client.core.shape.Node.java
License:Open Source License
/** * Constructor used by deserialization code. * //from www .ja v a2s. com * @param type * @param node */ protected Node(final NodeType type, final JSONObject node, final ValidationContext ctx) throws ValidationException { m_type = type; if (null == node) { m_attr = new Attributes(this); m_meta = new MetaData(); return; } JSONValue aval = node.get("attributes"); if (null == aval) { m_attr = new Attributes(this); } else { JSONObject aobj = aval.isObject(); if (null == aobj) { m_attr = new Attributes(this); } else { JavaScriptObject ajso = aobj.getJavaScriptObject(); if (null == ajso) { m_attr = new Attributes(this); } else { m_attr = new Attributes(ajso, this); } } } JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { NFastStringMapMixedJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } }
From source file:com.ait.lienzo.client.core.shape.storage.AbstractStorageEngine.java
License:Open Source License
protected AbstractStorageEngine(final StorageEngineType type, final JSONObject node, final ValidationContext ctx) throws ValidationException { m_type = type;//from w ww . j a v a 2 s . co m final JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { final JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { final JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { final NObjectJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } }
From source file:com.ait.lienzo3d.client.shape.BaseObject3D.java
License:Open Source License
protected BaseObject3D(final Type3D type, final JSONObject node, final ValidationContext ctx) throws ValidationException { m_type = type;//from ww w. j av a2 s .c o m if (null == node) { m_attr = new Attributes3D(this); m_meta = new MetaData(); return; } JSONValue aval = node.get("attributes"); if (null == aval) { m_attr = new Attributes3D(this); } else { JSONObject aobj = aval.isObject(); if (null == aobj) { m_attr = new Attributes3D(this); } else { JavaScriptObject ajso = aobj.getJavaScriptObject(); if (null == ajso) { m_attr = new Attributes3D(this); } else { m_attr = new Attributes3D(ajso, this); } } } JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { NFastStringMapMixedJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } refresh(); }
From source file:com.ait.toolkit.clientio.uploader.client.Uploader.java
License:Apache License
/** * Convenience method for setting the 'post_params' option of the component, either before or * after the widget has been added to the DOM. Equivalent to: * <pre><code>/* ww w . ja v a 2 s . co m*/ * JSONObject params = new JSONObject(); * params.put("post_param_name_1", new JSONString("post_param_value_1")); * params.put("post_param_name_2", new JSONString("post_param_value_2")); * params.put("post_param_name_n", new JSONString("post_param_value_n")); * uploader.setOption("post_params", params); * </code></pre> * The post_params setting defines the name/value pairs that will be posted with each uploaded file. * This setting accepts a simple JavaScript object. Multiple post name/value pairs should be defined * as demonstrated in the sample settings object. Values must be either strings or numbers * (as interpreted by the JavaScript typeof function). * <p/> * Note: Flash Player 8 does not support sending additional post parameters. SWFUpload will * automatically send the post_params as part of the query string. * <p/> * * @param postParams The value to set as the 'post_params' option on the Uploader component. * @return A reference to this {@link Uploader} instance for convenient method chaining. */ public Uploader setPostParams(JSONObject postParams) { if (swfUpload != null) { nativeSetPostParams(swfUpload, postParams != null ? postParams.getJavaScriptObject() : null); } else { this.postParams = postParams; } return this.setOption("/post_params", postParams); }
From source file:com.ait.toolkit.clientio.uploader.client.Uploader.java
License:Apache License
@Override protected void onLoad() { // Make sure our entire panel fits the size that they wanted for the button if (this.buttonWidth >= 0) { this.setWidth(this.buttonWidth + "px"); }/*w w w . ja v a 2 s . c om*/ if (this.buttonHeight >= 0) { this.setHeight(this.buttonHeight + "px"); } if (ajaxUploadEnabled && isAjaxUploadWithProgressEventsSupported()) { // If the browser supports the XMLHttpRequest Level 2 type then we can avoid rendering the flash component // and just stick with a DOM/Ajax approach. // Use a hidden file input component to handle allowing the user to popup the file system dialog // (but keep it outside of the button itself so it doesn't interfere with the mouse events) this.add(createFileUpload()); // Create the main element that will hold all of the inner workings of the uploader component Label button = new Label(); button.setWidth("100%"); button.setHeight("100%"); if (this.buttonCursor != null) { switch (this.buttonCursor) { case ARROW: button.getElement().getStyle().setCursor(Style.Cursor.DEFAULT); break; case HAND: button.getElement().getStyle().setCursor(Style.Cursor.POINTER); break; } } // Setup what we want to happen when someone clicks anywhere on the button button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (buttonDisabled) { return; } switch (buttonAction) { case START_UPLOAD: startUpload(); break; case SELECT_FILES: openFileDialog(fileUpload, true); break; case SELECT_FILE: default: openFileDialog(fileUpload, false); break; } } }); button.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px -" + buttonHeight + "px"); } } }); button.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px"); } } }); button.addMouseDownHandler(new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px -" + (buttonHeight * 2) + "px"); } } }); button.addMouseUpHandler(new MouseUpHandler() { public void onMouseUp(MouseUpEvent event) { if (buttonImageURL != null && buttonHeight >= 0 && !buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px"); } } }); // Depending on the way they wanted the uploader button rendered, create the appropriate elements // in the DOM that the user will click on. if (this.buttonTextStyle != null) { buttonTextStyleElement = Document.get().createStyleElement(); buttonTextStyleElement.setInnerText(this.buttonTextStyle); button.getElement().appendChild(buttonTextStyleElement); } if (this.buttonText != null) { buttonTextElement = Document.get().createDivElement(); buttonTextElement.setInnerHTML(this.buttonText); buttonTextElement.getStyle().setWidth(100, Style.Unit.PCT); buttonTextElement.getStyle().setHeight(100, Style.Unit.PCT); if (this.buttonTextLeftPadding > Integer.MIN_VALUE) { buttonTextElement.getStyle().setPaddingLeft(this.buttonTextLeftPadding, Style.Unit.PX); } if (this.buttonTextTopPadding > Integer.MIN_VALUE) { buttonTextElement.getStyle().setPaddingTop(this.buttonTextTopPadding, Style.Unit.PX); } button.getElement().appendChild(buttonTextElement); } if (this.buttonImageURL != null) { buttonImageElement = Document.get().createDivElement(); buttonImageElement.getStyle().setBackgroundImage("url(\"" + this.buttonImageURL + "\")"); if (this.buttonDisabled) { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px -" + (buttonHeight * 3) + "px"); } else { buttonImageElement.getStyle().setProperty("backgroundPosition", "0px 0px"); } buttonImageElement.getStyle().setWidth(100, Style.Unit.PCT); buttonImageElement.getStyle().setHeight(100, Style.Unit.PCT); button.getElement().appendChild(buttonImageElement); } // Add the entire button to the DOM this.add(button); } else { // If the browser doesn't support the XMLHttpRequest Level 2 type, then our only option is to use // the Flash/SWFUpload component. // The SWFUpload JS code completely replaces the DOM element that you give it as a target, // so we're creating an inner component that it can replace - leaving the outer component // for the caller to use as the GWT Widget that they can manage and style within the appropriate // container within their GWT application DivElement swfUploadElement = Document.get().createDivElement(); swfUploadElement.setId(Document.get().createUniqueId()); this.getElement().appendChild(swfUploadElement); JavaScriptObject nativeOptions = createNativeOptions(swfUploadElement.getId()); // Build a map that we'll use during the native creation process to setup // the necessary JSNI bridges to our Java event handlers... JSONObject eventHandlers = new JSONObject(); eventHandlers.put("swfupload_loaded_handler", JSONBoolean.getInstance(swfUploadLoadedHandler != null)); eventHandlers.put("file_dialog_start_handler", JSONBoolean.getInstance(fileDialogStartHandler != null)); eventHandlers.put("file_queued_handler", JSONBoolean.getInstance(fileQueuedHandler != null)); eventHandlers.put("file_queue_error_handler", JSONBoolean.getInstance(fileQueueErrorHandler != null)); eventHandlers.put("file_dialog_complete_handler", JSONBoolean.getInstance(fileDialogCompleteHandler != null)); eventHandlers.put("upload_start_handler", JSONBoolean.getInstance(uploadStartHandler != null)); eventHandlers.put("upload_progress_handler", JSONBoolean.getInstance(uploadProgressHandler != null)); eventHandlers.put("upload_error_handler", JSONBoolean.getInstance(uploadErrorHandler != null)); eventHandlers.put("upload_success_handler", JSONBoolean.getInstance(uploadSuccessHandler != null)); eventHandlers.put("upload_complete_handler", JSONBoolean.getInstance(uploadCompleteHandler != null)); swfUpload = nativeCreateSWFUpload(nativeOptions, eventHandlers.getJavaScriptObject()); } }
From source file:com.ait.toolkit.clientio.uploader.client.Uploader.java
License:Apache License
private JavaScriptObject createNativeOptions(String placeHolderId) { JSONObject options = configurable.getOptions(); if (options == null) { options = new JSONObject(); }/*from w w w . j a v a 2s . c o m*/ // Let the SWFUpload component know which element it can render itself inside of options.put("button_placeholder_id", new JSONString(placeHolderId)); // Unless they've explicitly overridden it, automatically serve the SWF out of our modules directly (which // should be included by GWT when it compiles in all of the resources in our "public" directory) if (flashURL == null) { options.put("flash_url", new JSONString(GWT.getModuleBaseURL() + "swfupload.swf")); } // For debugging the raw options that we're passing to the component on startup, uncomment the following line // com.google.gwt.user.client.Window.alert(options.toString()); return options.getJavaScriptObject(); }
From source file:com.appspot.attractiveness.client.PersonJso.java
License:Apache License
/** * Create and populate a {@link PersonJso} object from a JSON string. * @param json the JSON string to convert * @return the {@link PersonJso} object//w w w . ja v a 2 s . c om */ public static final PersonJso fromJSON(String json) { JSONObject obj = JSONParser.parseStrict(json).isObject(); if (obj == null) return null; else return obj.getJavaScriptObject().cast(); }