20 package net.sf.gridarta.gui.dialog.goexit;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.event.MouseEvent;
25 import java.awt.event.MouseListener;
26 import java.util.Collection;
27 import java.util.TreeSet;
28 import javax.swing.DefaultListModel;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JList;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.ListSelectionModel;
36 import javax.swing.ScrollPaneConstants;
37 import javax.swing.WindowConstants;
51 import net.
sf.japi.swing.action.ActionBuilder;
52 import net.
sf.japi.swing.action.ActionBuilderFactory;
53 import net.
sf.japi.swing.action.ActionMethod;
54 import org.jetbrains.annotations.NotNull;
66 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
102 private final DefaultListModel<G>
listModel =
new DefaultListModel<>();
130 list.setFocusable(
false);
131 final Component scrollPane =
new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
133 list.setCellRenderer(mapListCellRenderer);
134 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
135 final MouseListener mouseListener =
new MouseListener() {
138 public void mouseClicked(
final MouseEvent e) {
143 public void mousePressed(
final MouseEvent e) {
144 if (e.getClickCount() > 1) {
150 public void mouseReleased(
final MouseEvent e) {
155 public void mouseEntered(
final MouseEvent e) {
160 public void mouseExited(
final MouseEvent e) {
165 list.addMouseListener(mouseListener);
166 list.setFocusable(
true);
168 final JPanel panel =
new JPanel(
new BorderLayout());
169 panel.add(scrollPane, BorderLayout.CENTER);
170 final JOptionPane optionPane =
new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, EMPTY_BUTTON_ARRAY, list);
172 dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
173 dialog.setResizable(
true);
174 dialog.setSize(500, 250);
175 dialog.setLocationRelativeTo(parent);
185 for (
final Iterable<G> mapSquare : mapModel) {
186 for (
final G gameObject : mapSquare) {
187 if (exitGameObjectMatcher.
isMatching(gameObject)) {
190 exits.add(gameObject);
197 for (
final G exit : exits) {
198 listModel.addElement(exit);
201 list.setSelectedIndex(0);
202 list.ensureIndexIsVisible(0);
203 dialog.setVisible(
true);
229 final int index = list.getMinSelectionIndex();
230 final int newIndex = index > 0 ? index - 1 : listModel.size() - 1;
231 list.setSelectedIndex(newIndex);
232 list.ensureIndexIsVisible(newIndex);
240 final int index = list.getMaxSelectionIndex() + 1;
241 final int newIndex = index < listModel.size() ? index : 0;
242 list.setSelectedIndex(newIndex);
243 list.ensureIndexIsVisible(newIndex);
251 final int index = list.getMinSelectionIndex();
252 final int firstIndex = list.getFirstVisibleIndex();
254 if (firstIndex == -1) {
256 }
else if (index == -1) {
257 newIndex = firstIndex;
258 }
else if (index > firstIndex) {
259 newIndex = firstIndex;
261 newIndex = Math.max(firstIndex - (list.getLastVisibleIndex() - firstIndex), 0);
263 list.setSelectedIndex(newIndex);
264 list.ensureIndexIsVisible(newIndex);
272 final int index = list.getMaxSelectionIndex();
273 final int lastIndex = list.getLastVisibleIndex();
275 if (lastIndex == -1) {
277 }
else if (index == -1) {
278 newIndex = lastIndex;
279 }
else if (index < lastIndex) {
280 newIndex = lastIndex;
282 newIndex = Math.min(lastIndex + (lastIndex - list.getFirstVisibleIndex()), listModel.size() - 1);
284 list.setSelectedIndex(newIndex);
285 list.ensureIndexIsVisible(newIndex);
293 final int newIndex = 0;
294 list.setSelectedIndex(newIndex);
295 list.ensureIndexIsVisible(newIndex);
303 final int newIndex = listModel.size() - 1;
304 list.setSelectedIndex(newIndex);
305 list.ensureIndexIsVisible(newIndex);
313 final int index = list.getMinSelectionIndex();
315 final int newIndex = index > 0 ? index - 1 : listModel.size() - 1;
316 list.addSelectionInterval(newIndex, newIndex);
317 list.ensureIndexIsVisible(newIndex);
326 final int index = list.getMaxSelectionIndex();
327 if (index + 1 < listModel.size()) {
328 final int newIndex = index + 1;
329 list.addSelectionInterval(newIndex, newIndex);
330 list.ensureIndexIsVisible(newIndex);
339 final G selectedValue = list.getSelectedValue();
340 if (selectedValue == null) {
343 return enterMap.
enterExit(mapView, selectedValue,
true);
void goExitScrollUp()
Action method for scroll up.
GoExitDialog(@NotNull final Component parent, @NotNull final MapView< G, A, R > mapView, @NotNull final GameObjectMatcher exitGameObjectMatcher, @NotNull final EnterMap< G, A, R > enterMap, @NotNull final FaceObjectProviders faceObjectProviders)
Creates a new instance.
void goExitScrollTop()
Action method for scroll top.
A MapModel reflects the data of a map.
Graphical User Interface of Gridarta.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
Exception thrown if a game object does not specify a valid exit path.
final GameObjectMatcher exitGameObjectMatcher
The GameObjectMatcher for selecting exits.
void goExitScrollDown()
Action method for scroll down.
void goExitApply()
Action method for apply.
final MapListCellRenderer mapListCellRenderer
The MapListCellRenderer for list.
void goExitSelectDown()
Action method for select down.
void goExitCancel()
Action method for cancel.
void goExitScrollPageUp()
Action method for scroll page up.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
static final JButton [] EMPTY_BUTTON_ARRAY
An empty array of JButton instances.
Utility class for Swing related functions.
MapModel< G, A, R > getMapModel()
Returns the map model.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
boolean enterExit(@NotNull final MapView< G, A, R > mapView, @NotNull final GameObject< G, A, R > exit, final boolean allowRandomMapParameters)
Opens the map an exit game object points to.
final JList< G > list
The JList showing the matching maps.
final MapView< G, A, R > mapView
The MapView for this dialog.
GameObjects are the objects based on Archetypes found on maps.
A net.sf.gridarta.gui.panel.connectionview.CellRenderer for the locked items view.
Base classes for rendering maps.
Utility class for ActionBuilder related functions.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
static MapLocation newAbsoluteMapLocation(@NotNull final GameObject<?, ?, ?> gameObject, final boolean allowRandomMapParameters)
Creates a new instance from a BaseObject instance.
Currently nothing more than a marker interface for unification.
final EnterMap< G, A, R > enterMap
The EnterMap instance for entering maps.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Represents a location on a map consisting of a map path and a map coordinate.
void goExitScrollBottom()
Action method for scroll bottom.
Helper class for entering maps.
final DefaultListModel< G > listModel
The list model containing the search results.
void goExitSelectUp()
Action method for select up.
void showDialog()
Opens the dialog.
boolean goExit()
Opens the selected maps.
final JDialog dialog
The JDialog instance.
Interface for MapArchObjects.
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches an GameObject.
A dialog to ask the user for a map to open.
void goExitScrollPageDown()
Action method for scroll page down.
static void addAction(@NotNull final JComponent textComponent, @NotNull final Action action)
Adds an accelerator key for a component.