Crossfire JXClient, Trunk  R20561
PlayerNameTracker.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.main;
23 
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
33 
39 public class PlayerNameTracker {
40 
44  @NotNull
45  private final JXCConnection connection;
46 
50  @NotNull
51  private final ItemSet itemSet;
52 
56  @NotNull
58 
59  @Override
60  public void itemAdded(@NotNull final CfItem item) {
61  // ignore
62  }
63 
64  @Override
65  public void itemMoved(@NotNull final CfItem item) {
66  // ignore
67  }
68 
69  @Override
70  public void itemChanged(@NotNull final CfItem item) {
71  // ignore
72  }
73 
74  @Override
75  public void itemRemoved(@NotNull final CfItem item) {
76  // ignore
77  }
78 
79  @Override
80  public void playerChanged(@Nullable final CfItem player) {
81  connection.setCharacter(player == null ? null : player.getName());
82  }
83 
84  @Override
85  public void openContainerChanged(final int tag) {
86  // ignore
87  }
88 
89  };
90 
95  @NotNull
96  @SuppressWarnings("FieldCanBeLocal")
98 
99  @Override
100  public void start() {
101  itemSet.removeItemSetListener(itemSetListener);
102  }
103 
104  @Override
105  public void metaserver() {
106  itemSet.removeItemSetListener(itemSetListener);
107  }
108 
109  @Override
110  public void preConnecting(@NotNull final String serverInfo) {
111  connection.setHost(serverInfo);
112  }
113 
114  @Override
115  public void connecting(@NotNull final String serverInfo) {
116  itemSet.addItemSetListener(itemSetListener);
117  }
118 
119  @Override
120  public void connecting(@NotNull final ClientSocketState clientSocketState) {
121  // ignore
122  }
123 
124  @Override
125  public void connected() {
126  // ignore
127  }
128 
129  @Override
130  public void connectFailed(@NotNull final String reason) {
131  // ignore
132  }
133 
134  };
135 
142  public PlayerNameTracker(@NotNull final GuiStateManager guiStateManager, @NotNull final JXCConnection connection, @NotNull final ItemSet itemSet) {
143  this.connection = connection;
144  this.itemSet = itemSet;
145  guiStateManager.addGuiStateListener(guiStateListener);
146  }
147 
148 }
Interface for listeners interested gui state changes.
final JXCConnection connection
The JXCConnection to track.
void addItemSetListener(@NotNull final ItemSetListener listener)
Adds an ItemSetListener to be notified about changes.
Definition: ItemSet.java:93
void setCharacter(@Nullable final String character)
Updates the active character name.
void removeItemSetListener(@NotNull final ItemSetListener listener)
Removes an ItemSetListener to be notified about changes.
Definition: ItemSet.java:101
Tracks a GuiStateManager and updates a JXCConnection's character name.
Interface for listeners in ItemSet related events.
PlayerNameTracker(@NotNull final GuiStateManager guiStateManager, @NotNull final JXCConnection connection, @NotNull final ItemSet itemSet)
Creates a new instance.
final ItemSetListener itemSetListener
The listener to detect a changed player name.
void setHost(@Nullable final String serverInfo)
Updates information about the connected host.
Model class maintaining the CfItems known to the player.
Definition: ItemSet.java:43
The representation of a Crossfire Item, client-side.
Definition: CfItem.java:36
Connection progress states of the Crossfire server connection.
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.