File Source: NicklistRenderer.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.renderers.NicklistRenderer__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.addons.ui_swing.components.renderers;
    24  
    25  import com.dmdirc.ChannelClientProperty;
    26  import com.dmdirc.interfaces.ConfigChangeListener;
    27  import com.dmdirc.config.ConfigManager;
    28  import com.dmdirc.parser.irc.ChannelClientInfo;
    29  
    30  import java.awt.Color;
    31  import java.awt.Component;
    32  import java.util.Map;
    33  
    34  import javax.swing.BorderFactory;
    35  import javax.swing.DefaultListCellRenderer;
    36  import javax.swing.JList;
    37  
    38  /** Renders the nicklist. */
    39  public final class NicklistRenderer extends DefaultListCellRenderer implements
    40          ConfigChangeListener {
    41  
    42      /**
    43       * A version number for this class. It should be changed whenever the class
    44       * structure is changed (or anything else that would prevent serialized
    45       * objects being unserialized with the new class).
    46       */
    47      private static final long serialVersionUID = 5;
    48      /** Config manager. */
    49      private final ConfigManager config;
    50      /** Nicklist alternate background colour. */
    51      private Color altBackgroundColour;
    52      /** Show nick colours. */
    53      private boolean showColours;
    54      /** The list that we're using for the nicklist. */
    55      private final JList nicklist;
    56  
    57      /**
    58       * Creates a new instance of NicklistRenderer.
    59       *
    60       * @param config ConfigManager for the associated channel
    61       * @param nicklist The nicklist that we're rendering for.
    62       */
    63      public NicklistRenderer(final ConfigManager config, final JList nicklist) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.renderers.NicklistRenderer(ConfigManager, JList)
                  * 
                  *  Preconditions:
                  *    config != null
                  * 
                  *  Postconditions:
                  *    init'ed(this.altBackgroundColour)
                  *    this.config == config
                  *    this.config != null
                  *    this.nicklist == nicklist
                  *    init'ed(this.nicklist)
                  *    init'ed(this.showColours)
                  */
    64          super();
    65  
    66          this.config = config;
    67          this.nicklist = nicklist;
    68  
    69          config.addChangeListener("ui", "shownickcoloursinnicklist", this);
    70          config.addChangeListener("ui", "nicklistbackgroundcolour", this);
    71          config.addChangeListener("ui", "backgroundcolour", this);
    72          config.addChangeListener("ui", "nickListAltBackgroundColour", this);
    73          altBackgroundColour = config.getOptionColour(
    74                  "ui", "nickListAltBackgroundColour",
    75                  "ui", "nicklistbackgroundcolour",
    76                  "ui", "backgroundcolour");
    77          showColours = config.getOptionBool("ui", "shownickcoloursinnicklist");
    78      }
    79  
    80      /** {@inheritDoc} */
    81      @Override
    82      public Component getListCellRendererComponent(final JList list,
    83              final Object value, final int index, final boolean isSelected,
    84              final boolean cellHasFocus) {
    85  
                 /* 
    P/P           *  Method: Component getListCellRendererComponent(JList, Object, int, bool, bool)
                  * 
                  *  Preconditions:
                  *    init'ed(this.showColours)
                  *    value != null
                  *    (soft) init'ed(this.altBackgroundColour)
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.ChannelClientProperty.NICKLIST_BACKGROUND)
                  *    init'ed(com.dmdirc.ChannelClientProperty.NICKLIST_FOREGROUND)
                  * 
                  *  Postconditions:
                  *    return_value == this
                  *    return_value != null
                  * 
                  *  Test Vectors:
                  *    index mod 2: {0}, {1}
                  *    isSelected: {1}, {0}
                  *    this.showColours: {0}, {1}
                  *    com.dmdirc.parser.irc.ChannelClientInfo:getMap(...)@93: Addr_Set{null}, Inverse{null}
                  *    java.util.Map:containsKey(...)@100: {0}, {1}
                  *    java.util.Map:containsKey(...)@96: {0}, {1}
                  */
    86          super.getListCellRendererComponent(list, value, index, isSelected,
    87                  cellHasFocus);
    88  
    89          if (!isSelected && (index & 1) == 1) {
    90              setBackground(altBackgroundColour);
    91          }
    92  
    93          final Map map = ((ChannelClientInfo) value).getMap();
    94  
    95          if (showColours && map != null) {
    96              if (map.containsKey(ChannelClientProperty.NICKLIST_FOREGROUND)) {
    97                  setForeground((Color) map.get(ChannelClientProperty.NICKLIST_FOREGROUND));
    98              }
    99  
   100              if (map.containsKey(ChannelClientProperty.NICKLIST_BACKGROUND)) {
   101                  setBackground((Color) map.get(ChannelClientProperty.NICKLIST_BACKGROUND));
   102              }
   103          }
   104  
   105          setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
   106  
   107          return this;
   108      }
   109  
   110      /** {@inheritDoc} */
   111      @Override
   112      public void configChanged(final String domain, final String key) {
                 /* 
    P/P           *  Method: void configChanged(String, String)
                  * 
                  *  Preconditions:
                  *    this.config != null
                  *    this.nicklist != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.altBackgroundColour)
                  *    possibly_updated(this.showColours)
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@113: {0}, {1}
                  */
   113          if ("shownickcoloursinnicklist".equals(key)) {
   114              showColours = config.getOptionBool("ui", "shownickcoloursinnicklist");
   115  
   116          } else {
   117              altBackgroundColour =
   118                      config.getOptionColour(
   119                      "ui", "nickListAltBackgroundColour",
   120                      "ui", "nicklistbackgroundcolour",
   121                      "ui", "backgroundcolour");
   122          }
   123          nicklist.repaint();
   124      }
   125  }








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