Package org.zkoss.json

Examples of org.zkoss.json.JSONObject


 
  private LoadResult loadEast(Worksheet sheet,String type,
      int blockLeft,int blockTop,int blockRight, int blockBottom,
      int fetchWidth, int rangeWidth, int rangeTopHeight, int rangeBtmHeight) {

    JSONObject json = new JSONObject();
    json.put("type", "neighbor");
    json.put("width", fetchWidth);
    json.put("height", blockBottom - blockTop + 1); //the range of height to generate DOM
   
    //append row
    int cs = blockRight + 1;
    int ce = cs + fetchWidth;
    json.put("top", blockTop);
    json.put("left", cs);
   
    int rangeTop = rangeTopHeight > 0 ? blockTop - rangeTopHeight + 1 : blockTop;
    int rangeRight = rangeWidth > fetchWidth ? cs + rangeWidth - 1 : ce - 1;
    int rangeBottom = rangeBtmHeight < 0 ? blockBottom : blockBottom + rangeBtmHeight - 1;
    final SpreadsheetCtrl spreadsheetCtrl = ((SpreadsheetCtrl) _spreadsheet.getExtraCtrl());
    JSONObject mainBlock = spreadsheetCtrl.getRangeAttrs(sheet, _hidecolhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.COLUMN,
        SpreadsheetCtrl.CellAttribute.ALL, cs, rangeTop, rangeRight, rangeBottom);
    mainBlock.put("dir", "east");
    json.put("data", mainBlock);
 
    _lastleft = blockLeft;
    _lastright = ce - 1;
    _lasttop = blockTop;
    _lastbottom = blockBottom;

    //process frozen row data
    int fzr = _spreadsheet.getRowfreeze();
    if (fzr > -1) {
      mainBlock.put("topFrozen", spreadsheetCtrl.getRangeAttrs(sheet, _hiderowhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.BOTH, SpreadsheetCtrl.CellAttribute.ALL,
          cs, 0, rangeRight, fzr));
    }
    return new LoadResult(cs, rangeTop, rangeRight, rangeBottom, json);
  }
View Full Code Here


 
  private LoadResult loadWest(Worksheet sheet,String type,
      int blockLeft,int blockTop,int blockRight, int blockBottom,
      int fetchWidth, int rangeWidth, int rangeTopHeight, int rangeBtmHeight) {
   
    JSONObject json = new JSONObject();
    json.put("type", "neighbor");
    json.put("width", fetchWidth);// increased cell size
    json.put("height", blockBottom - blockTop + 1);// increased cell size
   
    // append row
    int cs = blockLeft - 1;
    int ce = cs - fetchWidth;
    json.put("top", blockTop);
    json.put("left", ce + 1);
   
    int rangeTop = rangeTopHeight > 0 ? blockTop - rangeTopHeight + 1 : blockTop;
    int rangeLeft = rangeWidth > fetchWidth ? blockLeft - rangeWidth - 1: ce + 1;
    if (rangeLeft < 0)
      rangeLeft = 0;
    int rangeBottom = rangeBtmHeight < 0 ? blockBottom : blockBottom + rangeBtmHeight - 1;
    final SpreadsheetCtrl spreadsheetCtrl = ((SpreadsheetCtrl) _spreadsheet.getExtraCtrl());
    JSONObject mainBlock = spreadsheetCtrl.getRangeAttrs(sheet, _hidecolhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.COLUMN,
        SpreadsheetCtrl.CellAttribute.ALL, rangeLeft, rangeTop, cs, rangeBottom);
    mainBlock.put("dir", "west");
    json.put("data", mainBlock);
   
    _lastleft = ce+1;
    _lastright = blockRight;
    _lasttop = blockTop;
    _lastbottom = blockBottom;
   
    // process frozen row data
    int fzr = _spreadsheet.getRowfreeze();
    if (fzr > -1) {
      mainBlock.put("topFrozen", spreadsheetCtrl.getRangeAttrs(sheet, _hiderowhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.BOTH, SpreadsheetCtrl.CellAttribute.ALL,
          rangeLeft, 0, cs, fzr));
    }
    return new LoadResult(rangeLeft, rangeTop, cs, rangeBottom, json);
  }
