Search in sources :

Example 6 with Pair

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();
}
Also used : ButtonModel(javax.swing.ButtonModel) HashMap(java.util.HashMap) Map(java.util.Map) RiskLevel(mudmap2.backend.RiskLevel) Pair(mudmap2.utils.Pair)

Example 7 with Pair

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

Example 8 with Pair

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;
}
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 9 with Pair

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

Aggregations

Pair (mudmap2.utils.Pair)7 Place (mudmap2.backend.Place)4 Map (java.util.Map)3 Color (java.awt.Color)2 GradientPaint (java.awt.GradientPaint)2 Graphics (java.awt.Graphics)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 HashMap (java.util.HashMap)2 Layer (mudmap2.backend.Layer)2 RiskLevel (mudmap2.backend.RiskLevel)2 WorldCoordinate (mudmap2.backend.WorldCoordinate)2 Pair (io.fabric8.utils.Pair)1 BasicStroke (java.awt.BasicStroke)1 Dimension (java.awt.Dimension)1 FontMetrics (java.awt.FontMetrics)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1