use of mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault in project mudmap2 by Neop.
the class WorldTab method setMeta.
public void setMeta(JSONObject meta) {
if (meta != null) {
MapPainterDefault mapPainter = (MapPainterDefault) getWorldPanel().getMappainter();
if (meta.has("showPaths"))
mapPainter.setShowPaths(meta.getBoolean("showPaths"));
if (meta.has("pathsCurved"))
mapPainter.setPathsCurved(meta.getBoolean("pathsCurved"));
if (meta.has("showCursor"))
getWorldPanel().setCursorEnabled(meta.getBoolean("showCursor"));
if (meta.has("showGrid"))
mapPainter.setGridEnabled(meta.getBoolean("showGrid"));
if (meta.has("tileSize"))
getWorldPanel().setTileSize(meta.getInt("tileSize"));
if (meta.has("history")) {
worldPanel.getHistory().clear();
JSONArray history = meta.getJSONArray("history");
Integer size = history.length();
for (Integer i = 0; i < size; ++i) {
JSONObject histEl = history.getJSONObject(i);
if (histEl.has("l") && histEl.has("x") && histEl.has("y")) {
Integer layer = histEl.getInt("l");
Integer x = histEl.getInt("x");
Integer y = histEl.getInt("y");
worldPanel.getHistory().add(new WorldCoordinate(layer, x, y));
}
}
}
}
}
use of mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault in project mudmap2 by Neop.
the class PathConnectDialog method create.
@Override
void create() {
setMinimumSize(new Dimension(600, 600));
setLayout(new GridBagLayout());
worldtab = new WorldTab(parentFrame, place.getLayer().getWorld(), true);
worldtab.getWorldPanel().resetHistory(new WorldCoordinate(place.getLayer().getId(), place.getX(), place.getY()));
worldtab.getWorldPanel().setCursorForced(true);
worldtab.getWorldPanel().resetHistory(place.getCoordinate());
worldtab.getWorldPanel().setFocusForced(false);
((MapPainterDefault) worldtab.getWorldPanel().getMappainter()).setGridEnabled(false);
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = constraints.gridy = 0;
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridwidth = 4;
add(worldtab, constraints);
// Place config
constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 1;
constraints.insets = new Insets(4, 4, 4, 4);
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
add(new JLabel(place.toString()), constraints);
LinkedList<String> directions1 = new LinkedList<>();
for (String s : Path.directions) if (place.getExit(s) == null)
directions1.add(s);
constraints.gridx = 1;
constraints.weightx = 0.0;
directionComboBox1 = new JComboBox<>(directions1.toArray(new String[directions1.size()]));
directionComboBox1.setEditable(true);
add(directionComboBox1, constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.weightx = 1.0;
add(labelOtherPlace = new JLabel(), constraints);
constraints.gridx = 1;
constraints.weightx = 0.0;
directionComboBox2 = new JComboBox<>();
updateDirectionComboBox2();
directionComboBox2.setEditable(true);
add(directionComboBox2, constraints);
// Buttons
constraints.insets = new Insets(2, 2, 2, 2);
constraints.gridx = 0;
constraints.gridy = 3;
constraints.weightx = 1.0;
JButton button_cancel = new JButton("Cancel");
add(button_cancel, constraints);
button_cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
constraints.gridx = 1;
constraints.gridy = 3;
JButton button_ok = new JButton("Ok");
add(button_ok, constraints);
getRootPane().setDefaultButton(button_ok);
button_ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
save();
dispose();
}
});
worldtab.getWorldPanel().addCursorListener(new MapCursorListener() {
@Override
public void placeSelected(Place p) {
if (p != place) {
other = p;
labelOtherPlace.setText(other.toString());
updateDirectionComboBox2();
}
}
@Override
public void placeDeselected(Layer layer, int x, int y) {
}
});
pack();
setLocation(getParent().getX() + (getParent().getWidth() - getWidth()) / 2, getParent().getY() + (getParent().getHeight() - getHeight()) / 2);
}
use of mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault in project mudmap2 by Neop.
the class Mainwindow method stateChanged.
@Override
public void stateChanged(ChangeEvent e) {
WorldTab wt = getSelectedTab();
if (e.getSource() == menuEditCurvedPaths) {
if (wt != null) {
MapPainterDefault mapPainter = (MapPainterDefault) wt.getWorldPanel().getMappainter();
mapPainter.setPathsCurved(((JCheckBoxMenuItem) e.getSource()).isSelected());
wt.repaint();
}
} else if (e.getSource() == menuEditShowCursor) {
if (wt != null) {
wt.getWorldPanel().setCursorEnabled(((JCheckBoxMenuItem) e.getSource()).isSelected());
wt.repaint();
}
} else if (e.getSource() == menuEditShowGrid) {
if (wt != null) {
MapPainterDefault mapPainter = (MapPainterDefault) wt.getWorldPanel().getMappainter();
mapPainter.setGridEnabled(((JCheckBoxMenuItem) e.getSource()).isSelected());
wt.repaint();
}
} else if (tabbedPane != null && e.getSource() == tabbedPane) {
// tab changed
if (wt != null) {
wt.getWorldPanel().callStatusUpdateListeners();
menuEditCurvedPaths.setState(((MapPainterDefault) wt.getWorldPanel().getMappainter()).getPathsCurved());
menuEditShowGrid.setState(((MapPainterDefault) wt.getWorldPanel().getMappainter()).isGridEnabled());
}
} else {
String message = getClass().getName() + ": ChangeEvent not recognized";
Logger.getLogger(WorldManager.class.getName()).log(Level.SEVERE, message);
JOptionPane.showMessageDialog(this, message, "MUD Map error", JOptionPane.ERROR_MESSAGE);
}
}
use of mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault 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.frontend.GUIElement.WorldPanel.MapPainterDefault 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;
}
Aggregations