Search in sources :

Example 11 with Pair

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;
}
Also used : Place(mudmap2.backend.Place) Pair(mudmap2.utils.Pair)

Example 12 with Pair

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;
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate) Color(java.awt.Color) Dimension(java.awt.Dimension) Layer(mudmap2.backend.Layer) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) MapPainterDefault(mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault) Place(mudmap2.backend.Place) Pair(mudmap2.utils.Pair)

Example 13 with Pair

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;
}
Also used : Place(mudmap2.backend.Place) Pair(mudmap2.utils.Pair)

Aggregations

Pair (mudmap2.utils.Pair)7 Map (java.util.Map)5 Place (mudmap2.backend.Place)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 GradientPaint (java.awt.GradientPaint)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Deployment (com.liveperson.ephemerals.deploy.Deployment)1 com.liveperson.ephemerals.deploy.probe (com.liveperson.ephemerals.deploy.probe)1 ContainerizedDeploymentUnit (com.liveperson.ephemerals.deploy.unit.ContainerizedDeploymentUnit)1 com.liveperson.ephemerals.deploy.volume (com.liveperson.ephemerals.deploy.volume)1 DEPLOYMENT_LABEL_KEY (com.liveperson.ephemerals.provider.kubernetes.KubernetesDeploymentHandler.DEPLOYMENT_LABEL_KEY)1 Names (com.netflix.frigga.Names)1