Package org.apache.wicket.ajax.json

Examples of org.apache.wicket.ajax.json.JSONObject


   * @param editedElement
   * @return
   */
  private boolean handleEditedElement(String editedElement) {
    try {
      JSONObject jsonEditedElement = new JSONObject(editedElement);
      Element element = getElementObject(jsonEditedElement);

      boolean isLoaded = false;

      if (!elementMap.isEmpty() && loadedElementMap.get(element.getId()) != null && !loadedElementMap.isEmpty()) {
        isLoaded = isEqual(element.getJSON(), loadedElementMap.get(element.getId()).getJSON());
      }

      // If the edited element is not from file loaded content this clause executes
      if (!isLoaded) {

        // Adding the element creation/editing is add to the undo snapshots
        if (snapShot == null && snapShotCreation == null) {
          snapShot = new ArrayList<Element>();
          snapShotCreation = new ArrayList<Boolean>();
        }

        if (elementMap.containsKey(element.getId()) && !elementMap.isEmpty()) {
          snapShot.add(elementMap.get(element.getId()));
          snapShotCreation.add(false);

        } else {
          snapShot.add(element);
          snapShotCreation.add(true);
        }

        if (Type.PointFree != element.getType()) {
          if (undoSnapshots.size() == 20) {
            undoSnapshots.pollFirst();
            undoSnapshotCreationList.pollFirst();
          }

          if (Type.PencilCurve == element.getType()) {
            List<Element> lastElementSnapshot = undoSnapshots.peekLast();
            if (lastElementSnapshot != null) {
              Element lastSnapshotElement = lastElementSnapshot.get(lastElementSnapshot.size() - 1);
 
              if ((lastSnapshotElement instanceof PencilCurve) && (lastSnapshotElement.getId() == element.getId())) {
                List<Boolean> lastCreationSnapshot = undoSnapshotCreationList.getLast();
 
                for (int i = 0; i < snapShot.size(); i++) {
                  lastElementSnapshot.add(snapShot.get(i));
                  lastCreationSnapshot.add(snapShotCreation.get(i));
                }
              } else {
                undoSnapshots.addLast(snapShot);
                undoSnapshotCreationList.addLast(snapShotCreation);
                isElementSnapshotList.addLast(true);
              }
            }
          } else if (Type.ClipArt == element.getType()) {
            List<Element> snapShotTemp = undoSnapshots.pollLast();
            List<Boolean> snapShotCreationTemp = undoSnapshotCreationList.pollLast();

            for (int i = 0; i < snapShotTemp.size(); i++) {
              snapShot.add(snapShotTemp.get(i));
              snapShotCreation.add(snapShotCreationTemp.get(i));
            }
            undoSnapshots.addLast(snapShot);
            undoSnapshotCreationList.addLast(snapShotCreation);
            isElementSnapshotList.addLast(true);

          } else {

            undoSnapshots.addLast(snapShot);
            undoSnapshotCreationList.addLast(snapShotCreation);
            isElementSnapshotList.addLast(true);
          }

          snapShot = null;
          snapShotCreation = null;
        }

        // Synchronizing newly added/edited element between whiteboard clients
        if (element != null) {
          elementMap.put(element.getId(), element);

          IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry();
          for (IWebSocketConnection c : reg.getConnections(Application.get())) {
            try {
              JSONObject jsonObject = new JSONObject(editedElement);
              c.sendMessage(getAddElementMessage(jsonObject).toString());
            } catch (Exception e) {
              log.error("Unexpected error while sending message through the web socket", e);
            }
          }
View Full Code Here


   * @param backgroundString
   * @return
   */
  private boolean handleBackground(String backgroundString) {
    try {
      JSONObject backgroundJSON = new JSONObject(backgroundString);
      Background backgroundObject = new Background(backgroundJSON);
      background = backgroundObject;

      Background previousBackground = new Background("Background", "", 0.0, 0.0, 0.0, 0.0);
      if (whiteboardMap.get(whiteboardObjectId).getBackground() != null) {
        previousBackground = whiteboardMap.get(whiteboardObjectId).getBackground();
      }
      whiteboardMap.get(whiteboardObjectId).setBackground(background);

      undoSnapshotCreationList_Background.addLast(previousBackground == null);
      undoSnapshots_Background.addLast(previousBackground);
      isElementSnapshotList.addLast(false);

      IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry();
      for (IWebSocketConnection c : reg.getConnections(Application.get())) {
        try {
          JSONObject jsonObject = new JSONObject(backgroundString);
          c.sendMessage(getAddBackgroundMessage(jsonObject).toString());
        } catch (Exception e) {
          log.error("Unexpected error while sending message through the web socket", e);
        }
      }
View Full Code Here

   *
   * @return JSON object with field values added
   * @throws JSONException
   */
  public JSONObject getJSON() throws JSONException {
    JSONObject jsonObject = super.getJSON(new JSONObject());
    jsonObject.put("obj", obj);
    jsonObject.put("x", x);
    jsonObject.put("y", y);

    return jsonObject;
  }
View Full Code Here

        for (IWebSocketConnection c : reg.getConnections(Application.get())) {
          try {
            if (previousBackground != null) {
              c.sendMessage(getAddBackgroundMessage(previousBackground.getJSON()).toString());
            } else {
              c.sendMessage(getAddBackgroundMessage(new JSONObject()).toString());
            }
          } catch (Exception e) {
            log.error("Unexpected error while sending message through the web socket", e);
          }
        }
View Full Code Here

    if (!saveFolder.exists()) {
      saveFolder.mkdir();
    }

    boolean result = false;
    JSONObject saveObject = new JSONObject();

    JSONArray elementArray = new JSONArray();
    for (int elementID : elementMap.keySet()) {
      try {
        elementArray.put(elementMap.get(elementID).getJSON());
      } catch (JSONException e) {
        log.error("Unexpected error while getting JSON", e);
      }
    }
    JSONObject backgroundJSON = null;
    if (background != null) {
      try {
        backgroundJSON = background.getJSON();
      } catch (JSONException e) {
        log.error("Unexpected error while getting JSON", e);
View Full Code Here

      }
    }
  }

  private JSONObject getAddElementMessage(JSONObject element) throws JSONException {
    return new JSONObject().put("type", "addElement").put("json", element);
  }
View Full Code Here

  private JSONObject getAddElementMessage(JSONObject element) throws JSONException {
    return new JSONObject().put("type", "addElement").put("json", element);
  }

  private JSONObject getAddBackgroundMessage(JSONObject element) throws JSONException {
    return new JSONObject().put("type", "addBackground").put("json", element);
  }
View Full Code Here

  private JSONObject getAddBackgroundMessage(JSONObject element) throws JSONException {
    return new JSONObject().put("type", "addBackground").put("json", element);
  }

  private JSONObject getUndoMessage(JSONArray changeList, String deleteList) throws JSONException {
    return new JSONObject().put("type", "undoList").put("changeList", changeList).put("deleteList", deleteList);
  }
View Full Code Here

    return new JSONObject().put("type", "parseWB").put("json", array);
  }
  */

  private JSONObject getEraseAllMessage(JSONArray array) throws JSONException {
    return new JSONObject().put("type", "eraseElements").put("json", array);
  }
View Full Code Here

  private JSONObject getEraseAllMessage(JSONArray array) throws JSONException {
    return new JSONObject().put("type", "eraseElements").put("json", array);
  }

  private JSONObject getClipArtListMessage(JSONArray array) throws JSONException {
    return new JSONObject().put("type", "clipArtList").put("json", array);
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.ajax.json.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.