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