Package com.google.gwt.json.client

Examples of com.google.gwt.json.client.JSONObject


          (int)jsonStep.get(Step.CORNER_Y_KEY).isNumber().doubleValue(),
          parseTasks(jsonStep), handlers[i]);
    }
  }
  private TaskBuilder[] parseTasks(JSONObject jsonStep) {
    JSONObject jsonTasks=jsonStep.get(TaskBuilder.TASKS_KEY).isObject();
    TaskBuilder[] builders=new TaskBuilder[jsonTasks.size()];
    int i=0;
    if(jsonTasks.containsKey(TaskBuilder.ButtonBuilder.BUTTON_KEY)){
      builders[i++]=new TaskBuilder.ButtonBuilder();
    }
   
    if(jsonTasks.containsKey(TaskBuilder.BlueMarkBuilder.MARK_KEY)){
      JSONObject jsonMark=jsonTasks.get(TaskBuilder.BlueMarkBuilder.MARK_KEY).isObject();
      builders[i++]=new TaskBuilder.BlueMarkBuilder((int) jsonMark.get(TaskBuilder.BlueMarkBuilder.INDEX_KEY).isNumber().doubleValue(),
                              jsonMark.get(TaskBuilder.BlueMarkBuilder.X_KEY).isNumber().doubleValue(),
                              jsonMark.get(TaskBuilder.BlueMarkBuilder.Y_KEY).isNumber().doubleValue(),
                              jsonMark.get(TaskBuilder.BlueMarkBuilder.ANGLE_KEY).isNumber().doubleValue());
    }
   
    if(jsonTasks.containsKey(TaskBuilder.TaskListBuilder.LIST_KEY)){
      JSONObject jsonList=jsonTasks.get(TaskBuilder.TaskListBuilder.LIST_KEY).isObject();
      builders[i++]=new TaskBuilder.TaskListBuilder((int)jsonList.get(TaskBuilder.TaskListBuilder.HEIGHT_KEY).isNumber().doubleValue(),
                              (int)jsonList.get(TaskBuilder.TaskListBuilder.Y_KEY).isNumber().doubleValue(),
                              (int)jsonList.get(TaskBuilder.TaskListBuilder.NUM_KEY).isNumber().doubleValue());
    }
    return builders;
  }
