Crossfire JXClient, Trunk  R20561
DefaultFacesManager.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.faces;
23 
25 import java.io.IOException;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
39 
43  @NotNull
44  private final FaceQueue faceQueue;
45 
49  @NotNull
51 
55  @NotNull
56  private final FaceImages emptyFaceImages;
57 
61  @NotNull
62  @SuppressWarnings("FieldCanBeLocal")
64 
65  @Override
66  public void faceLoaded(@NotNull final Face face, @NotNull final FaceImages faceImages) {
67  face.setFaceImages(faceImages);
68  fireFaceUpdated(face);
69  }
70 
71  @Override
72  public void faceFailed(@NotNull final Face face) {
73  face.setFaceImages(unknownFaceImages);
74  fireFaceUpdated(face);
75  }
76 
77  };
78 
85  public DefaultFacesManager(@NotNull final FaceCache faceCache, @NotNull final FaceQueue faceQueue) throws IOException {
86  super(faceCache);
87  this.faceQueue = faceQueue;
89 
90  emptyFaceImages = FaceImagesUtils.newEmptyFaceImages();
92  }
93 
101  @NotNull
102  @Override
103  protected FaceImages getFaceImages(final int faceNum, @Nullable final boolean[] isUnknownImage) {
104  if (faceNum == 0) {
105  if (isUnknownImage != null) {
106  isUnknownImage[0] = false;
107  }
108  return emptyFaceImages;
109  }
110 
111  final Face face = lookupFace(faceNum);
112  final FaceImages faceImages = face.getFaceImages();
113  if (faceImages != null) {
114  if (isUnknownImage != null) {
115  isUnknownImage[0] = false;
116  }
117  return faceImages;
118  }
119 
120  faceQueue.loadFace(face);
121  if (isUnknownImage != null) {
122  isUnknownImage[0] = true;
123  }
124  return unknownFaceImages;
125  }
126 
130  @Override
131  public void reset() {
132  super.reset();
133  faceQueue.reset();
134  }
135 
136 }
static FaceImages newFaceImages(@NotNull final ImageIcon originalImageIcon)
Creates a new FaceImages instance from an "original" face; the "scaled" and "magic map" sized images ...
final FaceImages emptyFaceImages
The empty face; returned for face ID 0.
FaceImages getFaceImages()
Returns the images.
Definition: Face.java:115
FaceImages getFaceImages(final int faceNum, @Nullable final boolean[] isUnknownImage)
Returns the FaceImages information for a face ID.
static final String UNKNOWN_PNG
The resource name of the "unknown" face.
Utility class for creating FaceImages instances.
Interface for classes implementing a means to load Faces.
Definition: FaceQueue.java:30
final FaceCache faceCache
The FaceCache instance used to look up in-memory faces.
void loadFace(@NotNull Face face)
Request a face.
void addFaceQueueListener(@NotNull FaceQueueListener faceQueueListener)
Adds a FaceQueueListener to be notified about processed faces.
Consists of three ImageIcons representing a Face.
Definition: FaceImages.java:31
final FaceQueueListener faceQueueListener
The FaceQueueListener registered to faceQueue.
static ImageIcon loadImage(@NotNull final String name)
Loads an image file.
void reset()
Reset the processing: forget about pending faces.
static FaceImages newEmptyFaceImages()
Creates a new FaceImages instance consisting of empty images.
Utility class for loading information from resources.
Interface for listeners interested in FaceQueue events.
Face lookupFace(final int faceNum)
Returns the Face instance for a given face ID.
DefaultFacesManager(@NotNull final FaceCache faceCache, @NotNull final FaceQueue faceQueue)
Creates a new instance.
final FaceQueue faceQueue
The FaceQueue instance used to load faces not present in-memory.
void fireFaceUpdated(@NotNull final Face face)
Notifies all FacesManagerListeners that a face has been updated.
Abstract base class for FacesManager implementations.