 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
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) {
Abstract base class for ItemView implementing classes.
void addInventoryListener(final int tag, @NotNull final ItemListener listener)
Adds an ItemListener to be notified about changes.
Model class maintaining the CfItems known to the player.
void run()
Updates the inventory contents asynchronously.
Iterable< CfItem > getPlayerInventory()
Returns the player's inventory.
long changeTimestamp
The timestamp when the inventory contents may have changed.
Interface for listeners for changes of item locations.
final ItemSetListener itemSetListener
The ItemSetListener attached to itemSet to track the current player object.
final Comparator< CfItem > comparator
The Comparator for sorting.
final List< CfItem > items
The items in the inventory ordered by comparator.
int findInsertionIndex(@NotNull final CfItem item)
Returns the insertion index of a CfItem.
InventoryFilter filter
The current inventory filter.
A filter option for the inventory view.
Interface for listeners for attribute changes of CfItems.
void doRebuildInventory()
Rebuilds the inventory view.
final ItemListener playerInventoryListener
The ItemListener attached to the current player object.
int currentPlayerTag
The tag of the current player object or.
The representation of a Crossfire Item, client-side.
Provides a view of all items in the current player's inventory.
int getTag()
Returns the tag.
final Object sync
The synchronization object for accesses to changeTimestamp.
void addItemSetListener(@NotNull final ItemSetListener listener)
Adds an ItemSetListener to be notified about changes.
final CfItemListener itemModifiedListener
The CfItemListener attached to all items in items.
CfItem getPlayer()
Returns the player object this client controls.
int getSize()
Returns the number of items.
void addModifiedRange(final int firstIndex, final int lastIndex)
Marks a range of slots as modified.
void setFilter(@NotNull final InventoryFilter filter)
Sets the InventoryFilter.
void setCurrentPlayerTag(final int currentPlayerTag)
Updates the current player object.
Interface for listeners in ItemSet related events.
final ItemSet itemSet
The ItemSet to monitor.
void removeInventoryListener(final int tag, @NotNull final ItemListener listener)
Removes an ItemListener to be notified about changes.
CfItem getItem(final int index)
Returns the CfItem in a given slot.