Crossfire JXClient, Trunk
AccountCreateCommand.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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.commands;
24 
33 import org.jetbrains.annotations.NotNull;
34 
39 public class AccountCreateCommand implements GUICommand {
40 
44  @NotNull
46 
50  @NotNull
51  private final AbstractGUIElement element;
52 
56  @NotNull
57  private final GuiFactory guiFactory;
58 
65  public AccountCreateCommand(@NotNull final CommandCallback commandCallback, @NotNull final AbstractGUIElement button, @NotNull final GuiFactory guiFactory) {
66  this.commandCallback = commandCallback;
67  element = button;
68  this.guiFactory = guiFactory;
69  }
70 
71  @Override
72  public boolean canExecute() {
73  return true;
74  }
75 
76  @Override
77  public void execute() {
78  final Gui gui = guiFactory.getGui(element);
79  if (gui == null) {
80  return;
81  }
82 
83  final GUIText loginField = gui.getFirstElement(GUIText.class, "account_login");
84  final GUIText passwordField = gui.getFirstElement(GUIText.class, "account_password");
85  final GUIText confirmField = gui.getFirstElement(GUIText.class, "account_password_confirm");
86 
87  if (loginField == null || passwordField == null || confirmField == null) {
88  return;
89  }
90 
91  final String login = loginField.getText();
92  final String password = passwordField.getText();
93  final String confirm = confirmField.getText();
94 
95  if (login.isEmpty()) {
96  final AbstractLabel error = gui.getFirstElement(GUILabelFailure.class, "account_create_error");
97  if (error != null) {
98  error.setText("Can't have an empty login!");
99  }
100  loginField.setActive(true);
101  return;
102  }
103 
104  if (password.isEmpty()) {
105  final AbstractLabel error = gui.getFirstElement(GUILabelFailure.class, "account_create_error");
106  if (error != null) {
107  error.setText("Can't have an empty password!");
108  }
109  confirmField.setText("");
110  passwordField.setActive(true);
111  return;
112  }
113  if (confirm.isEmpty()) {
114  confirmField.setActive(true);
115  return;
116  }
117  if (!confirm.equals(password)) {
118  final AbstractLabel error = gui.getFirstElement(GUILabelFailure.class, "account_create_error");
119  if (error != null) {
120  error.setText("Passwords don't match!");
121  }
122  passwordField.setText("");
123  confirmField.setText("");
124  passwordField.setActive(true);
125  return;
126  }
127 
128  commandCallback.accountCreate(login, password);
129  }
130 
131 }
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCommand.execute
void execute()
Definition: AccountCreateCommand.java:77
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.label.AbstractLabel
Definition: AbstractLabel.java:43
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCommand.AccountCreateCommand
AccountCreateCommand(@NotNull final CommandCallback commandCallback, @NotNull final AbstractGUIElement button, @NotNull final GuiFactory guiFactory)
Definition: AccountCreateCommand.java:65
com.realtime.crossfire.jxclient.gui.gui.Gui
Definition: Gui.java:49
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCommand.commandCallback
final CommandCallback commandCallback
Definition: AccountCreateCommand.java:45
com.realtime.crossfire.jxclient.gui.label
Definition: AbstractLabel.java:23
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.textinput
Definition: ActivateCommandInputCommand.java:23
com.realtime.crossfire.jxclient.gui.commandlist
Definition: CommandList.java:23
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback
Definition: CommandCallback.java:33
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback.accountCreate
void accountCreate(@NotNull String login, @NotNull String password)
com.realtime.crossfire.jxclient.skin.skin.GuiFactory.getGui
Gui getGui(@NotNull final AbstractGUIElement element)
Definition: GuiFactory.java:110
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCommand.canExecute
boolean canExecute()
Definition: AccountCreateCommand.java:72
com.realtime.crossfire.jxclient.gui.textinput.GUIText.getText
String getText()
Definition: GUIText.java:234
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCommand.guiFactory
final GuiFactory guiFactory
Definition: AccountCreateCommand.java:57
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.gui.Gui.getFirstElement
public< T extends GUIElement > T getFirstElement(@NotNull final Class< T > class_)
Definition: Gui.java:300
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCommand
Definition: AccountCreateCommand.java:39
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.gui.label.AbstractLabel.setText
void setText(@NotNull final String text)
Definition: AbstractLabel.java:120
com.realtime.crossfire
com.realtime.crossfire.jxclient.gui.commands.AccountCreateCommand.element
final AbstractGUIElement element
Definition: AccountCreateCommand.java:51
com.realtime.crossfire.jxclient.gui.textinput.GUIText
Definition: GUIText.java:61
com.realtime
com.realtime.crossfire.jxclient.gui.textinput.GUIText.setText
void setText(@NotNull final String text)
Definition: GUIText.java:223
com
com.realtime.crossfire.jxclient.gui.gui.ActivatableGUIElement.setActive
void setActive(final boolean active)
Definition: ActivatableGUIElement.java:115
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.gui.label.GUILabelFailure
Definition: GUILabelFailure.java:39
com.realtime.crossfire.jxclient.gui.commandlist.GUICommand
Definition: GUICommand.java:29