/** Updates the contour data my directly copying values. */ void updateDirect(GridData griddata) { if (griddata == null) { return; } if (autoscaleZ) { double[] minmax = griddata.getZRange(ampIndex); zmax = minmax[1]; zmin = minmax[0]; if (zMap != null) { zMap.setMinMax(zmin, zmax); } colorMap.setScale(zmin, zmax); } if (griddata instanceof ArrayData) { double[][] arrayData = griddata.getData()[ampIndex]; for (int i = 0; i < nx; i++) { // copy the rows System.arraycopy(arrayData[i], 0, internalData[i], 0, ny); if (zMap != null) { for (int j = 0; j < ny; j++) { internalData[i][j] = zMap.evaluate(internalData[i][j]); } } } } else if (griddata instanceof GridPointData) { double[][][] ptdata = griddata.getData(); for (int i = 0, nx = ptdata.length; i < nx; i++) { for (int j = 0, ny = ptdata[0].length; j < ny; j++) { internalData[i][j] = ptdata[i][j][2 + ampIndex]; if (zMap != null) { internalData[i][j] = zMap.evaluate(internalData[i][j]); } } } } }
/** * Sets the data storage to the given value. * * @param _griddata */ public void setGridData(GridData _griddata) { griddata = _griddata; if (griddata == null) { return; } nx = (interpolateLargeGrids && (griddata.getNx() > maxGridSize)) ? 32 : griddata.getNx(); ny = (interpolateLargeGrids && (griddata.getNy() > maxGridSize)) ? 32 : griddata.getNy(); internalData = new double[nx][ny]; }
/** * Sets the values and the scale. * * <p>The grid is resized to fit the new data if needed. * * @param obj array of new values * @param xmin double * @param xmax double * @param ymin double * @param ymax double */ public void setAll(Object obj, double xmin, double xmax, double ymin, double ymax) { double[][] val = (double[][]) obj; copyData(val); if (griddata.isCellData()) { griddata.setCellScale(xmin, xmax, ymin, ymax); } else { griddata.setScale(xmin, xmax, ymin, ymax); } update(); }
/** Updates the contour data. */ public void update() { if (griddata == null) { return; } if ((interpolateLargeGrids && (nx != griddata.getNx())) || (ny != griddata.getNy())) { updateInterpolated(griddata); } else { updateDirect(griddata); } colorMap.updateLegend(zMap); }
private void copyData(double val[][]) { if ((griddata != null) && !(griddata instanceof ArrayData)) { throw new IllegalStateException( "SetAll only supports ArrayData for data storage."); //$NON-NLS-1$ } if ((griddata == null) || (griddata.getNx() != val.length) || (griddata.getNy() != val[0].length)) { griddata = new ArrayData(val.length, val[0].length, 1); setGridData(griddata); } double[][] data = griddata.getData()[0]; int ny = data[0].length; for (int i = 0, nx = data.length; i < nx; i++) { System.arraycopy(val[i], 0, data[i], 0, ny); } }
/** GridData 구조에 JSON전문의 params에 대한 데이터를 입력한다. */ public static void setJsonParamData( GridData gridData, List<LinkedHashMap<String, String>> paramsList) throws Exception { // logger.info("params : " + paramsList); // logger.info("params count : " + paramsList.size()); for (LinkedHashMap<String, String> param : paramsList) { gridData.addParam(param.get(json_params_name_key), param.get(json_common_value)); // logger.info("param entry : " + param.entrySet()); } }
/** * RealGrid 의 JSON전문을 GridData 객체로 전환한다. * * <p>1. request 전문의 mode, rows, headers로 구분하여 파싱 및 WiseGrid 데이터 구조에 Set 한다. * * @param rawData request 로 올라온 RealGrid 의 JSON전문 * @return GridData JSON전문을 파싱하여 WiseGrid 의 자료구조에 맞춰 반환 * @throws Exception * @since v1, 0, 0, 0 */ public static GridData parse(String rawData) throws Exception { LinkedHashMap<String, Object> jsonDataMap = new ObjectMapper().readValue(rawData, LinkedHashMap.class); GridData gridData = new GridData(); String gridMode = ""; // JSON 전문의 mode, params, headers로 구분하여 파싱한다. for (String dataKey : jsonDataMap.keySet()) { // 모드 입력 if (json_mode.equals(dataKey)) { // logger.info("--------------------------- JSON전문의 mode를 GridData구조에 입력한다. // --------------------------------"); gridMode = (String) jsonDataMap.get(dataKey); gridData.setMode(gridMode); // logger.info("mode : " + gridMode); // logger.info("GridData Info: " + gridData); // // logger.info("---------------------------------------------------------------------------------------------------------"); // parameter 입력 } else if (json_params.equals(dataKey)) { // logger.info("--------------------------- JSON전문의 params를 GridData구조에 입력한다. // --------------------------------"); setJsonParamData(gridData, (List<LinkedHashMap<String, String>>) jsonDataMap.get(dataKey)); // // logger.info("---------------------------------------------------------------------------------------------------------"); // 헤더정보 입력 } else if (json_headers.equals(dataKey)) { // logger.info("--------------------------- JSON전문의 headers를 GridData구조에 // 입력한다. --------------------------------"); setJsonHeaderData(gridData, (List<LinkedHashMap<String, Object>>) jsonDataMap.get(dataKey)); // // logger.info("---------------------------------------------------------------------------------------------------------"); // rows 처리 } else if (json_rows.equals(dataKey)) { setRowData(gridData, (List<List<String>>) jsonDataMap.get(dataKey)); } else { throw new Exception("전문형식에 적합하지 않은 문자가 존재합니다."); } } return gridData; }
/** Updates the internal data by interpolating large grids onto a smaller array. */ void updateInterpolated(GridData griddata) { if (autoscaleZ) { double[] minmax = griddata.getZRange(ampIndex); zmax = minmax[1]; zmin = minmax[0]; if (zMap != null) { zMap.setMinMax(zmin, zmax); } colorMap.setScale(zmin, zmax); } double x = griddata.getLeft(), dx = (griddata.getRight() - griddata.getLeft()) / (nx - 1); double y = griddata.getTop(), dy = -(griddata.getTop() - griddata.getBottom()) / (ny - 1); for (int i = 0; i < nx; i++) { y = griddata.getTop(); for (int j = 0; j < ny; j++) { internalData[i][j] = griddata.interpolate(x, y, ampIndex); if (zMap != null) { internalData[i][j] = zMap.evaluate(internalData[i][j]); } y += dy; } x += dx; } }
/** GridData 구조에 JSON전문의 headers에 대한 데이터를 입력한다. */ public static void setJsonHeaderData( GridData gridData, List<LinkedHashMap<String, Object>> headersList) throws Exception { /* * 1. 헤더생성 CreateHeader() * 2. 데이터 타입에 따라 입력 * */ // logger.info("headers : " + headersList); // logger.info("headers count : " + headersList.size()); for (LinkedHashMap<String, Object> header : headersList) { String headerType = (String) header.get(json_headers_type); String headerKey = (String) header.get(json_headers_key); GridHeader gridHeader = gridData.createHeader(headerKey, headerType); /* * 콤보데이터 입력. * 콤보리스트 텍스트 -> GridHeader의 multiListValues로 입력 * 콤보리스트 실제값 -> GridHeader의 multiListHiddenValues로 입력 * */ if (t_combo.equals(headerType)) { List<LinkedHashMap<String, Object>> comboListData = (List<LinkedHashMap<String, Object>>) header.get(json_common_value); String[] comboTextData = new String[comboListData.size()]; String[] comboValueData = new String[comboListData.size()]; for (int i = 0; i < comboListData.size(); i++) { comboTextData[i] = (String) comboListData.get(i).get(json_headers_value_text); comboValueData[i] = (String) comboListData.get(i).get(json_common_value); } gridHeader.setComboValues(comboTextData, comboValueData); gridHeader.setOriginComboValues(comboTextData, comboValueData); } else { if (t_imagetext.equals(headerType)) { ArrayList<String> imageDataList = (ArrayList<String>) header.get(json_common_value); String[] imageDataArray = new String[imageDataList.size()]; gridHeader.setImageURLs(imageDataList.toArray(imageDataArray)); } } // logger.info("header info --> " + gridHeader); } }
/** mode가 save일때 request 전문의 rows 데이터 파싱 */ public static void setRowData(GridData gridData, List<List<String>> rowDataList) throws Exception { GridHeader[] gridHeaders = gridData.getHeaders(); int headersCount = gridHeaders.length; int rowCount = rowDataList.size(); int rowsColumnCount = 0; for (int i = 0; i < rowCount; i++) { rowsColumnCount = rowDataList.get(i).size(); if (rowsColumnCount != headersCount) { throw new Exception("헤더컬럼수와 로우즈 컬럼수가 일치하지 않습니다."); } else { for (int j = 0; j < headersCount; j++) { if (!(rowDataList.get(i).get(j) instanceof String)) { gridHeaders[j].addValue(String.valueOf(rowDataList.get(i).get(j)), ""); } else { gridHeaders[j].addValue(rowDataList.get(i).get(j), ""); } } } } }
/** * Paint the contour. * * @param g */ public synchronized void draw(DrawingPanel panel, Graphics g) { if (!visible || (griddata == null)) { return; } if (!autoscaleZ) { g.setColor(colorMap.getFloorColor()); int w = panel.getWidth() - panel.getLeftGutter() - panel.getRightGutter(); int h = panel.getHeight() - panel.getTopGutter() - panel.getBottomGutter(); g.fillRect(panel.getLeftGutter(), panel.getTopGutter(), Math.max(w, 0), Math.max(h, 0)); } accumulator.clearAccumulator(); contour_stepz = (zmax - zmin) / (contour_lines + 1); double z = zmin; for (int c = 0; c < contourColors.length; c++) { if (!autoscaleZ && (c == contourColors.length - 1)) { contourColors[c] = colorMap.getCeilColor(); } else { contourColors[c] = colorMap.doubleToColor(z); } z += contour_stepz; } // double dx=griddata.getDx(); // double dy=griddata.getDy(); // double x = griddata.getLeft(); double x = griddata.getLeft(), dx = (griddata.getRight() - griddata.getLeft()) / (nx - 1); double y = griddata.getTop(), dy = -(griddata.getTop() - griddata.getBottom()) / (ny - 1); for (int i = 0, mx = internalData.length - 1; i < mx; i++) { y = griddata.getTop(); for (int j = 0, my = internalData[0].length - 1; j < my; j++) { contour_vertex[0][0] = x; contour_vertex[0][1] = y; contour_vertex[0][2] = internalData[i][j]; contour_vertex[1][0] = x; contour_vertex[1][1] = y + dy; contour_vertex[1][2] = internalData[i][j + 1]; contour_vertex[2][0] = x + dx; contour_vertex[2][1] = y + dy; contour_vertex[2][2] = internalData[i + 1][j + 1]; contour_vertex[3][0] = x + dx; contour_vertex[3][1] = y; contour_vertex[3][2] = internalData[i + 1][j]; createContour(panel, g); y += dy; } x += dx; } if (showContourLines) { g.setColor(lineColor); accumulator.drawAll(g); int lpix = panel.xToPix(griddata.getLeft()); int tpix = panel.yToPix(griddata.getTop()); int rpix = panel.xToPix(griddata.getRight()); int bpix = panel.yToPix(griddata.getBottom()); g.drawRect( Math.min(lpix, rpix), Math.min(tpix, bpix), Math.abs(lpix - rpix), Math.abs(tpix - bpix)); } }
/** * Gets closest index from the given x world coordinate. * * @param x double the coordinate * @return int the index */ public int xToIndex(double x) { return griddata.xToIndex(x); }
/** * Gets the y coordinate for the given index. * * @param i int * @return double the y coordinate */ public double indexToY(int i) { return griddata.indexToY(i); }
public double getYMax() { return griddata.getTop(); }
public double getYMin() { return griddata.getBottom(); }
/** * Gets closest index from the given y world coordinate. * * @param y double the coordinate * @return int the index */ public int yToIndex(double y) { return griddata.yToIndex(y); }
/** * @param gdReq * @return GridData * @since 2015/09/09 */ public static GridData cloneResponseGridData(GridData gdReq) throws Exception { GridData gdRes = new GridData(); // mode 추가 gdRes.setMode(gdReq.getMode()); String headers[] = gdReq.getHeaderSequence(); for (int i = 0; i < gdReq.getHeaderCount(); i++) { GridHeader ghValue = gdReq.getHeader(headers[i]); String headerDataType = gdReq.getHeader(headers[i]).getDataType(); gdRes.createHeader(headers[i], headerDataType); if (headerDataType.equals("L")) { if (ghValue.getComboValues() != null) if (ghValue.getComboValues().length != 0) gdRes .getHeader(headers[i]) .setComboValues(ghValue.getComboValues(), ghValue.getComboHiddenValues()); // 오리진 콤보데이터 확인을 위한 코드. gdRes .getHeader(headers[i]) .setOriginComboValues( ghValue.getOriginComboValues(), ghValue.getOriginComboHiddenValues()); if (ghValue.hasComboList()) { for (int j = 0; j < ghValue.getComboListCount(); j++) { String comboListKey = ghValue.getComboListKeys()[j]; gdRes .getHeader(headers[i]) .addComboListValues( comboListKey, ghValue.getComboValues(comboListKey), ghValue.getComboHiddenValues(comboListKey)); } } } else if (headerDataType.equals("I")) { if (ghValue.getImageURLs() != null) if (ghValue.getImageURLs().length != 0) gdRes.getHeader(headers[i]).setImageURLs(ghValue.getImageURLs()); } } return gdRes; }
/** * WiseGrid 에 전달할 GridData 를 전문화해서 전송 * * @param gridObj realGrid 에 전달할 GridData 객체 * @param out 일반조회용 Out * @param out2 압축조회용 Out * @param bMulti 통합통신 여부 * @param bUseHiddenValue HiddenValue 사용 유무 - 현재는 사용안함 * @throws Exception * @since v2, 0, 0, 1 */ private static void write( GridData gridObj, Writer out, OutputStream out2, boolean bMulti, boolean bUseHiddenValue) throws Exception { if (out == null) { throw new Exception("Not available write method arguments!"); } // 동적메소드 사용여부 확인. // if (gridObj.hasDynamicMethod()) { } LinkedHashMap<String, Object> jsonResponseString = new LinkedHashMap<String, Object>(); // 헤더에서 데이터 추출 및 JSON형식으로 파싱 String gridMode = gridObj.getMode(); if ("search".equals(gridMode)) { jsonResponseString.put(json_mode, gridMode); GridHeader[] gridHeaders = gridObj.getHeaders(); String[][] rowData = new String[gridHeaders[0].getRowCount()][gridHeaders.length]; List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); String[] comboListValues = null; String[] comboListHiddenValues = null; // 그리드 헤더수만큼 for, 헤더의 row수 만큼 데이터 추출 for (int i = 0; i < gridHeaders.length; i++) { // setComboValues() 를 만나 콤보리스트 값이 변경이 되었을 경우만 콤보리스트 셋팅하여 response로 내려준다. if (t_combo.equals(gridHeaders[i].getDataType()) && gridHeaders[i].getComboListChange() == true) { // 콤보리스트 -> listItems int comboListItemCount = gridHeaders[i].getComboListItemCount(); comboListValues = gridHeaders[i].getComboValues(); comboListHiddenValues = gridHeaders[i].getComboHiddenValues(); /* * 리스트 <- 맵 <- 리스트 -< 맵 * */ LinkedHashMap<String, Object> comboItemMap = new LinkedHashMap<String, Object>(); List<LinkedHashMap<String, String>> comboSetList = new ArrayList<LinkedHashMap<String, String>>(); for (int k = 0; k < comboListItemCount; k++) { LinkedHashMap<String, String> comboDataSet = new LinkedHashMap<String, String>(); comboDataSet.put(comboListValues[k], comboListHiddenValues[k]); comboSetList.add(comboDataSet); } comboItemMap.put(gridHeaders[i].getID(), comboSetList); listItems.add(comboItemMap); } for (int j = 0; j < gridHeaders[i].getRowCount(); j++) { rowData[j][i] = gridHeaders[i].getValue(j); } } jsonResponseString.put("rows", rowData); if (listItems.size() != 0) { jsonResponseString.put("listItems", listItems); } } else { jsonResponseString.put(json_mode, "save"); } jsonResponseString.put(messageid, gridObj.getMessage()); jsonResponseString.put(statusid, gridObj.getStatus()); out.write(new ObjectMapper().writeValueAsString(jsonResponseString)); }
/* The following methods are requried for the measurable interface */ public double getXMin() { return griddata.getLeft(); }
public double getXMax() { return griddata.getRight(); }
/** Applies a hexagon-based layout to the container. */ @Override public void layout(IFigure container) { // Get the maximum bounding box we can use for layout out sub-figures. Rectangle limit = container.getClientArea(); // Math.cos() may vary across platforms, so pre-compute it. double cosPiDivSix = Math.sqrt(3) / 2.0; if (!rotated) { // Get the hexagon side lengths supported by the current // width/height of // the client area. double lx = 2.0 * (double) (limit.width - horizontalSpacing * (columns - 1)) / (double) (3 * columns + 1); double ly = (double) (limit.height - verticalSpacing * (rows - 1)) / (cosPiDivSix * (double) (rows * 2 + 1)); // Determine which length to use and flag the direction that needs // to be // padded (x or y). double l; int paddingX = 0, paddingY = 0; if (ly >= lx) { // Size restricted by width. l = lx; } else { // Size restricted by height. l = ly; paddingX++; } // Compute the half-height and half-width of each hexagon. lx = l / 2; // shortcut: sin(PI/6) = 1/2! ly = l * cosPiDivSix; // Compute the necessary padding for whichever dimension needs it. if (paddingX != 0) { // Size restricted by height. paddingX = (int) (((double) limit.width - horizontalSpacing * (rows - 1) - (lx * (double) (3 * columns + 1))) / 2.0); } else { // Size restricted by width. paddingY = (int) (((double) limit.height - verticalSpacing * (rows - 1) - (ly * (double) (2 * rows + 1))) / 2.0); } // Update the PointList used by each hexagon. // Note: The hexagons store references to the PointList, so we do // not need to call hexagon.setPoints(), which, in fact, // refreshes/repaints the Shape, in the quadratic loop below. points.setPoint(new Point((int) (lx), 0), 0); points.setPoint(new Point((int) (lx + l), 0), 1); points.setPoint(new Point((int) (l + l), (int) ly), 2); points.setPoint(new Point((int) (lx + l), (int) (ly + ly)), 3); points.setPoint(new Point((int) (lx), (int) (ly + ly)), 4); points.setPoint(new Point(0, (int) ly), 5); // We want to limit math ops, so compute the factors used in the // loop. double xFactor = l + lx + (double) horizontalSpacing; double yFactor = 2 * ly + (double) verticalSpacing; // Compute the width and height of each hexagon. int width = (int) Math.ceil(2 * l); int height = (int) Math.ceil(2 * ly); // Variables used throughout the below loop. int i, row, column, x, y, w, h; // Loop over the IFigures in the container with this layout. for (Object childObject : container.getChildren()) { IFigure child = (IFigure) childObject; // Get the constraints (and the x, y, w, h offsets from it). GridData constraint = getConstraint(child); Rectangle offsets = constraint.getOffsets(); // Get the index and compute the row and column for the index. i = constraint.getIndex(); row = i / columns; column = i % columns; // Compute the bounds of the cell in the row, column position. x = paddingX + (int) (column * xFactor) + offsets.x; y = paddingY + (int) (row * yFactor + ly * (double) (column % 2)) + offsets.y; w = width + offsets.width; h = height + offsets.height; // Set the bounds for the child IFigure. child.setBounds(new Rectangle(x, y, w, h)); } } else { // All hexagons are rotated 90 degrees. // Get the hexagon side lengths supported by the current // width/height of // the client area. double lx = (double) (limit.width - horizontalSpacing * (columns - 1)) / (cosPiDivSix * (double) (columns * 2 + 1)); double ly = 2.0 * (double) (limit.height - verticalSpacing * (rows - 1)) / (double) (3 * rows + 1); // Determine which length to use and flag the direction that needs // to be // padded (x or y). double l; int paddingX = 0, paddingY = 0; if (ly >= lx) { // Size restricted by width. l = lx; } else { // Size restricted by height. l = ly; paddingX++; } // Compute the half-height and half-width of each hexagon. lx = l * cosPiDivSix; ly = l / 2; // shortcut: sin(PI/6) = 1/2! // Compute the necessary padding for whichever dimension needs it. if (paddingX != 0) { // Size restricted by height. paddingX = (int) (((double) limit.width - horizontalSpacing * (columns - 1) - (lx * (double) (2 * columns + 1))) / 2.0); } else { // Size restricted by width. paddingY = (int) (((double) limit.height - verticalSpacing * (rows - 1) - (ly * (double) (3 * rows + 1))) / 2.0); } // Update the PointList used by each hexagon. // Note: The hexagons store references to the PointList, so we do // not need to call hexagon.setPoints(), which, in fact, // refreshes/repaints the Shape, in the quadratic loop below. points.setPoint(new Point((int) lx, 0), 0); points.setPoint(new Point((int) (lx + lx), (int) ly), 1); points.setPoint(new Point((int) (lx + lx), (int) (ly + l)), 2); points.setPoint(new Point((int) lx, (int) (l + l)), 3); points.setPoint(new Point(0, (int) (ly + l)), 4); points.setPoint(new Point(0, (int) ly), 5); // We want to limit math ops, so compute the factors used in the // loop. double xFactor = lx + lx + (double) horizontalSpacing; double yFactor = l + ly + (double) verticalSpacing; // Compute the width and height of each hexagon. int width = (int) Math.ceil(lx + lx); int height = (int) Math.ceil(l + l); // Variables used throughout the below loop. int i, row, column, x, y, w, h; // Loop over the IFigures in the container with this layout. for (Object childObject : container.getChildren()) { IFigure child = (IFigure) childObject; // Get the constraints (and the x, y, w, h offsets from it). GridData constraint = getConstraint(child); Rectangle offsets = constraint.getOffsets(); // Get the index and compute the row and column for the index. i = constraint.getIndex(); row = i / columns; column = i % columns; // Compute the bounds of the cell in the row, column position. x = paddingX + (int) (column * xFactor + lx * (double) (row % 2)) + offsets.x; y = paddingY + (int) (row * yFactor) + offsets.y; w = width + offsets.width; h = height + offsets.height; // Set the bounds for the child IFigure. child.setBounds(new Rectangle(x, y, w, h)); } } return; }