use of io.fabric8.utils.Pair in project mudmap2 by Neop.
the class ExportImageDialog method getSelectionSize.
/**
* Calculates the size needed to draw the selected places
* @param places selected places
* @return width and height
*/
Pair<Integer, Integer> getSelectionSize(HashSet<Place> places) {
Pair<Integer, Integer> imageSize = new Pair<>(0, 0);
if (!places.isEmpty()) {
// get bounds of selected places
int mapXMax, mapXMin, mapYMax, mapYMin;
Place place1 = places.iterator().next();
mapXMax = mapXMin = place1.getX();
mapYMax = mapYMin = place1.getY();
for (Place place : places) {
mapXMax = Math.max(mapXMax, place.getX());
mapXMin = Math.min(mapXMin, place.getX());
mapYMax = Math.max(mapYMax, place.getY());
mapYMin = Math.min(mapYMin, place.getY());
}
// calculate image size from bounds
int tileSize = (int) spTileSize.getValue();
imageSize.first = (mapXMax - mapXMin + 1) * tileSize;
imageSize.second = (mapYMax - mapYMin + 1) * tileSize;
}
return imageSize;
}
use of io.fabric8.utils.Pair in project mudmap2 by Neop.
the class ExportImageDialog method drawLayer.
/**
* Draws map
* @param center layer and center information
* @return image
*/
BufferedImage drawLayer(WorldCoordinate center) {
BufferedImage image = null;
Integer tileSize = (Integer) spTileSize.getValue();
int width, height;
// get image size and map center
if (rbSelection.isSelected()) {
HashSet<Place> places = worldTab.getWorldPanel().placeGroupGetSelection();
Pair<Integer, Integer> selectionSize = getSelectionSize(places);
width = selectionSize.first;
height = selectionSize.second;
Pair<Double, Double> selectionCenter = getSelectionCenter(places);
center = new WorldCoordinate(center.getLayer(), selectionCenter.first, selectionCenter.second);
} else if (rbCurrentView.isSelected()) {
Dimension size = worldTab.getWorldPanel().getSize();
width = size.width;
height = size.height;
} else {
// whole map
Pair<Integer, Integer> mapSize = getMapSize(worldTab.getWorld().getLayer(center.getLayer()));
width = mapSize.first;
height = mapSize.second;
Layer layer = worldTab.getWorld().getLayer(center.getLayer());
Pair<Double, Double> exactCenter = layer.getExactCenter();
center = new WorldCoordinate(layer.getId(), exactCenter.first, exactCenter.second);
}
if (width != 0 && height != 0) {
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
if (image != null) {
Graphics graphics = image.createGraphics();
graphics.setClip(0, 0, width, height);
((Graphics2D) graphics).setBackground(new Color(255, 255, 255, 0));
graphics.clearRect(0, 0, width, height);
graphics.setFont(worldTab.getFont());
MapPainterDefault mappainter = new MapPainterDefault();
mappainter.setGridEnabled(cbBackgroundGrid.isSelected());
mappainter.paint(graphics, tileSize, width, height, worldTab.getWorld().getLayer(center.getLayer()), center);
}
return image;
}
use of io.fabric8.utils.Pair in project mudmap2 by Neop.
the class ExportImageDialog method getSelectionCenter.
/**
* Calculates the selection center
* @param places selected places
* @return center coordinates
*/
Pair<Double, Double> getSelectionCenter(HashSet<Place> places) {
Pair<Double, Double> selectionCenter = new Pair<>(0.0, 0.0);
if (!places.isEmpty()) {
// get bounds of selected places
int mapXMax, mapXMin, mapYMax, mapYMin;
Place place1 = places.iterator().next();
mapXMax = mapXMin = place1.getX();
mapYMax = mapYMin = place1.getY();
for (Place place : places) {
mapXMax = Math.max(mapXMax, place.getX());
mapXMin = Math.min(mapXMin, place.getX());
mapYMax = Math.max(mapYMax, place.getY());
mapYMin = Math.min(mapYMin, place.getY());
}
// calculate selection center from bounds
selectionCenter.first = 0.5 * (double) (mapXMax - mapXMin + 1) + (double) mapXMin;
selectionCenter.second = 0.5 * (double) (mapYMax - mapYMin + 1) + (double) mapYMin - 1;
}
return selectionCenter;
}
Aggregations