use of mudmap2.backend.Place 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.Place 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.Place in project mudmap2 by Neop.
the class WorldTab method updateInfobar.
// ========================== Place selection ==============================
/**
* Updates the infobar
*/
private void updateInfobar() {
if (labelInfobar != null) {
if (worldPanel.isCursorEnabled()) {
Layer layer = getWorld().getLayer(worldPanel.getPosition().getLayer());
if (layer != null && layer.exist(worldPanel.getCursorX(), worldPanel.getCursorY())) {
Place pl;
pl = layer.get(worldPanel.getCursorX(), worldPanel.getCursorY());
boolean has_place_group = pl.getPlaceGroup() != null;
boolean has_comments = !pl.getComments().isEmpty();
String infotext = pl.getName();
if (has_place_group || has_comments)
infotext += " (";
if (has_place_group)
infotext += pl.getPlaceGroup().getName();
if (has_comments)
infotext += (has_place_group ? ", " : "") + pl.getCommentsString(false);
if (has_place_group || has_comments)
infotext += ")";
labelInfobar.setText(infotext);
} else {
labelInfobar.setText("");
}
} else
labelInfobar.setText("");
}
}
use of mudmap2.backend.Place in project mudmap2 by Neop.
the class ExportImageDialog method updateImageSize.
/**
* Updates the displayed image size
*/
void updateImageSize() {
if (centerPosition == null) {
centerPosition = new WorldCoordinate(worldTab.getWorldPanel().getPosition());
}
Pair<Integer, Integer> imageSize = new Pair<>(0, 0);
if (rbCurrentView.isSelected()) {
imageSize.first = worldTab.getWorldPanel().getWidth();
imageSize.second = worldTab.getWorldPanel().getHeight();
} else if (rbCurrentMap.isSelected()) {
Layer layer = worldTab.getWorld().getLayer(centerPosition.getLayer());
imageSize = getMapSize(layer);
} else if (rbAllMaps.isSelected()) {
for (Layer layer : worldTab.getWorld().getLayers()) {
// get largest image by area
Pair<Integer, Integer> imageSize2 = getMapSize(layer);
if (imageSize.first * imageSize.second < imageSize2.first * imageSize2.second) {
imageSize = imageSize2;
}
}
} else if (rbSelection.isSelected()) {
HashSet<Place> places = worldTab.getWorldPanel().placeGroupGetSelection();
imageSize = getSelectionSize(places);
}
imageWidth = imageSize.first;
imageHeight = imageSize.second;
lImageSize.setText("Image size: " + imageWidth + "x" + imageHeight + "px");
}
use of mudmap2.backend.Place 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;
}
Aggregations