Crossfire JXClient, Trunk
AccountPasswordCommand.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 AccountPasswordCommand implements GUICommand {
40 
44  @NotNull
46 
50  @NotNull
51  private final AbstractGUIElement element;
52 
56  @NotNull
57  private final GuiFactory guiFactory;
58 
66  public AccountPasswordCommand(@NotNull final CommandCallback commandCallback, @NotNull final AbstractGUIElement button, @NotNull final GuiFactory guiFactory) {
67  this.commandCallback = commandCallback;
68  element = button;
69  this.guiFactory = guiFactory;
70  }
71 
72  @Override
73  public boolean canExecute() {
74  return true;
75  }
76 
77  @Override
78  public void execute() {
79  final Gui gui = guiFactory.getGui(element);
80  if (gui == null) {
81  return;
82  }
83 
84  final GUIText currentPasswordField = gui.getFirstElement(GUIText.class, "account_password_current");
85  final GUIText newPasswordField = gui.getFirstElement(GUIText.class, "account_password_new");
86  final GUIText confirmPasswordField = gui.getFirstElement(GUIText.class, "account_password_confirm");
87 
88  if (currentPasswordField == null || newPasswordField == null || confirmPasswordField == null) {
89  return;
90  }
91 
92  final String currentPassword = currentPasswordField.getText();
93  final String newPassword = newPasswordField.getText();
94  final String confirmPassword = confirmPasswordField.getText();
95 
96  if (currentPassword.isEmpty()) {
97  final AbstractLabel error = gui.getFirstElement(GUILabelFailure.class, "account_password_error");
98  if (error != null) {
99  error.setText("Please enter your current password!");
100  }
101  return;
102  }
103 
104  if (newPassword.isEmpty()) {
105  final AbstractLabel error = gui.getFirstElement(GUILabelFailure.class, "account_password_error");
106  if (error != null) {
107  error.setText("Can't have an empty password!");
108  }
109  return;
110  }
111  if (!confirmPassword.equals(newPassword)) {
112  final AbstractLabel error = gui.getFirstElement(GUILabelFailure.class, "account_password_error");
113  if (error != null) {
114  error.setText("Passwords don't match!");
115  }
116  return;
117  }
118 
119  commandCallback.accountPassword(currentPassword, newPassword);
120  }
121 
122 }
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.gui.Gui
Definition: Gui.java:49
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.label
Definition: AbstractLabel.java:23
com.realtime.crossfire.jxclient.gui.commands.AccountPasswordCommand.AccountPasswordCommand
AccountPasswordCommand(@NotNull final CommandCallback commandCallback, @NotNull final AbstractGUIElement button, @NotNull final GuiFactory guiFactory)
Definition: AccountPasswordCommand.java:66
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.commands.AccountPasswordCommand.element
final AbstractGUIElement element
Definition: AccountPasswordCommand.java:51
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback
Definition: CommandCallback.java:33
com.realtime.crossfire.jxclient.skin.skin.GuiFactory.getGui
Gui getGui(@NotNull final AbstractGUIElement element)
Definition: GuiFactory.java:110
com.realtime.crossfire.jxclient.gui.textinput.GUIText.getText
String getText()
Definition: GUIText.java:234
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.gui.commands.AccountPasswordCommand.execute
void execute()
Definition: AccountPasswordCommand.java:78
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.textinput.CommandCallback.accountPassword
void accountPassword(@NotNull String currentPassword, @NotNull String newPassword)
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.textinput.GUIText
Definition: GUIText.java:61
com.realtime
com
com.realtime.crossfire.jxclient.gui.commands.AccountPasswordCommand.canExecute
boolean canExecute()
Definition: AccountPasswordCommand.java:73
com.realtime.crossfire.jxclient.gui.commands.AccountPasswordCommand.commandCallback
final CommandCallback commandCallback
Definition: AccountPasswordCommand.java:45
com.realtime.crossfire.jxclient.gui.gui.AbstractGUIElement
Definition: AbstractGUIElement.java:37
com.realtime.crossfire.jxclient.gui.commands.AccountPasswordCommand.guiFactory
final GuiFactory guiFactory
Definition: AccountPasswordCommand.java:57
com.realtime.crossfire.jxclient.gui.commands.AccountPasswordCommand
Definition: AccountPasswordCommand.java:39
com.realtime.crossfire.jxclient.gui.label.GUILabelFailure
Definition: GUILabelFailure.java:39
com.realtime.crossfire.jxclient.gui.commandlist.GUICommand
Definition: GUICommand.java:29