22 package com.realtime.crossfire.jxclient.shortcuts;
29 import java.util.ArrayList;
30 import java.util.Iterator;
31 import java.util.List;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
39 public class Shortcuts implements Iterable<Shortcut> {
46 private final List<Shortcut>
shortcuts =
new ArrayList<>();
92 if (shortcuts.isEmpty()) {
96 for (
int i = 0; i < shortcuts.size(); i++) {
97 final Shortcut shortcut = shortcuts.get(i);
98 if (shortcut != null) {
100 listener.shortcutRemoved(i, shortcut);
117 return shortcuts.get(index);
118 }
catch (
final IndexOutOfBoundsException ignored) {
129 while (shortcuts.size() <= index) {
133 final Shortcut oldShortcut = shortcuts.get(index);
134 if (oldShortcut != null) {
136 listener.shortcutRemoved(index, oldShortcut);
140 shortcuts.set(index, shortcut);
142 if (shortcut != null) {
144 listener.shortcutAdded(index, shortcut);
164 public void setSpellShortcut(
final int index, @NotNull
final String spellName,
final boolean cast) {
188 if (command.length() <= 0) {
189 System.err.println(
"shortcut: ignoring empty command");
193 if (command.contains(
"\n")) {
194 System.err.println(
"shortcut: ignoring multi-line command");
208 if (shortcut != null) {
218 listeners.
add(listener);
226 listeners.
remove(listener);
258 public void setFile(@Nullable
final File file) {
267 return shortcuts.iterator();
void setShortcut(final int index, @Nullable final Shortcut shortcut)
Sets a Shortcut.
final EventListenerList2< ShortcutsListener > listeners
The listeners to be notified.
void setCast(final boolean cast)
Sets whether the spell should be "cast" or "invoked".
Shortcuts(@NotNull final CommandQueue commandQueue, @NotNull final SpellsManager spellsManager)
Creates a new instance.
A list of event listeners.
void resetModified()
Resets the modified state.
void setSpellShortcut(final int index, @NotNull final Spell spell, final boolean cast)
Sets a Shortcut to a spell.
final List< Shortcut > shortcuts
The shortcuts.
File file
The backing file.
abstract void execute()
Executes the shortcut.
boolean isModified()
Returns whether the shortcuts have been modified since creation or last call to resetModified().
Manages all known spells.
File getFile()
Returns the backing file.
void clearShortcuts()
Clears all defined shortcuts.
void setSpellShortcut(final int index, @NotNull final String spellName, final boolean cast)
Sets a Shortcut to a spell.
void setCommandShortcut(final int index, @NotNull final String command)
Sets a Shortcut to a command.
boolean modified
Whether the contents of shortcuts have been modified from the last saved state.
void unsetShortcut(final int index)
Unsets a Shortcut.
Describes a Crossfire spell.
Shortcut getShortcut(final int index)
Returns a shortcut.
void add(@NotNull final T listener)
Adds a listener.
Interface for listeners for Shortcut changes.
final SpellsManager spellsManager
The SpellsManager instance to watch.
final CommandQueue commandQueue
The command queue for executing commands.
Abstract base class for shortcut commands.
void setFile(@Nullable final File file)
Sets the backing file.
Iterator< Shortcut > iterator()
A Shortcut that casts a spell.
A Shortcut that executes a Crossfire command.
Maintains the pending (ncom) commands sent to the server.
void addShortcutsListener(@NotNull final ShortcutsListener listener)
Adds a ShortcutsListener.
void remove(@NotNull final T listener)
Removes a listener.
Manages a list of Shortcuts.
void removeShortcutsListener(@NotNull final ShortcutsListener listener)
Removes a ShortcutsListener.
abstract void dispose()
Releases all allocated resources.
Spell getSpell(@NotNull final String spellName)
Returns a Spell instance by spell name.
void executeShortcut(final int index)
Executes a shortcut.