use of mudmap2.backend.World in project mudmap2 by Neop.
the class Mainwindow method createNewWorld.
public void createNewWorld() {
String name = JOptionPane.showInputDialog(this, "Enter new world name", "New world", JOptionPane.PLAIN_MESSAGE);
if (name != null && !name.isEmpty()) {
// create a new world
try {
World world = WorldManager.createWorld(name);
createTab(world, null);
} catch (Exception ex) {
Logger.getLogger(Mainwindow.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(this, "Couldn't create world \"" + name + "\":\n" + ex.getMessage());
}
}
}
use of mudmap2.backend.World 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.World in project mudmap2 by Neop.
the class WorldTab method createGui.
/**
* Creates the GUI elements
*/
private void createGui(World world, boolean passive) {
setLayout(new BorderLayout());
worldPanel = new WorldPanel(parentFrame, world, passive);
add(worldPanel, BorderLayout.CENTER);
worldPanel.addTileSiteListener(this);
worldPanel.addStatusListener(this);
worldPanel.addPlaceSelectionListener(new PlaceSelectionListener() {
@Override
public void placeSelected(Place place) {
updateInfobar();
}
@Override
public void placeDeselected(Place place) {
updateInfobar();
}
});
sidePanel = new SidePanel(world);
add(sidePanel, BorderLayout.EAST);
sidePanel.addLayerPanelListener(this);
sidePanel.addPlacePanelListener(this);
add(panelSouth = new JPanel(), BorderLayout.SOUTH);
panelSouth.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets(1, 2, 0, 2);
// add bottom panel elements
// previous / next buttons for the history
JButton button_prev = new JButton("Prev");
constraints.gridx++;
panelSouth.add(button_prev, constraints);
button_prev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
worldPanel.popPosition();
}
});
JButton button_next = new JButton("Next");
constraints.gridx++;
panelSouth.add(button_next, constraints);
button_next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
worldPanel.restorePosition();
}
});
constraints.gridx++;
constraints.weightx = 1.0;
constraints.fill = GridBagConstraints.BOTH;
panelSouth.add(labelInfobar = new ScrollLabel(), constraints);
labelInfobar.startThread();
// set default selected place to hte center place
worldPanel.setCursor((int) Math.round(worldPanel.getPosition().getX()), (int) Math.round(worldPanel.getPosition().getY()));
constraints.gridx++;
constraints.weightx = 0.0;
constraints.fill = GridBagConstraints.NONE;
panelSouth.add(new JLabel("Map zoom:"), constraints);
constraints.gridx++;
sliderZoom = new JSlider(0, 100, (int) (100.0 / WorldPanel.TILE_SIZE_MAX * worldPanel.getTileSize()));
panelSouth.add(sliderZoom, constraints);
sliderZoom.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent arg0) {
worldPanel.setTileSize((int) ((double) worldPanel.TILE_SIZE_MAX * ((JSlider) arg0.getSource()).getValue() / 100.0));
}
});
}
use of mudmap2.backend.World in project mudmap2 by Neop.
the class WorldTab method save.
/**
* Saves the changes in the world
*/
public void save() {
if (!worldPanel.isPassive()) {
WorldFile worldFile = getWorld().getWorldFile();
if (worldFile == null) {
if (filename == null || filename.isEmpty() || (new File(filename)).exists()) {
// get new filename
int ret;
do {
JFileChooser fileChooser = new JFileChooser(Environment.getWorldsDir());
ret = fileChooser.showSaveDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
filename = fileChooser.getSelectedFile().getAbsolutePath();
} else {
ret = JOptionPane.showConfirmDialog(this, "No file chosen: " + getWorld().getName() + " will not be saved!", "Saving world", JOptionPane.OK_CANCEL_OPTION);
if (ret == JOptionPane.OK_OPTION)
return;
}
} while (ret != JFileChooser.APPROVE_OPTION || ret != JOptionPane.OK_OPTION);
}
worldFile = new WorldFileDefault(filename);
getWorld().setWorldFile(worldFile);
}
// set meta data writer
if (worldFile.getWorldFileType() == WorldFileType.JSON) {
WorldFileJSON wfj = null;
if (worldFile instanceof WorldFileJSON) {
wfj = (WorldFileJSON) worldFile;
} else if (worldFile instanceof WorldFileDefault) {
wfj = (WorldFileJSON) ((WorldFileDefault) worldFile).getWorldFile();
}
if (wfj != null)
wfj.setMetaGetter(this);
}
// write world file
try {
worldFile.writeFile(getWorld());
WorldManager.putWorld(worldFile.getFilename(), getWorld());
} catch (IOException ex) {
Logger.getLogger(WorldTab.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(getParent(), "Could not save world file " + worldFile.getFilename(), "Saving world file", JOptionPane.ERROR_MESSAGE);
}
}
showMessage("World saved");
}
use of mudmap2.backend.World in project mudmap2 by Neop.
the class PlaceGroupDialog method save.
private void save() {
// add new PlaceGroup to world and place
if (new_group) {
placeGroup = new PlaceGroup(textfield_name.getText(), colorchooserbutton.getColor());
world.addPlaceGroup(placeGroup);
if (place != null && place_group == null)
place.setPlaceGroup(placeGroup);
} else {
// modify PlaceGroup
placeGroup.setName(textfield_name.getText());
placeGroup.setColor(colorchooserbutton.getColor());
}
// assign to all places
if (place_group != null)
for (Place pl : place_group) pl.setPlaceGroup(placeGroup);
getParent().repaint();
}
Aggregations