20 package net.sf.gridarta.gui.panel.selectedsquare;
22 import javax.swing.DefaultListModel;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
45 private final DefaultListModel<G>
model;
75 if (mapSquare ==
null) {
76 model.removeAllElements();
81 int currentSelectionIndex = -1;
82 int firstVisibleIndex = -1;
86 boolean foundVisibleIndex =
false;
87 for (
final G node : mapSquare.reverse()) {
89 if (node == gameObject) {
97 foundVisibleIndex =
true;
101 if (currentSelectionIndex == -1 && tmpSelect != -1) {
102 currentSelectionIndex = tmpSelect;
109 final int selectedIndex;
110 if (currentSelectionIndex != -1) {
111 selectedIndex = currentSelectionIndex;
112 }
else if (firstVisibleIndex != -1) {
113 selectedIndex = firstVisibleIndex;
117 return selectedIndex;
127 private int addInvObjects(@NotNull
final G node, @Nullable
final G gameObject) {
128 int selListCounter = -1;
129 for (
final G invObject : node.getHead().reverse()) {
130 if (invObject == gameObject) {
135 final int tmpListCounter =
addInvObjects(invObject, gameObject);
136 if (tmpListCounter != -1) {
137 selListCounter = tmpListCounter;
140 return selListCounter;
153 model.addElement(gameObject);