use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.
the class WorldPanel method placeGroupBoxModifySelection.
/**
* Modifies the box/shift selection box (eg on shift + direction key)
* @param x new coordinate
* @param y new coordinate
*/
private void placeGroupBoxModifySelection(int x, int y) {
placeGroup.clear();
placeGroupBoxEnd = new WorldCoordinate(getPosition().getLayer(), x, y);
// reset if layer changed
if (placeGroupBoxStart != null && placeGroupBoxStart.getLayer() != placeGroupBoxEnd.getLayer())
placeGroupBoxStart = null;
// set start, if not set
if (placeGroupBoxStart == null)
placeGroupBoxStart = placeGroupBoxEnd;
}
use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.
the class WorldTab method layerSelected.
// ========================= selection listener ============================
@Override
public void layerSelected(Layer layer) {
worldPanel.pushPosition(new WorldCoordinate(layer.getId(), layer.getCenterX(), layer.getCenterY()));
repaint();
}
use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.
the class WorldTab method getMeta.
@Override
public JSONObject getMeta(HashMap<Integer, Integer> layerTranslation) {
JSONObject root = new JSONObject();
MapPainterDefault mapPainter = (MapPainterDefault) getWorldPanel().getMappainter();
root.put("showPaths", mapPainter.getShowPaths());
root.put("pathsCurved", mapPainter.getPathsCurved());
root.put("showCursor", getWorldPanel().isCursorEnabled());
root.put("showGrid", mapPainter.isGridEnabled());
root.put("tileSize", getWorldPanel().getTileSize());
JSONArray history = new JSONArray();
root.put("history", history);
Integer cnt = 0;
for (WorldCoordinate coord : getWorldPanel().getHistory()) {
if (layerTranslation.containsKey(coord.getLayer())) {
JSONObject el = new JSONObject();
el.put("l", layerTranslation.get(coord.getLayer()));
el.put("x", coord.getX());
el.put("y", coord.getY());
history.put(el);
}
if (++cnt >= 25)
break;
}
return root;
}
use of mudmap2.backend.WorldCoordinate 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.backend.WorldCoordinate in project mudmap2 by Neop.
the class WorldPanelTest method testPushPopPosition.
/**
* Test of push/pop/get/restore/resetPosition method, of class WorldPanel.
*/
@Test
public void testPushPopPosition() {
System.out.println("pushPosition");
World world = new World();
WorldPanel instance = new WorldPanel(null, world, false);
WorldCoordinate home = new WorldCoordinate(1, 2, 3);
WorldCoordinate pos1 = new WorldCoordinate(4, 6, 1);
WorldCoordinate pos2 = new WorldCoordinate(1, 2, 6);
WorldCoordinate pos3 = new WorldCoordinate(1, 8, 4);
world.setHome(home);
assertTrue(home.compareTo(instance.getPosition()) == 0);
instance.popPosition();
assertTrue(home.compareTo(instance.getPosition()) == 0);
instance.pushPosition(pos1);
WorldCoordinate push1 = instance.getPosition();
// assertTrue(pos1.compareTo(instance.getPosition()) == 0);
instance.pushPosition(pos2);
WorldCoordinate push2 = instance.getPosition();
// assertTrue(pos2.compareTo(instance.getPosition()) == 0);
instance.pushPosition(pos3);
WorldCoordinate push3 = instance.getPosition();
// assertTrue(pos3.compareTo(instance.getPosition()) == 0);
instance.popPosition();
assertTrue(push2.compareTo(instance.getPosition()) == 0);
instance.popPosition();
assertTrue(push1.compareTo(instance.getPosition()) == 0);
instance.popPosition();
assertTrue(home.compareTo(instance.getPosition()) == 0);
instance.popPosition();
assertTrue(home.compareTo(instance.getPosition()) == 0);
instance.restorePosition();
assertTrue(push1.compareTo(instance.getPosition()) == 0);
instance.restorePosition();
assertTrue(push2.compareTo(instance.getPosition()) == 0);
instance.restorePosition();
assertTrue(push3.compareTo(instance.getPosition()) == 0);
instance.restorePosition();
assertTrue(push3.compareTo(instance.getPosition()) == 0);
WorldCoordinate reset = new WorldCoordinate(12, 1, 6);
instance.resetHistory(reset);
assertTrue(reset.compareTo(instance.getPosition()) == 0);
}
Aggregations