Search in sources :

Example 1 with MapCursorListener

use of mudmap2.frontend.GUIElement.WorldPanel.MapCursorListener 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 2 with MapCursorListener

use of mudmap2.frontend.GUIElement.WorldPanel.MapCursorListener in project mudmap2 by Neop.

the class WorldPanel method callCursorListeners.

/**
 * calls all place selection listeners
 */
private void callCursorListeners() {
    Layer layer = getWorld().getLayer(getPosition().getLayer());
    Place place = null;
    if (layer != null) {
        place = layer.get(getCursorX(), getCursorY());
    }
    if (place != null) {
        for (MapCursorListener listener : mapCursorListeners) listener.placeSelected(place);
        callPlaceSelectionListeners(place);
    } else {
        for (MapCursorListener listener : mapCursorListeners) listener.placeDeselected(layer, getCursorX(), getCursorY());
    }
    repaint();
}
Also used : Layer(mudmap2.backend.Layer) Place(mudmap2.backend.Place)

Aggregations

Layer (mudmap2.backend.Layer)2 Place (mudmap2.backend.Place)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 LinkedList (java.util.LinkedList)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 WorldCoordinate (mudmap2.backend.WorldCoordinate)1 MapCursorListener (mudmap2.frontend.GUIElement.WorldPanel.MapCursorListener)1 MapPainterDefault (mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault)1 WorldTab (mudmap2.frontend.WorldTab)1