Crossfire JXClient, Trunk  R20561
AccountPlayCharacterCommand.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) 2010 Nicolas Weeger.
19  */
20 
21 package com.realtime.crossfire.jxclient.gui.commands;
22 
29 import java.awt.Component;
30 import org.jetbrains.annotations.NotNull;
31 
36 public class AccountPlayCharacterCommand implements GUICommand {
37 
41  @NotNull
43 
47  @NotNull
48  private final Component element;
49 
55  public AccountPlayCharacterCommand(@NotNull final CommandCallback commandCallback, @NotNull final Component button) {
56  this.commandCallback = commandCallback;
57  element = button;
58  }
59 
63  @Override
64  public boolean canExecute() {
65  return true;
66  }
67 
71  @Override
72  public void execute() {
73  final Gui gui = GuiUtils.getGui(element);
74  if (gui == null) {
75  return;
76  }
77 
78  final GUICharacterList charactersList = gui.getFirstElement(GUICharacterList.class, "characters");
79  if (charactersList == null) {
80  return;
81  }
82 
83  final CharacterInformation current = charactersList.getCurrentCharacter();
84  if (current == null) {
85  return;
86  }
87 
88  commandCallback.accountPlayCharacter(current.getName());
89  }
90 
91 }
static Gui getGui(@NotNull final Component element)
Returns the Gui an element is part of.
Definition: GuiUtils.java:91
CharacterInformation getCurrentCharacter()
Returns the currently selected character in the list.
Combines a list of GUIElements to for a gui.
Definition: Gui.java:43
void execute()
Executes the command.Does nothing if called while canExecute() returnsfalse .
void accountPlayCharacter(@NotNull String name)
Plays a character from the current account.
boolean canExecute()
Returns whether this command may be executed.whether this command may be executed ...
Utility class for Gui related functions.
Definition: GuiUtils.java:35
Interface that defines callback functions needed by commands.
A GUIList display characters of an account.
AccountPlayCharacterCommand(@NotNull final CommandCallback commandCallback, @NotNull final Component button)
Creates a new instance.
final Component element
The Component to find information for account creation.
A GUICommand sending a play character request to the server.