Crossfire JXClient, Trunk  R20561
AccountCreateCharacterCommand.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 
28 import java.awt.Component;
29 import org.jetbrains.annotations.NotNull;
30 
35 public class AccountCreateCharacterCommand implements GUICommand {
36 
40  @NotNull
42 
46  @NotNull
47  private final Component element;
48 
55  public AccountCreateCharacterCommand(@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 GUIText loginField = gui.getFirstElement(GUIText.class, "character_login");
79 
80  if (loginField == null) {
81  return;
82  }
83 
84  final String login = loginField.getText();
85  if (login.isEmpty()) {
86  loginField.setActive(true);
87  return;
88  }
89 
90  commandCallback.accountCreateCharacter(login);
91  }
92 
93 }
boolean canExecute()
Returns whether this command may be executed.whether this command may be executed ...
static Gui getGui(@NotNull final Component element)
Returns the Gui an element is part of.
Definition: GuiUtils.java:91
Combines a list of GUIElements to for a gui.
Definition: Gui.java:43
AccountCreateCharacterCommand(@NotNull final CommandCallback commandCallback, @NotNull final Component button)
Creates a new instance.
void setActive(final boolean active)
Sets the active state of a GUI element.
String getText()
Returns the entered text.
Definition: GUIText.java:216
final Component element
The Component to find the Gui containing the fields.
Utility class for Gui related functions.
Definition: GuiUtils.java:35
void accountCreateCharacter(@NotNull String login)
Creates a character.
Interface that defines callback functions needed by commands.
void execute()
Executes the command.Does nothing if called while canExecute() returnsfalse .
Abstract base class for text input fields.
Definition: GUIText.java:57