File Source: WindowStatusPlugin.java

         /* 
    P/P   *  Method: com.dmdirc.addons.windowstatus.WindowStatusPlugin__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.windowstatus;
    24  
    25  import com.dmdirc.Channel;
    26  import com.dmdirc.FrameContainer;
    27  import com.dmdirc.Main;
    28  import com.dmdirc.Query;
    29  import com.dmdirc.Server;
    30  import com.dmdirc.actions.ActionManager;
    31  import com.dmdirc.actions.CoreActionType;
    32  import com.dmdirc.actions.interfaces.ActionType;
    33  import com.dmdirc.config.Identity;
    34  import com.dmdirc.config.IdentityManager;
    35  import com.dmdirc.config.prefs.PreferencesCategory;
    36  import com.dmdirc.config.prefs.PreferencesManager;
    37  import com.dmdirc.config.prefs.PreferencesSetting;
    38  import com.dmdirc.config.prefs.PreferencesType;
    39  import com.dmdirc.interfaces.ActionListener;
    40  import com.dmdirc.parser.irc.ChannelClientInfo;
    41  import com.dmdirc.parser.irc.ChannelInfo;
    42  import com.dmdirc.parser.irc.ClientInfo;
    43  import com.dmdirc.plugins.Plugin;
    44  import com.dmdirc.ui.interfaces.InputWindow;
    45  import com.dmdirc.ui.interfaces.Window;
    46  
    47  import java.util.Hashtable;
    48  import java.util.Map;
    49  import java.util.Map.Entry;
    50  
    51  /**
    52   * Displays information related to the current window in the status bar.
    53   *
    54   * @author Shane 'Dataforce' McCormack
    55   */
    56  public final class WindowStatusPlugin extends Plugin implements ActionListener {
    57  
    58  	/** The panel we use in the status bar. */
    59  	private final WindowStatusPanel panel = new WindowStatusPanel();
    60  
    61  	/** Creates a new instance of WindowStatusPlugin. */
    62  	public WindowStatusPlugin() {
        		 /* 
    P/P 		  *  Method: void com.dmdirc.addons.windowstatus.WindowStatusPlugin()
        		  * 
        		  *  Postconditions:
        		  *    this.panel == &new WindowStatusPanel(WindowStatusPlugin#1)
        		  *    new JLabel(WindowStatusPanel#1) num objects == 1
        		  *    new WindowStatusPanel(WindowStatusPlugin#1) num objects == 1
        		  *    this.panel.label == &new JLabel(WindowStatusPanel#1)
        		  */
    63  		super();
    64  	}
    65  
    66  	/**
    67  	 * Called when the plugin is loaded.
    68  	 */
    69      @Override
    70  	public void onLoad() {
        		 /* 
    P/P 		  *  Method: void onLoad()
        		  * 
        		  *  Presumptions:
        		  *    com.dmdirc.Main:getUI(...)@71 != null
        		  *    init'ed(com.dmdirc.actions.CoreActionType.CLIENT_FRAME_CHANGED)
        		  *    com.dmdirc.ui.interfaces.UIController:getStatusBar(...)@71 != null
        		  */
    71  		Main.getUI().getStatusBar().addComponent(panel);
    72  		updateStatus();
    73  
    74  		ActionManager.addListener(this, CoreActionType.CLIENT_FRAME_CHANGED);
    75  	}
    76  
    77  	/**
    78  	 * Called when this plugin is unloaded.
    79  	 */
    80      @Override
    81  	public void onUnload() {
        		 /* 
    P/P 		  *  Method: void onUnload()
        		  * 
        		  *  Presumptions:
        		  *    com.dmdirc.Main:getUI(...)@82 != null
        		  *    com.dmdirc.ui.interfaces.UIController:getStatusBar(...)@82 != null
        		  */
    82  		Main.getUI().getStatusBar().removeComponent(panel);
    83  		ActionManager.removeListener(this);
    84  	}
    85  
    86  	/**
    87  	 * Process an event of the specified type.
    88  	 *
    89  	 * @param type The type of the event to process
    90  	 * @param format Format of messages that are about to be sent. (May be null)
    91  	 * @param arguments The arguments for the event
    92  	 */
    93          @Override
    94  	public void processEvent(final ActionType type, final StringBuffer format, final Object... arguments) {
        		 /* 
    P/P 		  *  Method: void processEvent(ActionType, StringBuffer, Object[])
        		  * 
        		  *  Preconditions:
        		  *    type != null
        		  *    (soft) arguments != null
        		  *    (soft) arguments.length >= 1
        		  *    (soft) init'ed(arguments[0])
        		  * 
        		  *  Presumptions:
        		  *    init'ed(com.dmdirc.actions.CoreActionType.CLIENT_FRAME_CHANGED)
        		  * 
        		  *  Test Vectors:
        		  *    java.lang.Object:equals(...)@95: {0}, {1}
        		  */
    95  		if (type.equals(CoreActionType.CLIENT_FRAME_CHANGED)) {
    96  			updateStatus((FrameContainer) arguments[0]);
    97          }
    98  	}
    99  
   100  	/**
   101  	 * Update the window status using the current active window.
   102  	 */
   103  	public void updateStatus() {
        		 /* 
    P/P 		  *  Method: void updateStatus()
        		  * 
        		  *  Presumptions:
        		  *    com.dmdirc.Main:getUI(...)@104 != null
        		  * 
        		  *  Test Vectors:
        		  *    com.dmdirc.ui.interfaces.UIController:getActiveWindow(...)@104: Addr_Set{null}, Inverse{null}
        		  */
   104  		final Window active = Main.getUI().getActiveWindow();
   105  
   106  		if (active != null) {
   107  			updateStatus(((InputWindow) active).getContainer());
   108  		}
   109  	}
   110  
   111  	/**
   112  	 * Update the window status using a given FrameContainer as the active frame.
   113  	 *
   114  	 * @param current Window to use when adding status.
   115  	 */
   116  	public void updateStatus(final FrameContainer current) {
        		 /* 
    P/P 		  *  Method: void updateStatus(FrameContainer)
        		  * 
        		  *  Preconditions:
        		  *    (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
        		  *    (soft) init'ed(com/dmdirc/config/IdentityManager.globalconfig)
        		  *    (soft) this.panel != null
        		  *    (soft) this.panel.label != null
        		  * 
        		  *  Presumptions:
        		  *    com.dmdirc.Channel:getChannelInfo(...)@126 != null
        		  *    com.dmdirc.Query:getServer(...)@176 != null
        		  *    com.dmdirc.Query:getServer(...)@177 != null
        		  *    com.dmdirc.Server:getParser(...)@177 != null
        		  *    com.dmdirc.parser.irc.ChannelClientInfo:getImportantModePrefix(...)@137 != null
        		  *    ...
        		  * 
        		  *  Postconditions:
        		  *    init'ed(com/dmdirc/config/IdentityManager.globalconfig)
        		  *    java.lang.StringBuilder:toString(...)._tainted == 0
        		  *    init'ed(new ArrayList(getSources#1) num objects)
        		  *    new ArrayList(getSources#1) num objects == 0
        		  *    new ArrayList(getSources#1) num objects <= 1
        		  *    init'ed(new ConfigManager(getGlobalConfig#1) num objects)
        		  *    new ConfigManager(getGlobalConfig#1) num objects == 0
        		  *    new ConfigManager(getGlobalConfig#1) num objects <= 1
        		  *    init'ed(new ConfigManager(getGlobalConfig#1).channel)
        		  *    init'ed(new ConfigManager(getGlobalConfig#1).file)
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    current: Inverse{null}, Addr_Set{null}
        		  *    com.dmdirc.Channel:instanceof(...)@124: {0}, {1}
        		  *    com.dmdirc.Query:instanceof(...)@172: {0}, {1}
        		  *    com.dmdirc.Server:getParser(...)@176: Addr_Set{null}, Inverse{null}
        		  *    com.dmdirc.Server:instanceof(...)@120: {0}, {1}
        		  *    com.dmdirc.parser.irc.IRCParser:getClientInfo(...)@177: Addr_Set{null}, Inverse{null}
        		  *    java.lang.Boolean:parseBoolean(...)@159: {0}, {1}
        		  *    java.lang.String:isEmpty(...)@139: {0}, {1}
        		  *    java.lang.String:isEmpty(...)@180: {1}, {0}
        		  *    java.util.Iterator:hasNext(...)@133: {0}, {1}
        		  *    ...
        		  */
   117  		if (current == null) { return; }
   118  		final StringBuffer textString = new StringBuffer();
   119  
   120  		if (current instanceof Server) {
   121  			final Server frame = (Server)current;
   122  
   123  			textString.append(frame.getName());
   124  		} else if (current instanceof Channel) {
   125  			final Channel frame = (Channel) current;
   126  			final ChannelInfo chan = frame.getChannelInfo();
   127  			final Map<Long, String> names = new Hashtable<Long, String>();
   128  			final Map<Long, Integer> types = new Hashtable<Long, Integer>();
   129  
   130  			textString.append(chan.getName());
   131  			textString.append(" - Nicks: " + chan.getUserCount() + " (");
   132  
   133  			for (ChannelClientInfo client : chan.getChannelClients()) {
   134  				final Long im = client.getImportantModeValue();
   135  
   136  				if (!names.containsKey(im)) {
   137  					String mode = client.getImportantModePrefix();
   138  
   139  					if (mode.isEmpty()) {
   140  						if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "channel.shownone")) {
   141  							if (IdentityManager.getGlobalConfig().hasOptionString(getDomain(), "channel.noneprefix")) {
   142  								mode = IdentityManager.getGlobalConfig().getOption(getDomain(), "channel.noneprefix");
   143  							} else {
   144  								mode = "None:";
   145  							}
   146  						} else {
   147  							continue;
   148  						}
   149  					}
   150  					names.put(im, mode);
   151  				}
   152  
   153  				Integer count = types.get(im);
   154  
   155  				if (count == null) {
   156  					count = Integer.valueOf(1);
   157  				} else {
   158  					count++;
   159  				}
   160  				types.put(im, count);
   161  			}
   162  
   163  			boolean isFirst = true;
   164  
   165  			for (Entry<Long, Integer> entry : types.entrySet()) {
   166  				if (isFirst) { isFirst = false; } else { textString.append(' '); }
   167  				textString.append(names.get(entry.getKey()));
   168                  textString.append(entry.getValue());
   169  			}
   170  
   171  			textString.append(')');
   172  		} else if (current instanceof Query) {
   173  			final Query frame = (Query) current;
   174  
   175  			textString.append(frame.getHost());
   176  			if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "client.showname") && frame.getServer().getParser() != null) {
   177  				final ClientInfo client = frame.getServer().getParser().getClientInfo(frame.getHost());
   178  				if (client != null) {
   179  					final String realname = client.getRealName();
   180  					if (!realname.isEmpty()) {
   181  						textString.append(" - ");
   182                          textString.append(client.getRealName());
   183  					}
   184  				}
   185  			}
   186  		} else {
   187  			textString.append("???");
   188  		}
   189  		panel.setText(textString.toString());
   190  	}
   191  
   192  	/** {@inheritDoc} */
   193          @Override
   194  	public void showConfig(final PreferencesManager manager) {
                         /* 
    P/P                   *  Method: void showConfig(PreferencesManager)
                          * 
                          *  Preconditions:
                          *    manager != null
                          *    manager.categories != null
                          *    init'ed(com/dmdirc/config/IdentityManager.globalconfig)
                          *    (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
                          * 
                          *  Presumptions:
                          *    category.isInline@198 == 1
                          *    getCategory(...).subcats@208 != null
                          * 
                          *  Postconditions:
                          *    com/dmdirc/config/IdentityManager.globalconfig != null
                          *    java.lang.StringBuilder:toString(...)._tainted == 0
                          *    new ArrayList(getSources#1) num objects == 0
                          *    new ConfigManager(getGlobalConfig#1) num objects == 0
                          *    new MapList(ConfigManager#1) num objects == 0
                          *    new ArrayList(getSources#1) num objects <= 1
                          *    new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
                          *    new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
                          *    new ConfigManager(getGlobalConfig#1).channel == &amp;java.lang.StringBuilder:toString(...)
                          *    init'ed(new ConfigManager(getGlobalConfig#1).channel)
                          *    ...
                          */
   195                  final PreferencesCategory category
   196                          = new PreferencesCategory("Window status", "");
   197  
   198                  category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
   199                          getDomain(), "channel.shownone", "Show 'none' count",
   200                          "Should the count for users with no state be shown?"));
   201                  category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
   202                          getDomain(), "channel.noneprefix", "'None' count prefix",
   203                          "The Prefix to use when showing the 'none' count"));
   204                  category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
   205                          getDomain(), "client.showname", "Show real name",
   206                          "Should the realname for clients be shown if known?"));
   207  
   208  		manager.getCategory("Plugins").addSubCategory(category);
   209  	}
   210  }








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