/** * Getter for <code>RoomMap</code> object with all its properties, including <code>Receiver</code> * s and <code>CoordinateZeroMarkerView</code>s . * * @return the map * @see Receiver * @see ReceiverView * @see CoordinateZeroMarkerView */ public RoomMap getMap() { // set zero coordinate marker positions int lowerLeftMarkerOffsetXInPixels = (int) (lowerLeftMarker.getLocation().getX() / scalingRatioToFitContainer); int lowerLeftMarkerOffsetYInPixels = (int) (lowerLeftMarker.getLocation().getY() / scalingRatioToFitContainer) + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_HEIGHT); map.setLowerLeftMarkerOffsetXInPixels(lowerLeftMarkerOffsetXInPixels); map.setLowerLeftMarkerOffsetYInPixels(lowerLeftMarkerOffsetYInPixels); int upperRightMarkerOffsetXInPixels = (int) (upperRightMarker.getLocation().getX() / scalingRatioToFitContainer) + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_WIDTH); int upperRightMarkerOffsetYInPixels = (int) (upperRightMarker.getLocation().getY() / scalingRatioToFitContainer); map.setUpperRightMarkerOffsetXInPixels(upperRightMarkerOffsetXInPixels); map.setUpperRightMarkerOffsetYInPixels(upperRightMarkerOffsetYInPixels); // set room width and height in meters double roomWidthInMeters = parent.getRoomWidthInMeters(); double roomHeightInMeters = parent.getRoomHeightInMeters(); map.setWidthInMeters(roomWidthInMeters); map.setHeightInMeters(roomHeightInMeters); // set width and height ratios int mapWidthInPixels = upperRightMarkerOffsetXInPixels - lowerLeftMarkerOffsetXInPixels; int mapHeightInPixels = lowerLeftMarkerOffsetYInPixels - upperRightMarkerOffsetYInPixels; double mapWidthRatio = (mapWidthInPixels) / roomWidthInMeters; double mapHeightRatio = (mapHeightInPixels) / roomHeightInMeters; map.setRatioWidth(mapWidthRatio); map.setRatioHeight(mapHeightRatio); // set receiver positions in meters map.getReceivers().clear(); // first we remove all present receivers for (ReceiverView receiverView : receiverViews) { int receiverViewXInPixels = ((int) (receiverView.getLocation().getX() / scalingRatioToFitContainer)) + (ReceiverView.RECEIVER_ITEM_WIDTH / 2); int receiverViewYInPixels = ((int) (receiverView.getLocation().getY() / scalingRatioToFitContainer)) + (ReceiverView.RECEIVER_ITEM_HEIGHT / 2); double receiverPositionInMetersX = calculateReceiverPositionInMetersX( lowerLeftMarkerOffsetXInPixels, receiverViewXInPixels, mapWidthRatio); double receiverPositionInMetersY = calculateReceiverPositionInMetersY( lowerLeftMarkerOffsetYInPixels, receiverViewYInPixels, mapHeightRatio); receiverView.getReceiver().setxPos(receiverPositionInMetersX); receiverView.getReceiver().setyPos(receiverPositionInMetersY); map.addReceiver(receiverView.getReceiver()); } // set map title String titleFromInput = parent.getRoomTitle(); map.setTitle(titleFromInput.equals("") ? "Unkown" : titleFromInput); // set map xFrom, xTo, yFrom and yTo values map.setxFrom(0); map.setxTo(map.getWidthInMeters()); map.setyFrom(0); map.setyTo(map.getHeightInMeters()); Application.getApplication().setRoomMap(map); return map; }
/* * (non-Javadoc) * * @see dao.MapDAO#getAllMaps() */ @Override public List<RoomMap> getAllMaps() { if (allMaps != null) { return allMaps; } else { allMaps = new ArrayList<RoomMap>(); } // sample maps initialization values RoomMap map = null; BufferedImage image = null; double roomWidth = 0.0; double roomHeight = 0.0; String title = ""; ArrayList<Receiver> receivers = null; // add sample map, id 0 String path1 = "images/room_4m_6m.png"; image = (BufferedImage) Utilities.loadImage(path1); title = "Test Room"; roomWidth = 4.0; roomHeight = 6.0; receivers = new ArrayList<Receiver>(); receivers.add(new Receiver(0, 0.0, 0.0, 45.0, true)); receivers.add(new Receiver(1, 4.0, 0.0, 135.0, true)); receivers.add(new Receiver(2, 4.0, 6.0, 225.0, true)); receivers.add(new Receiver(3, 0.0, 6.0, 315.0, true)); map = new RoomMap(image, title, receivers); map.setId(0); map.setWidthInMeters(roomWidth); map.setHeightInMeters(roomHeight); map.setLowerLeftMarkerOffsetXInPixels(0); map.setLowerLeftMarkerOffsetYInPixels(460); map.setUpperRightMarkerOffsetXInPixels(309); map.setUpperRightMarkerOffsetYInPixels(0); map.setRatioWidth(75.5); map.setRatioHeight(75.5); map.setPath(path1); allMaps.add(map); // add sample map, id 1 String path2 = "images/test_room_fifth_floor.png"; image = (BufferedImage) Utilities.loadImage(path2); title = "Room 501"; roomWidth = 6.0; roomHeight = 6.0; receivers = new ArrayList<Receiver>(); receivers.add(new Receiver(0, 0.0, 6.0, 315.0, true)); receivers.add(new Receiver(1, 2.0, 6.0, 270.0, true)); receivers.add(new Receiver(2, 6.0, 6.0, 225.0, true)); receivers.add(new Receiver(3, 0.0, 2.45, 0.0, true)); receivers.add(new Receiver(4, 6.0, 2.45, 180.0, true)); receivers.add(new Receiver(6, 6.0, 0.0, 135.0, true)); receivers.add(new Receiver(9, 3.60, 2.0, 270.0, true)); map = new RoomMap(image, title, receivers); map.setId(1); map.setWidthInMeters(roomWidth); map.setHeightInMeters(roomHeight); map.setLowerLeftMarkerOffsetXInPixels(0); map.setLowerLeftMarkerOffsetYInPixels(538); map.setUpperRightMarkerOffsetXInPixels(538); map.setUpperRightMarkerOffsetYInPixels(0); map.setRatioWidth(89.67); map.setRatioHeight(89.67); map.setPath(path2); allMaps.add(map); // add sample map, id 2 String path3 = "images/room_4m_6m.png"; image = (BufferedImage) Utilities.loadImage(path3); title = "Room 481"; roomWidth = 5.0; roomHeight = 8.30; receivers = new ArrayList<Receiver>(); receivers.add(new Receiver(6, 0.7, 0.0, 90.0, true)); receivers.add(new Receiver(1, 5.0, 0.65, 135.0, true)); receivers.add(new Receiver(2, 5.0, 4.5, 180.0, true)); receivers.add(new Receiver(3, 0.0, 2.0, 0.0, true)); receivers.add(new Receiver(4, 0.0, 7.8, 315.0, true)); receivers.add(new Receiver(0, 2.5, 8.3, 270.0, true)); receivers.add(new Receiver(9, 4.80, 8.3, 225.0, true)); map = new RoomMap(image, title, receivers); map.setId(2); map.setWidthInMeters(roomWidth); map.setHeightInMeters(roomHeight); map.setLowerLeftMarkerOffsetXInPixels(0); map.setLowerLeftMarkerOffsetYInPixels(460); map.setUpperRightMarkerOffsetXInPixels(309); map.setUpperRightMarkerOffsetYInPixels(0); map.setRatioWidth(61.80); map.setRatioHeight(55.42); map.setPath(path3); allMaps.add(map); return allMaps; }