コード例 #1
0
ファイル: MapPreviewPanel.java プロジェクト: Wilt/rssi-system
  /** Adds <code>CoordinateZeroMarkerView</code>s to <code>RoomMap</code>. */
  public void addCoordinateZeroMarkerViewsToMap() {

    if (lowerLeftMarker == null || upperRightMarker == null) {
      lowerLeftMarker = new CoordinateZeroMarkerView(CoordinateZeroMarkerViewType.LOWER_LEFT, this);
      upperRightMarker =
          new CoordinateZeroMarkerView(CoordinateZeroMarkerViewType.UPPER_RIGHT, this);

      if (map.getLowerLeftMarkerOffsetXInPixels() != 0
          || map.getLowerLeftMarkerOffsetYInPixels() != 0) {
        lowerLeftMarker.setLocation(
            (int) (map.getLowerLeftMarkerOffsetXInPixels() * scalingRatioToFitContainer),
            ((int) (map.getLowerLeftMarkerOffsetYInPixels() * scalingRatioToFitContainer)
                - (int)
                    (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_HEIGHT
                        * scalingRatioToFitContainer)));
      }

      if (map.getUpperRightMarkerOffsetXInPixels() != 0
          || map.getUpperRightMarkerOffsetYInPixels() != 0) {
        upperRightMarker.setLocation(
            ((int) (map.getUpperRightMarkerOffsetXInPixels() * scalingRatioToFitContainer)
                - (int)
                    (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_WIDTH
                        * scalingRatioToFitContainer)),
            (int) (map.getUpperRightMarkerOffsetYInPixels() * scalingRatioToFitContainer));
      }

      add(lowerLeftMarker);
      add(upperRightMarker);
      lowerLeftMarker.repaint();
      upperRightMarker.repaint();
      revalidate();
      componentMover.registerComponent(lowerLeftMarker);
      componentMover.registerComponent(upperRightMarker);
    } else {
      // don't add another pair of zero coordinate map marker views, just set position to zero and
      // repaint the old
      // ones
      lowerLeftMarker.setLocation(0, 0);
      lowerLeftMarker.repaint();
      upperRightMarker.setLocation(0, 0);
      upperRightMarker.repaint();
      revalidate();
    }
  }
コード例 #2
0
ファイル: HardcodedMapDAO.java プロジェクト: Wilt/rssi-system
  private void uploadMapToServer(RoomMap newMap) {

    Mongo mongo = null;
    DB database;
    DBCollection sampleData;

    String databaseAddress = DEFAULT_DATABASE_ADDRESS;

    try { // read parameters from the configuration file
      databaseAddress = Utilities.getConfigurationValue(DATABASE_ADDRESS);

    } catch (NumberFormatException exception) { // reading has failed, use default values
      logger.info(
          "Reading parameters from configuration file failed. "
              + "Using default values for database_address instead.");
    }

    try {
      mongo = new Mongo(databaseAddress);
    } catch (UnknownHostException e1) {
      e1.printStackTrace();
    }

    database = mongo.getDB("rssiSystem");
    sampleData = database.getCollection("map_records");
    // remove all maps
    sampleData.drop();

    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    String strDate = simpledateformat.format(new Date());

    // -------------------
    // Load our image
    byte[] imageBytes = null;
    try {
      imageBytes = Utilities.LoadImageAsBytes(newMap.getPath());
    } catch (Exception e1) {
      e1.printStackTrace();
    }

    // ---------------------

    // Create GridFS object
    GridFS fs = new GridFS(database);
    // Save image into database
    GridFSInputFile in = fs.createFile(imageBytes);
    in.save();
    Object mapIdObject = in.getId();
    // System.out.println(mapIdObject);

    try {

      DBObject documentDetail = new BasicDBObject();

      documentDetail.put("_cls", "mapRecords"); // for mongoEngine ORM users
      documentDetail.put("image", mapIdObject);
      documentDetail.put("mapId", newMap.getId());
      documentDetail.put("width", newMap.getWidthInMeters());
      documentDetail.put("height", newMap.getHeightInMeters());
      documentDetail.put("offsetX", newMap.getLowerLeftMarkerOffsetXInPixels());
      documentDetail.put("offsetY", newMap.getLowerLeftMarkerOffsetYInPixels());
      documentDetail.put("offset2X", newMap.getUpperRightMarkerOffsetXInPixels());
      documentDetail.put("offset2Y", newMap.getUpperRightMarkerOffsetYInPixels());
      documentDetail.put("scalingX", newMap.getRatioWidth());
      documentDetail.put("scalingY", newMap.getRatioHeight());
      documentDetail.put("title", newMap.getTitle());
      documentDetail.put("updateTime", strDate);

      sampleData.insert(documentDetail);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }