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) {
96 firstVisibleIndex = updateIndex - 1;
97 foundVisibleIndex =
true;
101 if (currentSelectionIndex == -1 && tmpSelect != -1) {
102 currentSelectionIndex = tmpSelect;
105 if (updateIndex < model.size()) {
106 model.removeRange(updateIndex, model.size() - 1);
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;
148 if (updateIndex < model.size()) {
149 if (model.get(updateIndex) != gameObject) {
150 model.set(updateIndex, gameObject);
153 model.addElement(gameObject);
Base class for classes that contain GameObjects as children in the sense of containment.
boolean isEditType(int editType)
Get information on the current state of edit type.
int updateIndex
The next index to update.
ModelUpdater(@NotNull final DefaultListModel< G > model, @NotNull final MapViewSettings mapViewSettings)
Creates a new instance.
final DefaultListModel< G > model
The DefaultListModel to update.
int addInvObjects(@NotNull final G node, @Nullable final G gameObject)
Add inventory objects to an arch in the SelectedSquareView recursively.
int update(@Nullable final GameObjectContainer< G, A, R > mapSquare, @Nullable final G gameObject)
Updates the model to reflect a net.sf.gridarta.model.mapmodel.MapSquare.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
void addElement(final G gameObject)
Adds one GameObject to model.
Container for settings that affect the rendering of maps.
GameObjects are the objects based on Archetypes found on maps.
Updates a DefaultListModel instance to reflect the contents of a net.sf.gridarta.model.mapmodel.MapSquare instance.
final MapViewSettings mapViewSettings
The MapViewSettings to use.
boolean isEditTypeSet()
Returns whether a editType value is set so that not all squares are displayed.
Interface for MapArchObjects.