Crossfire JXClient, Trunk  R20561
AbstractFacesManager.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 javax.swing.ImageIcon;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
33 public abstract class AbstractFacesManager implements FacesManager {
34 
39  @NotNull
41 
45  @NotNull
46  private final FaceCache faceCache;
47 
52  protected AbstractFacesManager(@NotNull final FaceCache faceCache) {
53  this.faceCache = faceCache;
54  }
55 
59  @Override
60  public void addFacesManagerListener(@NotNull final FacesManagerListener facesManagerListener) {
61  facesManagerListeners.add(facesManagerListener);
62  }
63 
67  @Override
68  public void removeFacesManagerListener(@NotNull final FacesManagerListener facesManagerListener) {
69  facesManagerListeners.remove(facesManagerListener);
70  }
71 
77  protected void fireFaceUpdated(@NotNull final Face face) {
78  for (final FacesManagerListener facesManagerListener : facesManagerListeners) {
79  facesManagerListener.faceUpdated(face);
80  }
81  }
82 
86  @NotNull
87  @Override
88  public ImageIcon getOriginalImageIcon(final int faceNum, @Nullable final boolean[] isUnknownImage) {
89  return getFaceImages(faceNum, isUnknownImage).getOriginalImageIcon();
90  }
91 
95  @NotNull
96  @Override
97  public ImageIcon getScaledImageIcon(final int faceNum, @Nullable final boolean[] isUnknownImage) {
98  return getFaceImages(faceNum, isUnknownImage).getScaledImageIcon();
99  }
100 
104  @NotNull
105  @Override
106  public ImageIcon getMagicMapImageIcon(final int faceNum, @Nullable final boolean[] isUnknownImage) {
107  return getFaceImages(faceNum, isUnknownImage).getMagicMapImageIcon();
108  }
109 
113  @NotNull
114  @Override
115  public Face getFace(final int faceNum) {
116  getFaceImages(faceNum, null);
117  return faceCache.getFace(faceNum);
118  }
119 
129  @NotNull
130  protected abstract FaceImages getFaceImages(final int faceNum, @Nullable boolean[] isUnknownImage);
131 
139  @NotNull
140  protected Face lookupFace(final int faceNum) {
141  return faceCache.getFace(faceNum);
142  }
143 
147  @Nullable
148  @Override
149  public Face getFace2(final int faceNum) {
150  if (faceNum == 0) {
151  return null;
152  }
153 
154  getFaceImages(faceNum, null);
155  return faceCache.getFace(faceNum);
156  }
157 
161  @Override
162  public void reset() {
163  faceCache.reset();
164  }
165 
166 }
ImageIcon getScaledImageIcon()
Returns the ImageIcon scaled for the map view.
Definition: FaceImages.java:77
final EventListenerList2< FacesManagerListener > facesManagerListeners
The FacesManagerListeners to notify about changed faces.
final FaceCache faceCache
The FaceCache instance used to look up in-memory faces.
ImageIcon getScaledImageIcon(final int faceNum, @Nullable final boolean[] isUnknownImage)
Returns the "scaled" face for a face ID.This function returns immediately even if the face is not loa...
Consists of three ImageIcons representing a Face.
Definition: FaceImages.java:31
ImageIcon getMagicMapImageIcon()
Returns the ImageIcon scaled for the magic map view.
Definition: FaceImages.java:86
void addFacesManagerListener(@NotNull final FacesManagerListener facesManagerListener)
Adds a FacesManagerListener to be notified about updated faces.the listener
Interface for listeners interested in FacesManager events.
Face getFace(final int faceNum)
Returns a face by face id.
Definition: FaceCache.java:60
void add(@NotNull final T listener)
Adds a listener.
void removeFacesManagerListener(@NotNull final FacesManagerListener facesManagerListener)
Removes a FacesManagerListener to be notified about updated faces.the listener
AbstractFacesManager(@NotNull final FaceCache faceCache)
Creates a new instance.
ImageIcon getOriginalImageIcon(final int faceNum, @Nullable final boolean[] isUnknownImage)
Returns the "original" face for a face ID.This function returns immediately even if the face is not l...
Face lookupFace(final int faceNum)
Returns the Face instance for a given face ID.
abstract FaceImages getFaceImages(final int faceNum, @Nullable boolean[] isUnknownImage)
Returns the FaceImages information for a face ID.
void reset()
Forgets about all face information.
Definition: FaceCache.java:75
Face getFace2(final int faceNum)
Returns the Face instance for a given face ID.Requests the face from the server if necessary...
Face getFace(final int faceNum)
Returns the Face instance for a given face ID.Requests the face face from the server if necessary...
ImageIcon getMagicMapImageIcon(final int faceNum, @Nullable final boolean[] isUnknownImage)
Returns the "magic map" face for a face ID.This function returns immediately even if the face is not ...
void fireFaceUpdated(@NotNull final Face face)
Notifies all FacesManagerListeners that a face has been updated.
Abstract base class for FacesManager implementations.
void remove(@NotNull final T listener)
Removes a listener.
ImageIcon getOriginalImageIcon()
Returns the ImageIcon as sent by the Crossfire server.
Definition: FaceImages.java:68
Maintains a mapping of face numbers to face data.