22 package com.realtime.crossfire.jxclient.faces;
24 import java.nio.ByteBuffer;
25 import java.util.HashMap;
26 import java.util.LinkedList;
27 import java.util.List;
29 import javax.swing.ImageIcon;
30 import org.jetbrains.annotations.NotNull;
50 private final Object
sync =
new Object();
93 pendingAskfaces.clear();
95 pendingFacesQueue.clear();
104 final int faceNum = face.getFaceNum();
105 if (faceNum <= 0 || faceNum > 65535) {
110 final Integer faceObject = faceNum;
111 synchronized (
sync) {
112 if (pendingFaces.put(faceObject, face) != null) {
114 pendingFacesQueue.remove(face);
115 pendingFacesQueue.add(0, face);
118 pendingFacesQueue.add(0, face);
128 for (
final Face face : pendingFacesQueue) {
133 final int faceNum = face.getFaceNum();
134 if (pendingAskfaces.put(faceNum, face) == null) {
147 public void faceReceived(
final int faceNum,
final int faceSetNum, @NotNull
final ByteBuffer packet) {
148 final Integer faceObject = faceNum;
149 synchronized (
sync) {
150 final Face face = pendingAskfaces.remove(faceObject);
152 System.err.println(
"received unexpected image for face "+faceNum);
154 if (pendingFaces.remove(faceObject) != face) {
157 if (!pendingFacesQueue.remove(face)) {
161 final byte[] data =
new byte[packet.remaining()];
175 final ImageIcon originalImageIcon;
177 originalImageIcon =
new ImageIcon(data);
178 }
catch (
final IllegalArgumentException ex) {
179 System.err.println(
"Invalid .png data for face "+face+
": "+ex.getMessage());
183 if (originalImageIcon.getIconWidth() <= 0 || originalImageIcon.getIconHeight() <= 0) {
static FaceImages newFaceImages(@NotNull final ImageIcon originalImageIcon)
Creates a new FaceImages instance from an "original" face; the "scaled" and "magic map" sized images ...
final Map< Integer, Face > pendingFaces
Face numbers for which an "askface" command should be sent.
Utility class for creating FaceImages instances.
void faceReceived(final int faceNum, final int faceSetNum, @NotNull final ByteBuffer packet)
Notifies the askface manager that image information have been received from the server.
final Map< Integer, Face > pendingAskfaces
Face numbers for which "askface" commands have been sent without having received a response from the ...
Interface for classes that allow sending "askface" commands.
void fireFaceLoaded(@NotNull final Face face, @NotNull final FaceImages faceImages)
Notify all listener with FaceImages).
Abstract base class for classes implementing FaceQueue.
final Object sync
The object use for synchronization.
void fireFaceFailed(@NotNull final Face face)
Notify all listener with FaceQueueListener#faceFailed(Face).
void sendAskface(int faceNum)
Sends an "askface" command.
void sendAskface()
Sends some pending "askface" commands.
void reset()
Reset the processing: forget about pending faces.This function is called whenever the server socket b...
A FaceQueue requesting faces by "askface" commands sent to the Crossfire server.
final AskfaceQueue askfaceQueue
The connection to use.
static final int CONCURRENT_ASKFACE_COMMANDS
The maximum number of concurrently sent "askface" commands.
AskfaceFaceQueue(@NotNull final AskfaceQueue askfaceQueue)
Creates a new instance.
void loadFace(@NotNull final Face face)
Request a face.Must eventually call either FaceQueueListener#faceLoaded(Face, FaceImages) or FaceQueu...
final List< Face > pendingFacesQueue
The same elements as pendingFaces in query order.
void processFaceData(@NotNull final Face face, @NotNull final byte[] data)
Processes face information received from the server.