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