You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SetNickColour.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser.commands.channel;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.ChannelClientProperty;
  25. import com.dmdirc.FrameContainer;
  26. import com.dmdirc.Server;
  27. import com.dmdirc.commandparser.CommandArguments;
  28. import com.dmdirc.commandparser.CommandManager;
  29. import com.dmdirc.commandparser.commands.ChannelCommand;
  30. import com.dmdirc.commandparser.commands.IntelligentCommand;
  31. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  32. import com.dmdirc.ui.input.AdditionalTabTargets;
  33. import com.dmdirc.ui.input.TabCompletionType;
  34. import com.dmdirc.ui.interfaces.ChannelWindow;
  35. import com.dmdirc.ui.messages.ColourManager;
  36. import java.awt.Color;
  37. /**
  38. * Allows the user to set a nickname on the channel to use a custom colour.
  39. * @author chris
  40. */
  41. public final class SetNickColour extends ChannelCommand implements IntelligentCommand {
  42. /** Creates a new instance of SetNickColour. */
  43. public SetNickColour() {
  44. super();
  45. CommandManager.registerCommand(this);
  46. }
  47. /** {@inheritDoc} */
  48. @SuppressWarnings("unchecked") @Override
  49. public void execute(final FrameContainer<?> origin, final Server server,
  50. final Channel channel, final boolean isSilent, final CommandArguments args) {
  51. int offset = 0;
  52. boolean nicklist = true;
  53. boolean text = true;
  54. if (args.getArguments().length > offset && args.getArguments()[offset]
  55. .equalsIgnoreCase("--nicklist")) {
  56. text = false;
  57. offset++;
  58. } else if (args.getArguments().length > offset && args.getArguments()[offset]
  59. .equalsIgnoreCase("--text")) {
  60. nicklist = false;
  61. offset++;
  62. }
  63. if (args.getArguments().length <= offset) {
  64. showUsage(origin, isSilent, "setnickcolour", "[--nicklist|--text] <nick> [colour]");
  65. return;
  66. }
  67. final ChannelClientInfo target = channel.getChannelInfo()
  68. .getChannelClient(args.getArguments()[offset]);
  69. offset++;
  70. if (target == null) {
  71. sendLine(origin, isSilent, FORMAT_ERROR, "No such nickname ("
  72. + args.getArguments()[offset - 1] + ")!");
  73. } else if (args.getArguments().length <= offset) {
  74. // We're removing the colour
  75. if (nicklist) {
  76. target.getMap().remove(ChannelClientProperty.NICKLIST_FOREGROUND);
  77. }
  78. if (text) {
  79. target.getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
  80. }
  81. ((ChannelWindow) channel.getFrame()).redrawNicklist();
  82. } else {
  83. // We're setting the colour
  84. final Color newColour = ColourManager.parseColour(args.getArguments()[offset], null);
  85. if (newColour == null) {
  86. sendLine(origin, isSilent, FORMAT_ERROR, "Invalid colour specified.");
  87. return;
  88. }
  89. if (nicklist) {
  90. target.getMap().put(ChannelClientProperty.NICKLIST_FOREGROUND, newColour);
  91. }
  92. if (text) {
  93. target.getMap().put(ChannelClientProperty.TEXT_FOREGROUND, newColour);
  94. }
  95. ((ChannelWindow) channel.getFrame()).updateNames();
  96. }
  97. }
  98. /** {@inheritDoc} */
  99. @Override
  100. public String getName() {
  101. return "setnickcolour";
  102. }
  103. /** {@inheritDoc} */
  104. @Override
  105. public boolean showInHelp() {
  106. return true;
  107. }
  108. /** {@inheritDoc} */
  109. @Override
  110. public String getHelp() {
  111. return "setnickcolour [--nicklist|--text] <nick> [colour] - "
  112. + "set the specified person's display colour";
  113. }
  114. /** {@inheritDoc} */
  115. @Override
  116. public AdditionalTabTargets getSuggestions(final int arg,
  117. final IntelligentCommandContext context) {
  118. final AdditionalTabTargets targets = new AdditionalTabTargets();
  119. targets.excludeAll();
  120. if (arg == 0) {
  121. targets.include(TabCompletionType.CHANNEL_NICK);
  122. targets.add("--nicklist");
  123. targets.add("--text");
  124. } else if (arg == 1 && (context.getPreviousArgs().get(0).equals("--text")
  125. || context.getPreviousArgs().get(0).equals("--nicklist"))) {
  126. targets.include(TabCompletionType.CHANNEL_NICK);
  127. }
  128. return targets;
  129. }
  130. }