View Full Code Here

  }
 
  private LoadResult loadSouth(Worksheet sheet, String type,
      int blockLeft,int blockTop, int blockRight, int blockBottom, int fetchHeight, int rangeLeft, int cacheRight, int cacheRangeHeight) {
   
    JSONObject json = new JSONObject();
    json.put("type", "neighbor");
    json.put("width", blockRight - blockLeft + 1);
    json.put("height", fetchHeight);

    int rs = blockBottom + 1;
    int re = rs + fetchHeight;
    json.put("top", rs);
    json.put("left", blockLeft);
   
    int rangeBottom = Math.min(cacheRangeHeight > fetchHeight ? rs + cacheRangeHeight - 1 : re - 1, _spreadsheet.getMaxrows() - 1);
    rangeLeft = rangeLeft > 0 && rangeLeft < blockLeft ? rangeLeft : blockLeft;
    cacheRight = Math.max(blockRight, cacheRight);
    final SpreadsheetCtrl spreadsheetCtrl = ((SpreadsheetCtrl) _spreadsheet.getExtraCtrl());
    JSONObject mainBlock = spreadsheetCtrl.getRangeAttrs(sheet, _hidecolhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.ROW, SpreadsheetCtrl.CellAttribute.ALL,
        rangeLeft, rs, cacheRight, rangeBottom);
    mainBlock.put("dir", "south");
    json.put("data", mainBlock);

    _lastleft = blockLeft;
    _lastright = blockRight;
    _lasttop = blockTop;
    _lastbottom = re-1;
   
    // process frozen left
    int fzc = _spreadsheet.getColumnfreeze();
    if (fzc > -1) {
      mainBlock.put("leftFrozen", spreadsheetCtrl.getRangeAttrs(sheet, _hidecolhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.BOTH, SpreadsheetCtrl.CellAttribute.ALL,
          0, rs, fzc, rangeBottom));
    }

    return new LoadResult(rangeLeft, rs, cacheRight, rangeBottom, json);
  }
View Full Code Here

  }
  private LoadResult loadNorth(Worksheet sheet,String type,
      int blockLeft, int blockTop, int blockRight, int blockBottom,
      int fetchHeight, int rangeLeft, int rangeRight, int cacheRangeHeight) {

    JSONObject json = new JSONObject();
    json.put("type", "neighbor");
    json.put("width", blockRight - blockLeft + 1);
    json.put("height", fetchHeight);
   
    int rs = blockTop - 1;
    int re = rs - fetchHeight;
    json.put("top", re + 1);
    json.put("left", blockLeft);
   
    int rangeTop = cacheRangeHeight > fetchHeight ? rs - cacheRangeHeight - 1 : re + 1;
    rangeLeft = rangeLeft > 0 && rangeLeft < blockLeft ? rangeLeft : blockLeft;
//    rangeRight = Math.min(Math.max(blockRight, rangeRight), _spreadsheet.getMaxcolumns() - 1);
    rangeRight = Math.max(blockRight, rangeRight);
    final SpreadsheetCtrl spreadsheetCtrl = ((SpreadsheetCtrl) _spreadsheet.getExtraCtrl());
    JSONObject mainBlock = spreadsheetCtrl.getRangeAttrs(sheet, _hidecolhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.ROW, SpreadsheetCtrl.CellAttribute.ALL,
        rangeLeft, rangeTop, rangeRight, rs);
    mainBlock.put("dir", "north");
    json.put("data", mainBlock);
   
    _lastleft = blockLeft;
    _lastright = blockRight;
    _lasttop = re + 1;
    _lastbottom = blockBottom;
   
    // process frozen left
    int frc = _spreadsheet.getColumnfreeze();
    if (frc > -1) {
      mainBlock.put("leftFrozen", spreadsheetCtrl.getRangeAttrs(sheet, _hidecolhead ? SpreadsheetCtrl.Header.NONE : SpreadsheetCtrl.Header.BOTH, SpreadsheetCtrl.CellAttribute.ALL,
          0, rangeTop, frc, rs));
    }
    return new LoadResult(rangeLeft, rangeTop, rangeRight, rs, json);
  }
