use of mudmap2.utils.Pair in project mudmap2 by Neop.
the class EditWorldDialog method save.
/**
* Saves the changes
*/
private void save() throws Exception {
String name = textfield_name.getText();
// if textfield is not empty
if (!name.isEmpty()) {
world.setName(name);
}
// modify risk levels
for (Map.Entry<RiskLevel, Pair<JTextField, ColorChooserButton>> rl_color : risklevel_colors.entrySet()) {
String description = rl_color.getValue().first.getText();
if (description.isEmpty())
world.removeRiskLevel(rl_color.getKey());
else {
rl_color.getKey().setDescription(description);
rl_color.getKey().setColor(rl_color.getValue().second.getColor());
}
}
world.setTileCenterColor(tile_center_color.getColor());
// add new risk level, if name not empty
String name_new = risklevel_new_name.getText();
if (!name_new.isEmpty()) {
world.addRiskLevel(new RiskLevel(name_new, risklevel_new_color.getColor()));
}
ButtonModel selection = buttongroup_place_id.getSelection();
if (selection == radiobutton_place_id_none.getModel())
world.setShowPlaceID(World.ShowPlaceID.NONE);
else if (selection == radiobutton_place_id_all.getModel())
world.setShowPlaceID(World.ShowPlaceID.ALL);
else
world.setShowPlaceID(World.ShowPlaceID.UNIQUE);
getParent().repaint();
}
use of mudmap2.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 mudmap2.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 mudmap2.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