Search in sources :

Example 1 with Place

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));
}
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 2 with Place

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));
        }
    });
}
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 3 with Place

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

Example 4 with Place

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");
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate) Layer(mudmap2.backend.Layer) Pair(mudmap2.utils.Pair) HashSet(java.util.HashSet)

Example 5 with Place

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;
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) ButtonGroup(javax.swing.ButtonGroup) ColorChooserButton(mudmap2.frontend.GUIElement.ColorChooserButton) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) Font(java.awt.Font)

Aggregations

Place (mudmap2.backend.Place)20 Layer (mudmap2.backend.Layer)14 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 JLabel (javax.swing.JLabel)7 Path (mudmap2.backend.Path)7 PlaceGroup (mudmap2.backend.PlaceGroup)7 WorldCoordinate (mudmap2.backend.WorldCoordinate)7 Color (java.awt.Color)6 GridBagConstraints (java.awt.GridBagConstraints)6 GridBagLayout (java.awt.GridBagLayout)6 JButton (javax.swing.JButton)6 Insets (java.awt.Insets)5 Pair (mudmap2.utils.Pair)5 HashMap (java.util.HashMap)4 JCheckBox (javax.swing.JCheckBox)4 World (mudmap2.backend.World)4 Dimension (java.awt.Dimension)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3