Crossfire JXClient, Trunk
src
gui
src
main
java
com
realtime
crossfire
jxclient
commands
BindCommand.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.commands;
24
25
import
com
.
realtime
.
crossfire
.
jxclient
.
gui
.
commandlist
.
CommandList
;
26
import
com
.
realtime
.
crossfire
.
jxclient
.
gui
.
commandlist
.
CommandListType
;
27
import
com
.
realtime
.
crossfire
.
jxclient
.
gui
.
commandlist
.
GUICommandFactory
;
28
import
com
.
realtime
.
crossfire
.
jxclient
.
gui
.
textinput
.
CommandCallback
;
29
import
com
.
realtime
.
crossfire
.
jxclient
.
server
.
crossfire
.
CrossfireServerConnection
;
30
import
com
.
realtime
.
crossfire
.
jxclient
.
util
.
StringUtils
;
31
import
org.jetbrains.annotations.NotNull;
32
37
public
class
BindCommand
extends
AbstractCommand
{
38
42
@NotNull
43
private
final
CommandCallback
commandCallback
;
44
48
@NotNull
49
private
final
GUICommandFactory
guiCommandFactory
;
50
57
public
BindCommand
(@NotNull
final
CrossfireServerConnection
crossfireServerConnection
, @NotNull
final
CommandCallback
commandCallback
, @NotNull
final
GUICommandFactory
guiCommandFactory
) {
58
super(
"bind"
,
crossfireServerConnection
);
59
this.commandCallback =
commandCallback
;
60
this.guiCommandFactory =
guiCommandFactory
;
61
}
62
63
@Override
64
public
boolean
allArguments
() {
65
return
true
;
66
}
67
68
@Override
69
public
void
execute
(@NotNull
final
String args) {
70
final
String commandList;
71
final
boolean
perCharacterBinding;
72
if
(args.equals(
"-c"
)) {
73
perCharacterBinding =
true
;
74
commandList =
""
;
75
}
else
if
(args.startsWith(
"-c "
)) {
76
perCharacterBinding =
true
;
77
commandList =
StringUtils
.
trimLeading
(args.substring(3));
78
}
else
{
79
perCharacterBinding =
false
;
80
commandList = args;
81
}
82
83
if
(commandList.isEmpty()) {
84
drawInfoError
(
"Which command do you want to bind?"
);
85
return
;
86
}
87
88
final
CommandList
commandList2 =
new
CommandList
(
CommandListType
.
AND
);
89
commandList2.
add
(
guiCommandFactory
.
createCommand
(commandList));
90
if
(!
commandCallback
.
createKeyBinding
(perCharacterBinding, commandList2)) {
91
drawInfoError
(
"Cannot use bind -c since no character is logged in."
);
92
//noinspection UnnecessaryReturnStatement
93
return
;
94
}
95
}
96
97
@NotNull
98
@Override
99
public
String
getHelp
() {
100
//noinspection StringBufferReplaceableByString
101
final
StringBuilder sb =
new
StringBuilder();
102
sb.append(
"Binds a command to a key\n"
);
103
sb.append(
"\n"
);
104
sb.append(
"Usage: bind <command>\n"
);
105
sb.append(
"Usage: bind -c <command>\n"
);
106
sb.append(
"\n"
);
107
sb.append(
"Asks the user for a key, then associates the given <command> with that key.\n"
);
108
sb.append(
"If the option -c is used, the command is associated only with the current character. "
);
109
sb.append(
"Otherwise the command is associated with all characters on all Crossfire servers.\n"
);
110
sb.append(
"The ESC key cannot be bound. Its fixed function is to cancel an action.\n"
);
111
sb.append(
"Note: Unbind a key: unbind\n"
);
112
return
sb.toString();
113
}
114
115
}
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.gui.commandlist.CommandList
Definition:
CommandList.java:34
com.realtime.crossfire.jxclient.util.StringUtils.trimLeading
static String trimLeading(@NotNull final CharSequence str)
Definition:
StringUtils.java:54
com.realtime.crossfire.jxclient.gui.commandlist.CommandListType.AND
AND
Definition:
CommandListType.java:34
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback.createKeyBinding
boolean createKeyBinding(boolean perCharacter, @NotNull CommandList commandList)
com.realtime.crossfire.jxclient.gui.textinput
Definition:
ActivateCommandInputCommand.java:23
com.realtime.crossfire.jxclient.gui.commandlist
Definition:
CommandList.java:23
com.realtime.crossfire.jxclient.commands.BindCommand.getHelp
String getHelp()
Definition:
BindCommand.java:99
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback
Definition:
CommandCallback.java:33
com.realtime.crossfire.jxclient.commands.AbstractCommand.crossfireServerConnection
final CrossfireServerConnection crossfireServerConnection
Definition:
AbstractCommand.java:45
com.realtime.crossfire.jxclient.commands.BindCommand.guiCommandFactory
final GUICommandFactory guiCommandFactory
Definition:
BindCommand.java:49
com.realtime.crossfire.jxclient.commands.BindCommand.allArguments
boolean allArguments()
Definition:
BindCommand.java:64
com.realtime.crossfire.jxclient.commands.AbstractCommand.drawInfoError
void drawInfoError(@NotNull final String message)
Definition:
AbstractCommand.java:69
com.realtime.crossfire.jxclient.gui.commandlist.GUICommandFactory.createCommand
GUICommand createCommand(@NotNull final String commandString)
com.realtime.crossfire.jxclient.commands.BindCommand
Definition:
BindCommand.java:37
com.realtime.crossfire.jxclient.gui.commandlist.GUICommandFactory
Definition:
GUICommandFactory.java:32
com.realtime.crossfire.jxclient.commands.BindCommand.execute
void execute(@NotNull final String args)
Definition:
BindCommand.java:69
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition:
CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.util.StringUtils
Definition:
StringUtils.java:34
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.util
Definition:
Codec.java:23
com.realtime.crossfire.jxclient.server.crossfire
Definition:
AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.gui.commandlist.CommandList.add
void add(@NotNull final GUICommand guiCommand)
Definition:
CommandList.java:60
com.realtime.crossfire.jxclient.commands.BindCommand.BindCommand
BindCommand(@NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final CommandCallback commandCallback, @NotNull final GUICommandFactory guiCommandFactory)
Definition:
BindCommand.java:57
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.commands.BindCommand.commandCallback
final CommandCallback commandCallback
Definition:
BindCommand.java:43
com.realtime.crossfire.jxclient.gui.commandlist.CommandListType
Definition:
CommandListType.java:29
com.realtime.crossfire.jxclient.commands.AbstractCommand
Definition:
AbstractCommand.java:33
Generated by
1.8.17