00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.shortcuts;
00023
00024 import com.realtime.crossfire.jxclient.faces.Face;
00025 import com.realtime.crossfire.jxclient.queue.CommandQueue;
00026 import com.realtime.crossfire.jxclient.spells.Spell;
00027 import com.realtime.crossfire.jxclient.spells.SpellListener;
00028 import org.jetbrains.annotations.NotNull;
00029
00034 public class ShortcutSpell extends Shortcut {
00035
00039 @NotNull
00040 private static final String CAST = "cast ";
00041
00045 @NotNull
00046 private static final String INVOKE = "invoke ";
00047
00051 @NotNull
00052 private final CommandQueue commandQueue;
00053
00057 @NotNull
00058 private final Spell spell;
00059
00063 @NotNull
00064 private String command = CAST;
00065
00069 @NotNull
00070 private final SpellListener spellListener = new SpellListener() {
00071
00072 @Override
00073 public void spellChanged() {
00074 fireModifiedEvent();
00075 }
00076
00077 };
00078
00084 public ShortcutSpell(@NotNull final CommandQueue commandQueue, @NotNull final Spell spell) {
00085 this.commandQueue = commandQueue;
00086 this.spell = spell;
00087 spell.addSpellListener(spellListener);
00088 }
00089
00094 @NotNull
00095 public Spell getSpell() {
00096 return spell;
00097 }
00098
00103 public boolean isCast() {
00104 return command == CAST;
00105 }
00106
00112 public void setCast(final boolean cast) {
00113 final String newCommand = cast ? CAST : INVOKE;
00114 if (command == newCommand) {
00115 return;
00116 }
00117
00118 command = newCommand;
00119 fireModifiedEvent();
00120 }
00121
00125 @Override
00126 public void dispose() {
00127 spell.removeSpellListener(spellListener);
00128 }
00129
00133 @Override
00134 public void execute() {
00135 if (!spell.isUnknown()) {
00136 commandQueue.sendNcom(false, command+spell.getTag());
00137 }
00138 }
00139
00143 @NotNull
00144 @Override
00145 public String getTooltipText() {
00146 return command+spell.getTooltipText();
00147 }
00148
00152 @Override
00153 public void visit(@NotNull final ShortcutVisitor visitor) {
00154 visitor.visit(this);
00155 }
00156
00160 @Override
00161 public boolean displaysFace(final Face face) {
00162 return face.getFaceNum() == spell.getFaceNum();
00163 }
00164
00165 }