Crossfire JXClient, Trunk  R20561
AccountLoginCommand.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 AccountLoginCommand implements GUICommand {
36 
40  @NotNull
42 
46  @NotNull
47  private final Component element;
48 
54  public AccountLoginCommand(@NotNull final CommandCallback commandCallback, @NotNull final Component button) {
55  this.commandCallback = commandCallback;
56  element = button;
57  }
58 
62  @Override
63  public boolean canExecute() {
64  return true;
65  }
66 
70  @Override
71  public void execute() {
72  final Gui gui = GuiUtils.getGui(element);
73  if (gui == null) {
74  return;
75  }
76 
77  final GUIText loginField = gui.getFirstElement(GUIText.class, "account_login");
78  final GUIText passwordField = gui.getFirstElement(GUIText.class, "account_password");
79 
80  if (loginField == null || passwordField == null) {
81  return;
82  }
83 
84  final String login = loginField.getText();
85  final String password = passwordField.getText();
86 
87  commandCallback.accountLogin(login, password);
88  }
89 
90 }
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
A GUICommand sending an account login request to the server.
void execute()
Executes the command.Does nothing if called while canExecute() returnsfalse .
String getText()
Returns the entered text.
Definition: GUIText.java:216
final Component element
The Component to find information for account creation.
AccountLoginCommand(@NotNull final CommandCallback commandCallback, @NotNull final Component button)
Creates a new instance.
Utility class for Gui related functions.
Definition: GuiUtils.java:35
void accountLogin(@NotNull String login, @NotNull String password)
Login to an account.
Interface that defines callback functions needed by commands.
final CommandCallback commandCallback
The CommandCallback to use.
Abstract base class for text input fields.
Definition: GUIText.java:57
boolean canExecute()
Returns whether this command may be executed.whether this command may be executed ...