File Source: SetNickColour.java

         /* 
    P/P   *  Method: com.dmdirc.commandparser.commands.channel.SetNickColour__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 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  
    23  package com.dmdirc.commandparser.commands.channel;
    24  
    25  import com.dmdirc.Channel;
    26  import com.dmdirc.ChannelClientProperty;
    27  import com.dmdirc.Server;
    28  import com.dmdirc.commandparser.CommandArguments;
    29  import com.dmdirc.commandparser.CommandManager;
    30  import com.dmdirc.commandparser.commands.ChannelCommand;
    31  import com.dmdirc.commandparser.commands.IntelligentCommand;
    32  import com.dmdirc.parser.irc.ChannelClientInfo;
    33  import com.dmdirc.ui.input.AdditionalTabTargets;
    34  import com.dmdirc.ui.input.TabCompletionType;
    35  import com.dmdirc.ui.interfaces.ChannelWindow;
    36  import com.dmdirc.ui.interfaces.InputWindow;
    37  import com.dmdirc.ui.messages.ColourManager;
    38  
    39  import java.awt.Color;
    40  import java.util.List;
    41  
    42  /**
    43   * Allows the user to set a nickname on the channel to use a custom colour.
    44   * @author chris
    45   */
    46  public final class SetNickColour extends ChannelCommand implements IntelligentCommand {
    47      
    48      /** Creates a new instance of SetNickColour. */
    49      public SetNickColour() {
                 /* 
    P/P           *  Method: void com.dmdirc.commandparser.commands.channel.SetNickColour()
                  * 
                  *  Preconditions:
                  *    init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
                  */
    50          super();
    51          
    52          CommandManager.registerCommand(this);
    53      }
    54      
    55      /** {@inheritDoc} */
    56      @SuppressWarnings("unchecked") @Override
    57      public void execute(final InputWindow origin, final Server server,
    58              final Channel channel, final boolean isSilent, final CommandArguments args) {
    59          
                 /* 
    P/P           *  Method: void execute(InputWindow, Server, Channel, bool, CommandArguments)
                  * 
                  *  Preconditions:
                  *    args != null
                  *    init'ed(args.words)
                  *    (soft) args.line != null
                  *    (soft) channel != null
                  *    (soft) init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
                  * 
                  *  Presumptions:
                  *    offset < getArguments(...).length@77
                  *    offset < getArguments(...).length@81
                  *    offset <= getArguments(...).length@93 - 2
                  *    com.dmdirc.Channel:getChannelInfo(...)@77 != null
                  *    com.dmdirc.Channel:getFrame(...)@107 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    args.words != null
                  *    init'ed(java.lang.String:split(...)._tainted)
                  *    java.lang.String:split(...)._tainted == 0
                  *    init'ed(java.lang.String:split(...).length)
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.parser.irc.ChannelInfo:getUser(...)@77: Inverse{null}, Addr_Set{null}
                  *    com.dmdirc.ui.messages.ColourManager:parseColour(...)@93: Inverse{null}, Addr_Set{null}
                  *    getArguments(...).length@64: {0}, {1..+Inf}
                  *    getArguments(...).length@67: {0}, {1..+Inf}
                  *    getArguments(...).length@72: {2..+Inf}, {0,1}
                  *    getArguments(...).length@82: {3..+Inf}, {0..2}
                  *    java.lang.String:equalsIgnoreCase(...)@64: {0}, {1}
                  *    java.lang.String:equalsIgnoreCase(...)@67: {0}, {1}
                  */
    60          int offset = 0;
    61          boolean nicklist = true;
    62          boolean text = true;
    63          
    64          if (args.getArguments().length > offset && args.getArguments()[offset].equalsIgnoreCase("--nicklist")) {
    65              text = false;
    66              offset++;
    67          } else if (args.getArguments().length > offset && args.getArguments()[offset].equalsIgnoreCase("--text")) {
    68              nicklist = false;
    69              offset++;
    70          }
    71          
    72          if (args.getArguments().length <= offset) {
    73              showUsage(origin, isSilent, "setnickcolour", "[--nicklist|--text] <nick> [colour]");
    74              return;
    75          }
    76          
    77          final ChannelClientInfo target = channel.getChannelInfo().getUser(args.getArguments()[offset]);
    78          offset++;
    79          
    80          if (target == null) {
    81              sendLine(origin, isSilent, FORMAT_ERROR, "No such nickname (" + args.getArguments()[offset - 1] + ")!");
    82          } else if (args.getArguments().length <= offset) {
    83              // We're removing the colour
    84              if (nicklist) {
    85                  target.getMap().remove(ChannelClientProperty.NICKLIST_FOREGROUND);
    86              }
    87              if (text) {
    88                  target.getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
    89              }
    90              ((ChannelWindow) channel.getFrame()).redrawNicklist();
    91          } else {
    92              // We're setting the colour
    93              final Color newColour = ColourManager.parseColour(args.getArguments()[offset], null);
    94              if (newColour == null) {
    95                  sendLine(origin, isSilent, FORMAT_ERROR, "Invalid colour specified.");
    96                  return;
    97              }
    98  
    99              if (nicklist) {
   100                  target.getMap().put(ChannelClientProperty.NICKLIST_FOREGROUND, newColour);
   101              }
   102  
   103              if (text) {
   104                  target.getMap().put(ChannelClientProperty.TEXT_FOREGROUND, newColour);
   105              }
   106  
   107              ((ChannelWindow) channel.getFrame()).updateNames();
   108          }
   109      }
   110      
   111      /** {@inheritDoc} */
   112      @Override
   113      public String getName() {
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"setnickcolour"
                  */
   114          return "setnickcolour";
   115      }
   116      
   117      /** {@inheritDoc} */
   118      @Override
   119      public boolean showInHelp() {
                 /* 
    P/P           *  Method: bool showInHelp()
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
   120          return true;
   121      }
   122      
   123      /** {@inheritDoc} */
   124      @Override
   125      public String getHelp() {
                 /* 
    P/P           *  Method: String getHelp()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"setnickcolour [--nicklist|--text] <nick> [colour] - set the specified person's display colour"
                  */
   126          return "setnickcolour [--nicklist|--text] <nick> [colour] - "
   127                  + "set the specified person's display colour";
   128      }
   129  
   130      /** {@inheritDoc} */
   131      @Override
   132      public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
                 /* 
    P/P           *  Method: AdditionalTabTargets getSuggestions(int, List)
                  * 
                  *  Preconditions:
                  *    (soft) previousArgs != null
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.ui.input.TabCompletionType.CHANNEL_NICK)
                  *    java.util.List:get(...)@140 != null
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new AdditionalTabTargets(getSuggestions#1)
                  *    new AdditionalTabTargets(getSuggestions#1) num objects == 1
                  * 
                  *  Test Vectors:
                  *    arg: {-231..-1, 2..232-1}, {0}, {1}
                  *    java.lang.String:equals(...)@140: {1}, {0}
                  *    java.lang.String:equals(...)@140: {0}, {1}
                  */
   133          final AdditionalTabTargets targets = new AdditionalTabTargets();
   134          targets.excludeAll();
   135          
   136          if (arg == 0) {
   137              targets.include(TabCompletionType.CHANNEL_NICK);
   138              targets.add("--nicklist");
   139              targets.add("--text");
   140          } else if (arg == 1 && (previousArgs.get(0).equals("--text")
   141                  || previousArgs.get(0).equals("--nicklist"))) {
   142              targets.include(TabCompletionType.CHANNEL_NICK);            
   143          }
   144          
   145          return targets;
   146      }
   147      
   148  }








SofCheck Inspector Build Version : 2.17854
SetNickColour.java 2009-Jun-25 01:54:24
SetNickColour.class 2009-Sep-02 17:04:16