23 package com.realtime.crossfire.jxclient.items;
25 import java.util.ArrayList;
26 import java.util.Comparator;
27 import java.util.List;
28 import javax.swing.SwingUtilities;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
56 private final Object
sync =
new Object();
66 @SuppressWarnings(
"FieldAccessedSynchronizedAndUnsynchronized")
81 @SuppressWarnings("FieldCanBeLocal")
85 public void playerChanged(@Nullable
final CfItem player) {
90 public void openContainerChanged(
final int tag) {
103 public void itemChanged(
final int tag) {
105 throw new IllegalArgumentException(
"tag="+tag+
" but expecting currentPlayerTag="+
currentPlayerTag);
111 public void itemRemoved(
final int tag) {
116 public void inventoryAdded(
final int tag,
final int index, @NotNull
final CfItem item) {
118 throw new IllegalArgumentException(
"tag="+tag+
" but expecting currentPlayerTag="+
currentPlayerTag);
124 public void inventoryRemoved(
final int tag,
final int index) {
126 throw new IllegalArgumentException(
"tag="+tag+
" but expecting currentPlayerTag="+
currentPlayerTag);
143 @SuppressWarnings(
"FieldAccessedSynchronizedAndUnsynchronized")
154 final Thread thread =
new Thread(this::run,
"inventory view refresh");
155 thread.setDaemon(
true);
169 if (this.currentPlayerTag != -1) {
173 if (this.currentPlayerTag != -1) {
178 synchronized (
sync) {
189 while (!Thread.currentThread().isInterrupted()) {
190 final long milliseconds;
191 synchronized (
sync) {
199 if (milliseconds <= 0) {
204 if (milliseconds > 0) {
206 Thread.sleep(milliseconds);
210 SwingUtilities.invokeLater(this::doRebuildInventory);
212 }
catch (
final InterruptedException ignored) {
213 Thread.currentThread().interrupt();
223 synchronized (
items) {
224 oldSize =
items.size();
233 items.add(index, item);
238 newSize =
items.size();
245 synchronized (
items) {
254 synchronized (
items) {
255 return items.get(index);
257 }
catch (
final IndexOutOfBoundsException ignored) {
273 synchronized (
items) {
274 for (i = 0; i <
items.size(); i++) {
288 if (this.filter ==
filter) {