Search in sources :

Example 1 with World

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

Example 2 with World

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));
}
Also used : JPanel(javax.swing.JPanel) AboutDialog(mudmap2.frontend.dialog.AboutDialog) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) OpenWorldDialog(mudmap2.frontend.dialog.OpenWorldDialog) JSeparator(javax.swing.JSeparator) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 3 with World

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));
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) SidePanel(mudmap2.frontend.sidePanel.SidePanel) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) PlaceSelectionListener(mudmap2.frontend.GUIElement.WorldPanel.PlaceSelectionListener) WorldPanel(mudmap2.frontend.GUIElement.WorldPanel.WorldPanel) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ScrollLabel(mudmap2.frontend.GUIElement.ScrollLabel) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) Place(mudmap2.backend.Place)

Example 4 with World

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");
}
Also used : JFileChooser(javax.swing.JFileChooser) WorldFile(mudmap2.backend.WorldFileReader.WorldFile) IOException(java.io.IOException) WorldFileJSON(mudmap2.backend.WorldFileReader.current.WorldFileJSON) WorldFile(mudmap2.backend.WorldFileReader.WorldFile) File(java.io.File) WorldFileDefault(mudmap2.backend.WorldFileReader.current.WorldFileDefault)

Example 5 with World

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

Aggregations

World (mudmap2.backend.World)31 Test (org.junit.Test)27 IOException (java.io.IOException)11 FileNotFoundException (java.io.FileNotFoundException)9 Place (mudmap2.backend.Place)9 File (java.io.File)7 WorldFileDefault (mudmap2.backend.WorldFileReader.current.WorldFileDefault)7 Layer (mudmap2.backend.Layer)6 Path (mudmap2.backend.Path)6 WorldCoordinate (mudmap2.backend.WorldCoordinate)6 Color (java.awt.Color)5 HashMap (java.util.HashMap)5 WorldFile (mudmap2.backend.WorldFileReader.WorldFile)5 PlaceGroup (mudmap2.backend.PlaceGroup)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 Map (java.util.Map)3 JLabel (javax.swing.JLabel)3 RiskLevel (mudmap2.backend.RiskLevel)3 BorderLayout (java.awt.BorderLayout)2