use of mudmap2.backend.Path in project mudmap2 by Neop.
the class Mainwindow method initGui.
private void initGui() {
// Add GUI components
JMenuBar menuBar = new JMenuBar();
add(menuBar, BorderLayout.NORTH);
JMenu menuFile = new JMenu("File");
menuBar.add(menuFile);
// Edit renamed to World
JMenu menuEdit = new JMenu("World");
menuBar.add(menuEdit);
JMenu menuHelp = new JMenu("Help");
menuBar.add(menuHelp);
JMenuItem menuFileNew = new JMenuItem("New");
menuFile.add(menuFileNew);
menuFileNew.setActionCommand("new_world");
menuFileNew.addActionListener(this);
JMenuItem menuFileOpen = new JMenuItem("Open");
menuFileOpen.addActionListener(new OpenWorldDialog(this));
menuFile.add(menuFileOpen);
// available worlds
JMenu menuFileOpenRecent = new JMenu("Open known world");
menuFile.add(menuFileOpenRecent);
WorldFileList.findWorlds();
for (final Entry<String, String> entry : WorldFileList.getWorlds().entrySet()) {
JMenuItem openWorldEntry = new JMenuItem(entry.getValue() + " (" + entry.getKey() + ")");
menuFileOpenRecent.add(openWorldEntry);
openWorldEntry.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
try {
createTab(WorldManager.getWorld(entry.getKey()), entry.getKey());
} catch (Exception ex) {
JOptionPane.showMessageDialog(getParent(), "Could not open world: " + ex.getMessage());
Logger.getLogger(Mainwindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
menuFile.addSeparator();
JMenuItem menuFileSave = new JMenuItem("Save");
menuFileSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
menuFileSave.setActionCommand("save_world");
menuFileSave.addActionListener(this);
menuFile.add(menuFileSave);
JMenuItem menuFileSaveAs = new JMenuItem("Save as");
menuFileSaveAs.setActionCommand("save_world_as");
menuFileSaveAs.addActionListener(this);
menuFile.add(menuFileSaveAs);
JMenuItem menuFileSaveAsImage = new JMenuItem("Export as image");
menuFileSaveAsImage.setActionCommand("export_image");
menuFileSaveAsImage.addActionListener(this);
menuFile.add(menuFileSaveAsImage);
menuFile.addSeparator();
JMenuItem menuFileQuit = new JMenuItem("Quit");
menuFileQuit.setActionCommand("quit");
menuFileQuit.addActionListener(this);
menuFile.add(menuFileQuit);
JMenuItem menuEditEditWorld = new JMenuItem("Edit world");
menuEditEditWorld.setActionCommand("edit_world");
menuEditEditWorld.addActionListener(this);
menuEdit.add(menuEditEditWorld);
JMenuItem menuEditPathColors = new JMenuItem("Path colors");
menuEditPathColors.setActionCommand("path_colors");
menuEditPathColors.addActionListener(this);
menuEdit.add(menuEditPathColors);
JMenuItem menuEditAddPlaceGroup = new JMenuItem("Add place group");
menuEditAddPlaceGroup.setActionCommand("add_place_group");
menuEditAddPlaceGroup.addActionListener(this);
menuEdit.add(menuEditAddPlaceGroup);
menuEdit.add(new JSeparator());
JMenuItem menuEditSetHomePosition = new JMenuItem("Set home position");
menuEditSetHomePosition.setActionCommand("set_home");
menuEditSetHomePosition.addActionListener(this);
menuEdit.add(menuEditSetHomePosition);
JMenuItem menuEditGotoHomePosition = new JMenuItem("Go to home position");
menuEditGotoHomePosition.setActionCommand("goto_home");
menuEditGotoHomePosition.addActionListener(this);
menuEdit.add(menuEditGotoHomePosition);
menuEdit.add(new JSeparator());
menuEditCurvedPaths = new JCheckBoxMenuItem("Curved paths");
menuEdit.add(menuEditCurvedPaths);
menuEditCurvedPaths.addChangeListener(this);
menuEditShowCursor = new JCheckBoxMenuItem("Show place cursor");
menuEdit.add(menuEditShowCursor);
menuEditShowCursor.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 0));
menuEditShowCursor.addChangeListener(this);
menuEditShowGrid = new JCheckBoxMenuItem("Show grid");
menuEdit.add(menuEditShowGrid);
menuEditShowGrid.addChangeListener(this);
JMenuItem menuHelpAbout = new JMenuItem("About");
menuHelp.add(menuHelpAbout);
menuHelpAbout.addActionListener((ActionListener) new AboutDialog(this));
BorderLayout infoPanelLayout = new BorderLayout();
infoPanel = new JPanel(infoPanelLayout);
add(infoPanel, BorderLayout.CENTER);
infoPanel.add(new JLabel("Load or create a world in the File menu.", SwingConstants.CENTER));
}
use of mudmap2.backend.Path in project mudmap2 by Neop.
the class ExportImageDialog method createLegendPanel.
/**
* Creates legend panel
* @return panel
*/
JPanel createLegendPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JPanel pRow1 = new JPanel();
pRow1.setLayout(new GridBagLayout());
panel.add(pRow1);
GridBagConstraints constraints1 = new GridBagConstraints();
constraints1.fill = GridBagConstraints.HORIZONTAL;
constraints1.insets = new Insets(2, 2, 2, 2);
constraints1.weightx = 1;
constraints1.gridx = constraints1.gridy = 1;
JLabel label = new JLabel("Legend:");
Font font = label.getFont();
label.setFont(font.deriveFont(Font.BOLD));
pRow1.add(label, constraints1);
cbLegendPathColors = new JCheckBox("Path colors");
cbLegendPlaceGroups = new JCheckBox("Place groups");
cbLegendRiskLevels = new JCheckBox("Risk levels");
constraints1.gridx++;
pRow1.add(cbLegendPathColors, constraints1);
constraints1.gridx++;
pRow1.add(cbLegendPlaceGroups, constraints1);
constraints1.gridx++;
pRow1.add(cbLegendRiskLevels, constraints1);
cbLegendPathColors.addActionListener(new UpdateDialogListener());
cbLegendPlaceGroups.addActionListener(new UpdateDialogListener());
cbLegendRiskLevels.addActionListener(new UpdateDialogListener());
constraints1.gridy++;
constraints1.gridx = 1;
pRow1.add(new JLabel("Position:"), constraints1);
rbLegendPosBottom = new JRadioButton("Bottom");
rbLegendPosLeft = new JRadioButton("Left");
rbLegendPosRight = new JRadioButton("Right");
rbLegendPosTop = new JRadioButton("Top");
ButtonGroup bgLegendPos = new ButtonGroup();
bgLegendPos.add(rbLegendPosBottom);
bgLegendPos.add(rbLegendPosLeft);
bgLegendPos.add(rbLegendPosRight);
bgLegendPos.add(rbLegendPosTop);
rbLegendPosBottom.setSelected(true);
constraints1.gridx++;
pRow1.add(rbLegendPosTop, constraints1);
constraints1.gridx++;
pRow1.add(rbLegendPosBottom, constraints1);
constraints1.gridx++;
pRow1.add(rbLegendPosLeft, constraints1);
constraints1.gridx++;
pRow1.add(rbLegendPosRight, constraints1);
JPanel pRow2 = new JPanel();
pRow2.setLayout(new GridBagLayout());
panel.add(pRow2);
GridBagConstraints constraints2 = new GridBagConstraints();
constraints2.fill = GridBagConstraints.HORIZONTAL;
constraints2.insets = new Insets(2, 2, 2, 2);
constraints2.gridx = constraints1.gridy = 1;
pRow2.add(new JLabel("Background color:"), constraints2);
constraints2.gridx++;
constraints2.weightx = 2;
ccbLegendBackground = new ColorChooserButton(pRow2, Color.LIGHT_GRAY);
pRow2.add(ccbLegendBackground, constraints2);
return panel;
}
use of mudmap2.backend.Path in project mudmap2 by Neop.
the class PathConnectNeighborsDialog method save.
private void save() {
for (Entry<Place, JCheckBox> entry : neighbor_checkboxes.entrySet()) {
if (entry.getValue().isSelected()) {
int dx = entry.getKey().getX() - place.getX();
int dy = entry.getKey().getY() - place.getY();
// get direction
String dir = Path.getDir(dx, dy);
// connect path
place.connectPath(new Path(place, dir, entry.getKey(), Path.getOppositeDir(dir)));
}
}
getParent().repaint();
}
use of mudmap2.backend.Path in project mudmap2 by Neop.
the class MapPainterDefault method paint.
@Override
public void paint(Graphics g, int tileSize, double graphicsWidth, double graphicsHeight, Layer layer, WorldCoordinate curPos) {
this.graphicsWidth = graphicsWidth;
this.graphicsHeight = graphicsHeight;
this.tileSize = tileSize;
this.curPos = curPos;
tileFont = g.getFont();
final float selectionStrokeWidth = getTileSelectionStrokeWidth();
final int tileBorderWidthScaled = getTileBorderWidth();
// max number of text lines tht fit in a tile
FontMetrics fm = g.getFontMetrics();
final int maxLines = (int) Math.round((double) (tileSize - 3 * (tileBorderWidthScaled + (int) Math.ceil(getRiskLevelStrokeWidth()))) / fm.getHeight());
final int maxLineLength = tileSize - 2 * (tileBorderWidthScaled + (int) selectionStrokeWidth + (int) Math.ceil(getRiskLevelStrokeWidth()));
final Boolean drawText = fm.stringWidth("WW") < (tileSize - 2 * (getRiskLevelStrokeWidth() + getTileBorderWidth()));
// screen center in world coordinates
// note: wdtwd2
final double screenCenterX = (graphicsWidth / tileSize) / 2.0;
final double screenCenterY = (graphicsHeight / tileSize) / 2.0;
final int placeXOffset = (int) (Math.round((float) curPos.getX()) - Math.round(screenCenterX));
final int placeYOffset = (int) (Math.round((float) curPos.getY()) - Math.floor(screenCenterY));
// more precalculation
final double placeXpxConst = remint(screenCenterX) - remint(curPos.getX());
final double placeYPXConst = remint(screenCenterY) + remint(curPos.getY());
// prepare graphic for paths
// Paths will be drawn on this graphic and later on copied to g
// to mask out the tile positions on graphic_path
ArrayList<Pair<Integer, Integer>> tilePositions = new ArrayList<>();
BufferedImage imagePath = new BufferedImage((int) graphicsWidth, (int) graphicsHeight, BufferedImage.TYPE_INT_ARGB);
Graphics graphicPath = imagePath.getGraphics();
((Graphics2D) graphicPath).setStroke(new BasicStroke(getPathStrokeWidth()));
((Graphics2D) graphicPath).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// getPlace the locations of copied places
HashSet<Pair<Integer, Integer>> copiedPlaceLocations = mudmap2.CopyPaste.getCopyPlaceLocations();
// clear screen
if (backgroundColor == null) {
g.clearRect(0, 0, (int) graphicsWidth + 1, (int) graphicsHeight + 1);
} else {
g.setColor(backgroundColor);
g.fillRect(0, 0, (int) graphicsWidth + 1, (int) graphicsHeight + 1);
}
// ------------------ draw the grid --------------------------------
if (isGridEnabled()) {
g.setColor(Color.lightGray);
for (int tileX = (g.getClipBounds().x / tileSize) - 1; tileX < graphicsWidth / tileSize + 1; ++tileX) {
final int x = (int) Math.round((tileX + placeXpxConst) * tileSize);
g.drawLine(x, 0, x, (int) graphicsHeight);
}
for (int tileY = (g.getClipBounds().y / tileSize) - 1; tileY < graphicsHeight / tileSize + 1; ++tileY) {
final int y = (int) Math.round((tileY + placeYPXConst) * tileSize);
g.drawLine(0, y, (int) graphicsWidth, y);
}
}
// ------------------ draw the tiles / places ----------------------
for (int tileX = (g.getClipBounds().x / tileSize) - 1; tileX < graphicsWidth / tileSize + 1; ++tileX) {
for (int tileY = (g.getClipBounds().y / tileSize) - 1; tileY < graphicsHeight / tileSize + 1; ++tileY) {
// place position on the map
final int placeX = tileX + placeXOffset;
final int placeY = (int) (graphicsHeight / tileSize) - tileY + placeYOffset;
if (layer != null && layer.exist(placeX, placeY)) {
Place curPlace = layer.get(placeX, placeY);
// place position in pixel on the screen
final int placeXpx = (int) Math.round((tileX + placeXpxConst) * tileSize);
final int placeYpx = (int) Math.round((tileY + placeYPXConst) * tileSize);
tilePositions.add(new Pair<>(placeXpx, placeYpx));
// number of drawn text lines
int lineNum = 0;
// draw place group color
if (curPlace.getPlaceGroup() != null) {
g.setColor(curPlace.getPlaceGroup().getColor());
g.fillRect(placeXpx, placeYpx, tileSize, tileSize);
}
// draw tile center color
if (drawText) {
g.setColor(layer.getWorld().getTileCenterColor());
g.fillRect(placeXpx + tileBorderWidthScaled, placeYpx + tileBorderWidthScaled, tileSize - 2 * tileBorderWidthScaled, tileSize - 2 * tileBorderWidthScaled);
}
// draw risk level border
if (curPlace.getRiskLevel() != null) {
g.setColor(curPlace.getRiskLevel().getColor());
((Graphics2D) g).setStroke(new BasicStroke(getRiskLevelStrokeWidth()));
g.drawRect(placeXpx + tileBorderWidthScaled, placeYpx + tileBorderWidthScaled, tileSize - 2 * tileBorderWidthScaled - (int) (0.5 * getRiskLevelStrokeWidth()), tileSize - 2 * tileBorderWidthScaled - (int) (0.5 * getRiskLevelStrokeWidth()));
}
LinkedList<String> text = new LinkedList<>();
String flags = "", exits = "";
// draw text, if tiles are large enough
if (drawText) {
g.setColor(Color.BLACK);
// place name
// gets place name if unique, else place name with ID
String placeName;
switch(layer.getWorld().getShowPlaceId()) {
default:
case UNIQUE:
case NONE:
// name only
placeName = curPlace.getName();
break;
case ALL:
// name and id
placeName = curPlace.toString();
break;
}
text.add(placeName);
int reclvlmin = curPlace.getRecLevelMin(), reclvlmax = curPlace.getRecLevelMax();
if (reclvlmin > -1 || reclvlmax > -1) {
String levelString = "lvl " + (reclvlmin > -1 ? reclvlmin : "?") + " - " + (reclvlmax > -1 ? reclvlmax : "?");
text.add(levelString);
}
// parents
if (lineNum < maxLines && !curPlace.getParents().isEmpty()) {
int parentsNum = curPlace.getParents().size();
String paStr = "Pa" + (parentsNum > 1 ? " (" + curPlace.getParents().size() + "): " : ": ");
boolean firstParent = true;
for (Place parent : curPlace.getParents()) {
paStr += (firstParent ? "" : ", ") + parent.getName();
firstParent = false;
}
text.add(paStr);
}
// children
if (lineNum < maxLines && !curPlace.getChildren().isEmpty()) {
int childrenNum = curPlace.getChildren().size();
String chStr = "Ch" + (childrenNum > 1 ? " (" + curPlace.getChildren().size() + "): " : ": ");
boolean firstChild = true;
for (Place child : curPlace.getChildren()) {
chStr += (firstChild ? "" : ", ") + child.getName();
firstChild = false;
}
text.add(chStr);
}
// flags
if (lineNum < maxLines) {
// place has comments
if (!curPlace.getComments().isEmpty())
flags += "Co";
if (!curPlace.getChildren().isEmpty())
flags += "Ch";
if (!curPlace.getParents().isEmpty())
flags += "Pa";
// other flags
for (Map.Entry<String, Boolean> flag : curPlace.getFlags().entrySet()) {
if (flag.getValue())
flags += flag.getKey().toUpperCase();
if (fm.stringWidth(flags) >= tileSize - 2 * tileBorderWidthScaled)
break;
}
}
}
// mark place group selection
if (isSelected(curPlace) || (mudmap2.CopyPaste.isCut() && mudmap2.CopyPaste.isMarked(curPlace))) {
g.setColor(new Color(255, 255, 255, 128));
g.fillRect(placeXpx, placeYpx, tileSize, tileSize);
}
// draw path lines here
boolean exitUp = false, exitDown = false, exitnstd = false;
if (getShowPaths()) {
for (Path path : curPlace.getPaths()) {
Place otherPlace = path.getOtherPlace(curPlace);
Color colorPlace1 = layer.getWorld().getPathColor(path.getExitDirections()[0]);
Color colorPlace2 = layer.getWorld().getPathColor(path.getExitDirections()[1]);
if (path.getPlaces()[0] != curPlace) {
Color tmp = colorPlace1;
colorPlace1 = colorPlace2;
colorPlace2 = tmp;
}
// usually the main place (path.getPlaces()[0]) draws the path. If it isn't on screen, the other place draws it
if (Objects.equals(otherPlace.getLayer().getId(), layer.getId()) && (path.getPlaces()[0] == curPlace || !isOnScreen(otherPlace))) {
Pair<Integer, Integer> exitOffset = getExitOffset(path.getExit(curPlace));
Pair<Integer, Integer> exitOffsetOther = getExitOffset(path.getExit(otherPlace));
boolean drawCurves = getPathsCurved();
// exit positions on the map
final double exit1x = placeXpx + exitOffset.first;
final double exit1y = placeYpx + exitOffset.second;
final double exit2x = placeXpx + (otherPlace.getX() - curPlace.getX()) * tileSize + exitOffsetOther.first;
final double exit2y = placeYpx - (otherPlace.getY() - curPlace.getY()) * tileSize + exitOffsetOther.second;
if (colorPlace1.equals(colorPlace2)) {
// same color
((Graphics2D) graphicPath).setPaint(colorPlace1);
} else {
// draw gradient
GradientPaint gp = new GradientPaint((float) exit1x, (float) exit1y, colorPlace1, (float) exit2x, (float) exit2y, colorPlace2);
((Graphics2D) graphicPath).setPaint(gp);
}
if (drawCurves) {
Pair<Double, Double> normal1 = getExitNormal(path.getExit(curPlace));
Pair<Double, Double> normal2 = getExitNormal(path.getExit(otherPlace));
double dx = exit2x - exit1x;
double dy = exit2y - exit1y;
if (drawCurves = Math.sqrt(dx * dx + dy * dy) >= 1.5 * tileSize) {
CubicCurve2D c = new CubicCurve2D.Double();
// point 1
c.setCurve(exit1x, exit1y, // point 2
exit1x + normal1.first * tileSize, exit1y - normal1.second * tileSize, // point 3
exit2x + normal2.first * tileSize, exit2y - normal2.second * tileSize, // point 4
exit2x, exit2y);
((Graphics2D) graphicPath).draw(c);
}
}
if (!drawCurves) {
graphicPath.drawLine((int) exit1x, (int) exit1y, (int) exit2x, (int) exit2y);
}
}
// draw exit dots, if tiles are larger than 20
if (tileSize >= 20) {
g.setColor(colorPlace1);
String exit = path.getExit(curPlace);
switch(exit) {
case "u":
exitUp = true;
break;
case "d":
exitDown = true;
break;
default:
Pair<Integer, Integer> exitOffset = getExitOffset(exit);
if (exitOffset.first != tileSize / 2 || exitOffset.second != tileSize / 2) {
int exitCircleRadius2 = getExitCircleRadius();
g.fillOval(placeXpx + exitOffset.first - exitCircleRadius2, placeYpx + exitOffset.second - exitCircleRadius2, 2 * exitCircleRadius2, 2 * exitCircleRadius2);
} else {
// non-standard exit
exitnstd = true;
}
break;
}
}
}
}
// draw exits
if (tileSize >= 20 && (exitUp || exitDown) && drawText && lineNum <= maxLines) {
// have some arrows: ⬆⬇ ↑↓
exits = "" + (exitnstd ? "+" : "") + (exitUp ? "↑" : "") + (exitDown ? "↓" : "");
}
g.setColor(Color.BLACK);
final int border = (int) (tileBorderWidthScaled + getRiskLevelStrokeWidth());
drawText(g, placeXpx + border, placeYpx + border, tileSize - 2 * border, tileSize - 2 * border, text, flags, exits);
}
// TODO: extract from parent loop
if (copiedPlaceLocations != null) {
boolean locationFound = false;
for (Pair<Integer, Integer> location : copiedPlaceLocations) {
if (location.first == placeX - placeSelectedX && location.second == placeY - placeSelectedY) {
locationFound = true;
break;
}
}
if (locationFound) {
// alternative: getScreenPosX();
int placeXpx = (int) ((tileX + remint(screenCenterX) - remint(curPos.getX())) * tileSize);
int placeYpx = (int) ((tileY + remint(screenCenterY) + remint(curPos.getY())) * tileSize);
drawCursor(g, Color.BLUE, placeXpx, placeYpx, selectionStrokeWidth);
}
}
// draw cursor / place selection
if (placeSelectionEnabled && placeX == placeSelectedX && placeY == placeSelectedY) {
// alternative: getScreenPosX();
int placeXpx = (int) ((tileX + remint(screenCenterX) - remint(curPos.getX())) * tileSize);
int placeYpx = (int) ((tileY + remint(screenCenterY) + remint(curPos.getY())) * tileSize);
drawCursor(g, TILE_SELECTION_COLOR, placeXpx, placeYpx, selectionStrokeWidth);
}
}
}
// mask out tile positions on graphicPath
((Graphics2D) graphicPath).setBackground(new Color(0, 0, 0, 0));
int clearTileSize = tileSize - 2 * tileBorderWidthScaled;
for (Pair<Integer, Integer> p : tilePositions) // graphicPath.clearRect(p.first, p.second, p.first + tileSize, p.second + tileSize);
graphicPath.clearRect(p.first + tileBorderWidthScaled, p.second + tileBorderWidthScaled, clearTileSize, clearTileSize);
// draw graphicPath to g
if (getShowPaths())
g.drawImage(imagePath, 0, 0, null);
graphicPath.dispose();
}
use of mudmap2.backend.Path in project mudmap2 by Neop.
the class CopyPaste method paste.
/**
* Pastes the cut / copied places to layer, if possible
* @param x
* @param y
* @param layer
* @return false on error or user abort
*/
public static boolean paste(int x, int y, Layer layer) {
if (!canPaste(x, y, layer))
return false;
// ask user
String title = (copyMode ? "Copy " : "Paste ") + "place(s)";
String message = title + "? This can not be undone!" + (copyPlaces.iterator().next().getLayer().getWorld() != layer.getWorld() ? " Pasting to another world might cause problems!" : "");
int ret = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
if (ret == JOptionPane.YES_OPTION) {
// map to translate from old to new place
HashMap<Place, Place> place_to_new_place = new HashMap<Place, Place>();
Place[] places;
if (copyMode) {
places = copyPlaces.toArray(new Place[copyPlaces.size()]);
} else {
// getPlace movement direction
final int fact_x = (x <= copydx ? 1 : -1);
final int fact_y = (y <= copydy ? 1 : -1);
// sort places
ArrayList<Place> ordered_places = new ArrayList<>(copyPlaces);
Collections.sort(ordered_places, new Comparator<Place>() {
@Override
public int compare(Place t, Place t1) {
// list will be moved first
if (fact_x * t.getX() > fact_x * t1.getX())
return 1;
else if (t.getX() == t1.getX()) {
if (fact_y * t.getY() > fact_y * t1.getY())
return 1;
else if (t.getY() == t1.getY())
return 0;
}
return -1;
}
});
places = ordered_places.toArray(new Place[ordered_places.size()]);
}
// copy places
for (Place place : places) {
try {
if (place.getLayer().getWorld() != layer.getWorld()) {
if (place.getPlaceGroup() != null && !layer.getWorld().getPlaceGroups().contains(place.getPlaceGroup()))
layer.getWorld().addPlaceGroup(place.getPlaceGroup());
}
if (copyMode) {
// copy places -> duplicate on new layer
Place new_place = place.duplicate();
place_to_new_place.put(place, new_place);
layer.put(new_place, place.getX() - copydx + x, place.getY() - copydy + y);
} else {
// remove place from old layer
Layer layerOld = place.getLayer();
layerOld.remove(place);
// add place to new layer
place.setLayer(layer);
layer.put(place, place.getX() - copydx + x, place.getY() - copydy + y);
}
} catch (Exception ex) {
Logger.getLogger(Mudmap2.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
// recreate paths and child connections after copy-paste
if (copyMode) {
for (Place place : copyPlaces) {
Place new_place = place_to_new_place.get(place);
// connect paths
for (Path path : place.getPaths()) {
// only check first place, because the other side will
// check itself
Place path_end_place = path.getPlaces()[0];
// if end place is not this place and is also copied
if (path_end_place != place && copyPlaces.contains(path_end_place)) {
Place other_new_place = place_to_new_place.get(path_end_place);
new_place.connectPath(new Path(other_new_place, path.getExitDirections()[0], new_place, path.getExitDirections()[1]));
}
}
// connect children
for (Place child : place.getChildren()) {
// if child is copied, too
if (copyPlaces.contains(child)) {
Place new_child = place_to_new_place.get(child);
new_place.connectChild(new_child);
}
}
}
// moving places modifies their coordinates so that they cant be pasted again
} else
resetCopy();
}
// don't clean up but change cut to copy
return true;
}
Aggregations