 |
Gridarta Editor
|
Go to the documentation of this file.
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);
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);
175 dialog.setLocationRelativeTo(parent);
185 for (
final Iterable<G> mapSquare : mapModel) {
186 for (
final G gameObject : mapSquare) {
190 exits.add(gameObject);
197 for (
final G exit : exits) {
201 list.setSelectedIndex(0);
202 list.ensureIndexIsVisible(0);
229 final int index =
list.getMinSelectionIndex();
230 final int newIndex = (index > 0 ? index :
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 :
listModel.size()) - 1;
316 list.addSelectionInterval(newIndex, newIndex);
317 list.ensureIndexIsVisible(newIndex);
326 final int index =
list.getMaxSelectionIndex();
328 final int newIndex = index + 1;
329 list.addSelectionInterval(newIndex, newIndex);
330 list.ensureIndexIsVisible(newIndex);
339 final G selectedValue =
list.getSelectedValue();
A MapModel reflects the data of a map.
A net.sf.gridarta.gui.panel.connectionview.CellRenderer for the locked items view.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
Base package of all Gridarta classes.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
final JDialog dialog
The JDialog instance.
Interface for classes that match GameObjects.
Provider for faces of GameObjects and Archetypes.
Reflects a game object (object on a map).
final DefaultListModel< G > listModel
The list model containing the search results.
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches a GameObject.
void showDialog()
Opens the dialog.
boolean goExit()
Opens the selected maps.
void goExitScrollBottom()
Action method for scroll bottom.
static void addAction(@NotNull final JComponent textComponent, @NotNull final Action action)
Adds an accelerator key for a component.
Helper class for entering maps.
Graphical User Interface of Gridarta.
void goExitScrollUp()
Action method for scroll up.
void goExitSelectUp()
Action method for select up.
final EnterMap< G, A, R > enterMap
The EnterMap instance for entering maps.
GameObjects are the objects based on Archetypes found on maps.
static MapLocation newAbsoluteMapLocation(@NotNull final GameObject<?, ?, ?> gameObject, final boolean allowRandomMapParameters)
Creates a new instance from a BaseObject instance.
Classes related to matching {GameObjects}, so called { net.sf.gridarta.model.match....
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.
Utility class for Swing related functions.
Interface for MapArchObjects.
final GameObjectMatcher exitGameObjectMatcher
The GameObjectMatcher for selecting exits.
void goExitScrollPageDown()
Action method for scroll page down.
Exception thrown if a game object does not specify a valid exit path.
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.
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.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
void goExitScrollDown()
Action method for scroll down.
void goExitApply()
Action method for apply.
static final JButton[] EMPTY_BUTTON_ARRAY
An empty array of JButton instances.
A dialog to ask the user for a map to open.
void goExitScrollTop()
Action method for scroll top.
final MapListCellRenderer mapListCellRenderer
The MapListCellRenderer for list.
Base classes for rendering maps.
The face is the appearance of an object.
void goExitSelectDown()
Action method for select down.
void goExitCancel()
Action method for cancel.
Currently nothing more than a marker interface for unification.
Utility class for ActionBuilder related functions.
MapModel< G, A, R > getMapModel()
Returns the map model.
void goExitScrollPageUp()
Action method for scroll page up.
final MapView< G, A, R > mapView
The MapView for this dialog.
final JList< G > list
The JList showing the matching maps.