View Full Code Here

     * @param start
     * @param end
     * @return
     */
    private JSONObject getHeaderAttrs(Worksheet sheet, boolean isRow, int start, int end) {
      JSONObject attrs = new JSONObject();
      attrs.put("s", start);
      attrs.put("e", end);
     
      JSONArray headers = new JSONArray();
      attrs.put("hs", headers);
      if (isRow) {
        attrs.put("t", "r"); //type: row
        for (int row = start; row <= end; row++) {
          headers.add(getRowHeaderAttrs(sheet, row));
        }
      } else { //column header
        attrs.put("t", "c"); //type: column
        for (int col = start; col <= end; col++) {
          headers.add(getColumnHeaderAttrs(sheet, col));
        }
      }
      return attrs;
View Full Code Here

     * </ul>
     *
     * @return
     */
    private JSONObject getColumnHeaderAttrs(Worksheet sheet, int col) {
      JSONObject attrs = new JSONObject();
//      attrs.put("i", col);//getHeaderAttrs method has provide index info
      attrs.put("t", Spreadsheet.this.getColumntitle(col));

      HeaderPositionHelper colHelper = Spreadsheet.this.getColumnPositionHelper(sheet);
      HeaderPositionInfo info = colHelper.getInfo(col);
      if (info != null) {
        attrs.put("p", info.id);
//        if (info.size != defaultSize) {
//          attrs.put("s", info.size);
//        }
//        if (info.hidden) {
//          attrs.put("h", 1); //1 stand for true;
View Full Code Here

     * </ul>
     *
     * @return
     */
    private JSONObject getRowHeaderAttrs(Worksheet sheet, int row) {
      JSONObject attrs = new JSONObject();
//      attrs.put("i", row);//getHeaderAttrs method has provide index info
      attrs.put("t", Spreadsheet.this.getRowtitle(row));

      HeaderPositionHelper rowHelper = Spreadsheet.this.getRowPositionHelper(sheet);
      HeaderPositionInfo info = rowHelper.getInfo(row);
      if (info != null) {
        attrs.put("p", info.id);
//        if (info.hidden)
//          attrs.put("h", 1);
      }
      return attrs;
    }
View Full Code Here

     * @param bottom
     * @param containsHeader
     * @return
     */
    public JSONObject getRangeAttrs(Worksheet sheet, Header containsHeader, CellAttribute type, int left, int top, int right, int bottom) {
      JSONObject attrs = new JSONObject();
     
      attrs.put("id", ((SheetCtrl)sheet).getUuid());
     
      attrs.put("l", left);
      attrs.put("t", top);
      attrs.put("r", right);
      attrs.put("b", bottom);
      attrs.put("at", type);
     
      JSONArray rows = new JSONArray();
      attrs.put("rs", rows);
     
      StringAggregation styleAggregation = new StringAggregation();
      StringAggregation textAggregation = new StringAggregation();
      MergeAggregation mergeAggregation = new MergeAggregation(getMergeMatrixHelper(sheet));
      for (int row = top; row <= bottom; row++) {
        JSONObject r = getRowAttrs(row);
        rows.add(r);
       
        JSONArray cells = new JSONArray();
        r.put("cs", cells);
        for (int col = left; col <= right; col++) {
          cells.add(getCellAttr(sheet, type, row, col, styleAggregation, textAggregation, mergeAggregation));
        }
      }
     
View Full Code Here

     * </ul>
     */
    public JSONObject getRowAttrs(int row) {
      Worksheet sheet = getSelectedSheet();
      HeaderPositionHelper helper = Spreadsheet.this.getRowPositionHelper(sheet);
      JSONObject attrs = new JSONObject();
      //row num
      attrs.put("r", row);
     
      HeaderPositionInfo info = helper.getInfo(row);
      if (info != null) {
        attrs.put("h", info.id);
        if (info.hidden) {
          attrs.put("hd", "t"); //t stand for true
        }
      }
      return attrs;
    }
View Full Code Here

        updateStyle = (updateAll || type == CellAttribute.STYLE),
        updateSize = (updateAll || type == CellAttribute.SIZE),
        updateMerge = (updateAll || type == CellAttribute.MERGE);
     
      Cell cell = Utils.getCell(sheet, row, col);
      JSONObject attrs = new JSONObject();
     
      //row num, cell num attr
//      if (cell != null) {
//        attrs.put("r", row);
//        attrs.put("c", col);
//      }
     
      //merge
      MergeIndex mergeIndex = mergeAggregation.add(row, col);
      if (updateMerge && mergeIndex != null) {
        attrs.put("mi", mergeIndex.getMergeId());
        attrs.put("mc", mergeIndex.getMergeCSSId());
      }
     
      //width, height id
      if (updateSize) {
        if (cell != null) {
          //process overflow when cell type is string, halign is left, no wrap, no merge
          CellStyle cellStyle = cell.getCellStyle();
          if (cell.getCellType() == Cell.CELL_TYPE_STRING &&
            mergeIndex == null && !cellStyle.getWrapText() &&
            BookHelper.getRealAlignment(cell) == CellStyle.ALIGN_LEFT) {
           
            attrs.put("ovf", 1); //1 stand for true
            int c = getMaxOverflowableCellIndex(cell, sheet.getRow(row));
            if (c != col) {
              attrs.put("moc", c);
            }
          }
        }
      }
     
      //style attr
      if (updateStyle) {
        CellFormatHelper cfh = new CellFormatHelper(sheet, row, col, getMergeMatrixHelper(sheet));
        String style = cfh.getHtmlStyle();
        if (!Strings.isEmpty(style)) {
          int idx = styleAggregation.add(style);
          attrs.put("s", idx);
        }
        String innerStyle = cfh.getInnerHtmlStyle();
        if (!Strings.isEmpty(innerStyle)) {
          int idx = styleAggregation.add(innerStyle);
          attrs.put("is", idx);
        }
        if (cfh.hasRightBorder()) {
          attrs.put("rb", 1);
        }
      }
     
      if (cell != null) {
        int cellType = cell.getCellType();
        if (cellType != Cell.CELL_TYPE_BLANK)
          attrs.put("ct", cellType);
       
        if (updateText) {
          if (cellType != Cell.CELL_TYPE_BLANK) {
            final String cellText = getCelltext(sheet, row, col);
            final String editText = getEdittext(sheet, row, col);
            final String formatText = getCellFormatText(sheet, row, col);
           
            if (Objects.equals(cellText, editText) && Objects.equals(editText, formatText)) {
              attrs.put("meft", textAggregation.add(cellText));
            } else {
              attrs.put("t", textAggregation.add(cellText));
              attrs.put("et", textAggregation.add(editText));
              attrs.put("ft", textAggregation.add(formatText));
            }
          }
        }
       
        if (updateStyle) {
          CellStyle cellStyle = cell.getCellStyle();
          boolean locked = cellStyle.getLocked();
          if (!locked)
            attrs.put("l", "f"); //f stand for "false"
         
          boolean wrap = cellStyle.getWrapText();
          if (wrap)
            attrs.put("wp", 1);
         
          int horizontalAlignment = BookHelper.getRealAlignment(cell);
          switch(horizontalAlignment) {
          case CellStyle.ALIGN_CENTER:
          case CellStyle.ALIGN_CENTER_SELECTION:
            attrs.put("ha", "c");
            break;
          case CellStyle.ALIGN_RIGHT:
            attrs.put("ha", "r");
            break;
          }
         
          int verticalAlignment = cellStyle.getVerticalAlignment();
          switch(verticalAlignment) {
          case CellStyle.VERTICAL_TOP:
            attrs.put("va", "t");
            break;
          case CellStyle.VERTICAL_CENTER:
            attrs.put("va", "c");
            break;
          //case CellStyle.VERTICAL_BOTTOM: //default
          //  break;
          }
         
          Font font = _book.getFontAt(cellStyle.getFontIndex());
          short fontHeight = font.getFontHeightInPoints();
          if (fontHeight != XSSFFont.DEFAULT_FONT_SIZE) {
            attrs.put("fs", fontHeight);
          }
        }
      }
      return attrs;
    }
View Full Code Here

TOP

Related Classes of org.zkoss.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.