Search in sources :

Example 1 with WorldTab

use of mudmap2.frontend.WorldTab in project mudmap2 by Neop.

the class Mainwindow method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    WorldTab wt = getSelectedTab();
    switch(e.getActionCommand()) {
        case "new_world":
            createNewWorld();
            break;
        case "save_world":
            if (wt != null)
                wt.save();
            break;
        case "save_world_as":
            if (wt != null) {
                SaveWorldDialog dlg = new SaveWorldDialog(Mainwindow.this, wt);
                int ret = dlg.showSaveDialog(wt);
                if (ret == JFileChooser.APPROVE_OPTION) {
                    wt.getWorld().setWorldFile(dlg.getWorldFile());
                    wt.setFilename(dlg.getSelectedFile().getAbsolutePath());
                    wt.save();
                }
            }
            break;
        case "export_image":
            if (wt != null) {
                ExportImageDialog dlg = new ExportImageDialog(Mainwindow.this, wt);
                dlg.setVisible(true);
            }
            break;
        case "quit":
            quit();
            break;
        case "edit_world":
            if (wt != null) {
                (new EditWorldDialog(Mainwindow.this, wt.getWorld())).setVisible(true);
            }
            break;
        case "path_colors":
            if (wt != null) {
                (new PathColorDialog(Mainwindow.this, wt.getWorld())).setVisible(true);
                wt.repaint();
            }
            break;
        case "add_place_group":
            if (wt != null)
                (new PlaceGroupDialog(Mainwindow.this, wt.getWorld())).setVisible(true);
            break;
        case // set home position
        "set_home":
            if (wt != null)
                wt.getWorldPanel().setHome();
            break;
        case // go to home position
        "goto_home":
            if (wt != null)
                wt.getWorldPanel().gotoHome();
            break;
        default:
            String message = getClass().getName() + ": ActionCommand not recognized";
            Logger.getLogger(WorldManager.class.getName()).log(Level.SEVERE, message);
            JOptionPane.showMessageDialog(this, message, "MUD Map error", JOptionPane.ERROR_MESSAGE);
            break;
    }
}
Also used : PlaceGroupDialog(mudmap2.frontend.dialog.PlaceGroupDialog) SaveWorldDialog(mudmap2.frontend.dialog.SaveWorldDialog) PathColorDialog(mudmap2.frontend.dialog.PathColorDialog) EditWorldDialog(mudmap2.frontend.dialog.EditWorldDialog) ExportImageDialog(mudmap2.frontend.dialog.ExportImageDialog)

Example 2 with WorldTab

use of mudmap2.frontend.WorldTab 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);
}
Also used : WorldTab(mudmap2.frontend.WorldTab) GridBagConstraints(java.awt.GridBagConstraints) WorldCoordinate(mudmap2.backend.WorldCoordinate) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Layer(mudmap2.backend.Layer) LinkedList(java.util.LinkedList) MapCursorListener(mudmap2.frontend.GUIElement.WorldPanel.MapCursorListener) ActionListener(java.awt.event.ActionListener) MapPainterDefault(mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault) Place(mudmap2.backend.Place)

Example 3 with WorldTab

use of mudmap2.frontend.WorldTab in project mudmap2 by Neop.

the class WorldTabTest method testGetWorld.

/**
 * Test of getWorld method, of class WorldTab.
 */
@Test
public void testGetWorld() {
    System.out.println("getWorld");
    WorldTab instance = new WorldTab(null, new World(), false);
    assertNotNull(instance.getWorld());
    instance = new WorldTab(null, new World(), true);
    assertNotNull(instance.getWorld());
    instance = new WorldTab(null, new World(), "", false);
    assertNotNull(instance.getWorld());
    instance = new WorldTab(null, new World(), "", true);
    assertNotNull(instance.getWorld());
    instance = new WorldTab(instance);
    assertNotNull(instance.getWorld());
}
Also used : World(mudmap2.backend.World) Test(org.junit.Test)

Example 4 with WorldTab

use of mudmap2.frontend.WorldTab in project mudmap2 by Neop.

the class WorldTabTest method testCreateLayer.

/**
 * Test of save method, of class WorldTab.
 */
/*@Test
    public void testSave() {
        System.out.println("save");
        WorldTab instance = null;
        instance.save();
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }*/
/**
 * Test of showMessage method, of class WorldTab.
 */
/*@Test
    public void testShowMessage() {
        System.out.println("showMessage");
        String message = "";
        WorldTab instance = null;
        instance.showMessage(message);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }*/
/**
 * Test of layerSelected method, of class WorldTab.
 */
/*@Test
    public void testLayerSelected() {
        System.out.println("layerSelected");
        Layer layer = null;
        MouseEvent event = null;
        WorldTab instance = null;
        instance.layerSelected(layer, event);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }*/
/**
 * Test of createLayer method, of class WorldTab.
 */
@Test
public void testCreateLayer() {
    System.out.println("createLayer");
    World world = new World();
    WorldTab instance = new WorldTab(null, world, false);
    int layerCnt = world.getLayers().size();
    instance.createLayer();
    assertEquals(layerCnt + 1, world.getLayers().size());
}
Also used : World(mudmap2.backend.World) Test(org.junit.Test)

Example 5 with WorldTab

use of mudmap2.frontend.WorldTab 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);
    }
}
Also used : MapPainterDefault(mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault) WorldManager(mudmap2.backend.WorldManager) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Aggregations

World (mudmap2.backend.World)5 WorldCoordinate (mudmap2.backend.WorldCoordinate)4 Test (org.junit.Test)4 Layer (mudmap2.backend.Layer)3 Place (mudmap2.backend.Place)3 Color (java.awt.Color)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Path (mudmap2.backend.Path)2 PlaceGroup (mudmap2.backend.PlaceGroup)2 RiskLevel (mudmap2.backend.RiskLevel)2 WorldFileInvalidTypeException (mudmap2.backend.WorldFileReader.Exception.WorldFileInvalidTypeException)2 MapPainterDefault (mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault)2 WorldTab (mudmap2.frontend.WorldTab)2 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1