View Full Code Here


  }
  public static class CrossBuilder implements LevelBuilder{

    @Override
    public void build(JSONObject creation) {
      JSONObject pos=creation.get(POSITION).isObject();
      new Cross(
          new Point(pos.get(X).isNumber().doubleValue(),
                 pos.get(Y).isNumber().doubleValue()),
          Math.toRadians(creation.get(ANGLE).isNumber().doubleValue()));
                
     
    }
View Full Code Here

  }
  public static class RedGobletBuilder implements LevelBuilder{
   
    @Override
    public void build(JSONObject creation) {
      JSONObject pos=creation.get(POSITION).isObject();
      new RedGoblet(
          new Point(pos.get(X).isNumber().doubleValue(),
                 pos.get(Y).isNumber().doubleValue()),
                Math.toRadians(creation.get(ANGLE).isNumber().doubleValue()),
               (int)creation.get("gAng").isNumber().doubleValue());
    }
View Full Code Here

 
  public static class ArrowAreaBuilder extends AreaBuilder{

    @Override
    public void buildArea(JSONObject jsonArea) {
      JSONObject pos=jsonArea.get(POSITION).isObject();
      new ArrowArea(
          new Point(pos.get(X).isNumber().doubleValue(),
                pos.get(Y).isNumber().doubleValue()),
                Math.toRadians(jsonArea.get(ANGLE).isNumber().doubleValue()),
                jsonArea.get("r").isNumber().doubleValue());
     
    }
View Full Code Here

    this.gravityAngle=(int)jsonContext.get("gravityAng").isNumber().doubleValue();
    this.fullPower=(int)jsonContext.get("fullPower").isNumber().doubleValue();
    this.requiredScore=(int)jsonContext.get("reqScore").isNumber().doubleValue();
    this.hint=jsonContext.get("hint").isBoolean().booleanValue();
   
    JSONObject bounds=jsonContext.get("bounds").isObject();
    this.width = bounds.get("width").isNumber().doubleValue();
    this.height = bounds.get("height").isNumber().doubleValue();
   
    JSONObject camera=jsonContext.get("camera").isObject();
    this.viewPoint = new Point(camera.get(X).isNumber().doubleValue(),
                   camera.get(Y).isNumber().doubleValue());
    JSONArray defs;
    int i;
   
    defs=jsonContext.get("areaDefs").isArray();
    areaDefs=new String[defs.size()];
View Full Code Here

  @Override
  public String toString(){
    return world.getTitle()+"-"+levelNumber;
  }
  public void buildLevel(){
    JSONObject levelCreations=jsonContext.get("creations").isObject();
    JSONValue unknownCreation;
    LevelBuilder builder;
   
    JSONArray creationArray;
   
    int i;
   
    for(String key:levelCreations.keySet()){
      unknownCreation=levelCreations.get(key);
      builder=BUILDER_MAP.get(key);
      if(unknownCreation.isArray()!=null){
        creationArray=unknownCreation.isArray();
       
        for(i=0;i<creationArray.size();i++){
View Full Code Here

                // if I get this exception it means I shouldn't strip out the html
                // this issue still needs more research
                Log.debug("Failed to strip out HTML.  This should be preferred?");
            }
            try {
                JSONObject response = JSONParser.parseLenient(json).isObject();
                JSONString outcome = response.get("outcome").isString();
                if (outcome != null && "success".equalsIgnoreCase(outcome.stringValue())) {
                    patchManager.getPatches(new SimpleCallback<Patches>() {
                        @Override
                        public void onSuccess(final Patches result) {
                            context.patchInfo = result.getLatest();
                            wizard.next();
                        }
                    });
                } else {
                    context.patchFailedDetails = stringify(response.getJavaScriptObject(), 2);
                    // TODO conflict detection could be improved!?
                    if (context.patchFailedDetails.contains("conflicts")) {
                        context.conflict = true;
                    } else {
                        context.patchFailed = true;
View Full Code Here

        long startTime = System.currentTimeMillis();
        int initSize = knownMarkers.size();
        List<String> markersFromThisUpdate = new ArrayList<String>();

        for (int i = 0; i < array.size(); i++) {
          JSONObject jsMarker;
          JSONString jsMID, jsTitle, jsIcon;
          JSONNumber jsLat, jsLng;
          JSONBoolean jsVisible, jsHasInfo, jsDraggable;
          Marker marker = null;
          boolean isOldMarker = false;
          boolean replaceMarker = false;

          if ((jsMarker = array.get(i).isObject()) == null) {
            continue;
          }

          // Read marker id
          if ((value = jsMarker.get("mid")) == null) {
            continue;
          }
          if ((jsMID = value.isString()) == null) {
            continue;
          }

          if ((value = jsMarker.get("draggable")) == null) {
            continue;
          } else {
            if (knownMarkers.containsKey(jsMID.toString())) {
              marker = knownMarkers.get(jsMID.toString());
              marker.setDraggingEnabled((((JSONBoolean) jsMarker
                  .get("draggable")).booleanValue()));
              isOldMarker = true;
            }
          }

          // Add maker to list of markers in this update
          markersFromThisUpdate.add(jsMID.toString());

          // Read marker latitude
          if ((value = jsMarker.get("lat")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsLat = value.isNumber()) == null) {
            if (!isOldMarker)
              continue;
          }

          // Read marker longitude
          if ((value = jsMarker.get("lng")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsLng = value.isNumber()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            // marker.setLatLng(jsLng.doubleValue());
          }

          // Read marker title
          if ((value = jsMarker.get("title")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsTitle = value.isString()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            if (isOldMarker && marker != null) {
              String title = marker.getTitle();

              // if title is changed
              if (!jsTitle.stringValue().equals(title)) {
                replaceMarker = true;
                log(1, "Title changed: " + marker.getTitle());
              }
            }
          }

          // Read marker visibility
          if ((value = jsMarker.get("visible")) == null) {
            if (!isOldMarker)
              continue;
          }
          if ((jsVisible = value.isBoolean()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            if (marker != null) {
              boolean old = marker.isVisible();

              marker.setVisible(jsVisible.booleanValue());

              if (old != marker.isVisible()) {
                log(1,
                    "Toggled marker '" + marker.getTitle()
                        + "' visibility to "
                        + jsVisible.booleanValue());
              }
            }
          }

          // Read marker draggability (is that a word? :)
          if ((value = jsMarker.get("draggable")) == null) {
            if (!isOldMarker)
              continue;
          }

          if ((jsDraggable = value.isBoolean()) == null) {
            if (!isOldMarker)
              continue;
          }

          // Change position, if changed
          if (marker != null && jsLat != null && jsLng != null
              && marker.getLatLng() != null) {
            LatLng llang = marker.getLatLng();

            LatLng llang2 = LatLng.newInstance(jsLat.doubleValue(),
                jsLng.doubleValue());
            if (!llang.isEquals(llang2)) {
              marker.setLatLng(llang2);
            }
          }

          // Read marker icon
          if ((value = jsMarker.get("icon")) == null) {
            jsIcon = null;
            if (marker != null) {
              String currentURL = getMarkerIconURL(marker);
              if (!currentURL
                  .startsWith("http://maps.gstatic.com")
                  && currentURL != null && currentURL != "") {
                replaceMarker = true;
                log(1, "Icon url changed " + marker.getTitle()
                    + " from '" + currentURL + "'");
              }
            }
          } else if ((jsIcon = value.isString()) == null) {
            if (!isOldMarker)
              continue;
          } else {
            if (marker != null
                && getMarkerIconURL(marker) != jsIcon
                    .toString()) {
              replaceMarker = true;
              log(1, "Icon url changed 2 " + marker.getTitle());
            }
          }

          int iconAnchorX = 0;
          if ((value = jsMarker.get("iconAnchorX")) != null) {
            JSONNumber jsAnchorX;
            if ((jsAnchorX = value.isNumber()) != null) {
              log(1, "Anchor X: " + jsAnchorX.toString());
              iconAnchorX = (int) Math.round(jsAnchorX
                  .doubleValue());
            } else {
              log(1, "Anchor X NaN");
            }
          }

          int iconAnchorY = 0;
          if ((value = jsMarker.get("iconAnchorY")) != null) {
            JSONNumber jsAnchorY;
            if ((jsAnchorY = value.isNumber()) != null) {
              iconAnchorY = (int) Math.round(jsAnchorY
                  .doubleValue());
            }
          }

          // do not create new one if old found (only if we want to
          // replace it)
          if (isOldMarker && !replaceMarker)
            continue;

          if (!isOldMarker)
            replaceMarker = false; // Never replace a marker if
                        // there is no previous one

          if (replaceMarker) {
            log(1, "Replacing marker " + marker.getTitle());
            map.removeOverlay(marker);
            markersFromThisUpdate.remove(marker);
          }

          marker = createMarker(jsLat, jsLng, jsTitle, jsVisible,
              jsIcon, iconAnchorX, iconAnchorY, jsDraggable);

          if (marker != null) {
            map.addOverlay(marker);

            // Add dragEnd handlers to marker
            marker.addMarkerDragEndHandler(VGoogleMap.this);

            // Read boolean telling if marker has a info window
            if ((value = jsMarker.get("info")) != null) {
              if ((jsHasInfo = value.isBoolean()) != null
                  && jsHasInfo.booleanValue()) {
                marker.addMarkerClickHandler(new InfoWindowOpener(
                    jsMID.stringValue()));
View Full Code Here

    return "s:" + value.toString();
  }

  @SuppressWarnings("unchecked")
  protected static JSONObject encodeMap(Map<String, Object> data) {
    JSONObject jsobj = new JSONObject();
    for (String key : data.keySet()) {
      Object val = data.get(key);
      if (val instanceof String) {
        jsobj.put(key, new JSONString(encodeValue(val)));
      } else if (val instanceof Date) {
        jsobj.put(key, new JSONString(encodeValue(val)));
      } else if (val instanceof Number) {
        jsobj.put(key, new JSONString(encodeValue(val)));
      } else if (val instanceof Boolean) {
        jsobj.put(key, JSONBoolean.getInstance((Boolean) val));
      } else if (val == null) {
        jsobj.put(key, JSONNull.getInstance());
      } else if (val instanceof Map) {
        jsobj.put(key, encodeMap((Map<String, Object>) val));
      } else if (val instanceof List) {
        jsobj.put(key, encodeList((List<Object>) val));
      } else if (val instanceof ModelData) {
        jsobj.put(key, encodeMap(((ModelData) val).getProperties()));
      }
    }

    return jsobj;
  }
View Full Code Here

      }
    }
    model.updateYScale();

    JavaScriptObject jso = Util.getJsObject(model, 8);
    JSONObject json = new JSONObject(jso);
    setJsonData(json.toString());
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.json.client.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.