Ejemplo n.º 1
0
  public void saveState() {
    if (getModel() == null) {
      return;
    }

    final String group = getFileName();

    new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, BUFFER_SIZE, 0)
        .setValue(myPositionStack.size());
    new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, POSITION_IN_BUFFER, 0)
        .setValue(myCurrentPointInStack);

    final ZLIntegerOption option = new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, "", 0);
    for (int i = 0; i < myPositionStack.size(); ++i) {
      Position position = (Position) myPositionStack.get(i);
      option.changeName(PARAGRAPH_PREFIX + i);
      int paragraphIndex = position.ParagraphIndex + position.ModelIndex;
      final ArrayList models = getModelList();
      for (int j = 0; j < position.ModelIndex; j++) {
        paragraphIndex += ((ZLTextModel) models.get(j)).getParagraphsNumber();
      }

      option.setValue(paragraphIndex);

      option.changeName(CHAR_PREFIX + i);
      option.setValue(position.CharIndex);

      option.changeName(WORD_PREFIX + i);
      option.setValue(position.WordIndex);

      //			option.changeName(MODEL_PREFIX + i);
      //			option.setValue(position.ModelIndex);
    }
  }
 void reset() {
   Hashes.setValue(Collections.<String>emptyList());
   Title.setValue("");
   DownloadUrl.setValue("");
   Mimetype.setValue("");
   ThumbnailUrl.setValue("");
   Size.setValue(0);
 }
    void init(Map<String, Object> book) {
      if (book == null) {
        reset();
      } else {
        Hashes.setValue((List<String>) book.get("all_hashes"));
        Title.setValue((String) book.get("title"));

        final String downloadUrl = (String) book.get("download_url");
        DownloadUrl.setValue(downloadUrl != null ? downloadUrl : "");
        final String mimetype = (String) book.get("mimetype");
        Mimetype.setValue(mimetype != null ? mimetype : "");
        final String thumbnailUrl = (String) book.get("thumbnail_url");
        ThumbnailUrl.setValue(thumbnailUrl != null ? thumbnailUrl : "");
        final Long size = (Long) book.get("size");
        Size.setValue(size != null ? (int) (long) size : 0);
      }
    }
  public boolean updateFromServer(Map<String, Object> data) {
    System.err.println("RESPONSE = " + data);
    myGeneration.setValue((int) (long) (Long) data.get("generation"));

    final List<Map> positions = (List<Map>) data.get("positions");
    if (positions != null) {
      for (Map<String, Object> map : positions) {
        final ZLTextFixedPosition.WithTimestamp pos = map2Position(map);
        for (String hash : (List<String>) map.get("all_hashes")) {
          savePosition(hash, pos);
        }
      }
    }

    myServerBook.init((Map<String, Object>) data.get("currentbook"));

    return data.size() > 1;
  }