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;
}
}
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);
}
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());
}
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());
}
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);
}
}
Aggregations