File Source: PopupManager.java

         /* 
    P/P   *  Method: com.dmdirc.commandparser.PopupManager__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;
    24  
    25  import com.dmdirc.actions.ActionManager;
    26  import com.dmdirc.actions.CoreActionType;
    27  import com.dmdirc.config.ConfigManager;
    28  
    29  
    30  /**
    31   * The popup manager manages which commands should be present in popup menus.
    32   *
    33   * @author Chris
    34   */
    35  public class PopupManager {
    36      
    37      /**
    38       * Creates a new instance of PopupManager.
    39       */
             /* 
    P/P       *  Method: void com.dmdirc.commandparser.PopupManager()
              */
    40      private PopupManager() {
    41          // Shouldn't be instansiated.
    42      }
    43      
    44      /**
    45       * Returns the popup menu that should be used for the specified type.
    46       * Configuration data is read from the specified config manager.
    47       * 
    48       * @param menuType The type of the menu that is needed
    49       * @param configManager The config manager to be used for the menu
    50       * @return The PopupMenu that should be displayed
    51       */
    52      public static PopupMenu getMenu(final PopupType menuType, final ConfigManager configManager) {
                 /* 
    P/P           *  Method: PopupMenu getMenu(PopupType, ConfigManager)
                  * 
                  *  Preconditions:
                  *    configManager != null
                  *    menuType != null
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.actions.CoreActionType.CLIENT_POPUP_GENERATED)
                  * 
                  *  Postconditions:
                  *    return_value == &new PopupMenu(getMenu#1*)
                  *    new ArrayList(PopupMenu#1) num objects == 1
                  *    new PopupMenu(getMenu#1*) num objects == 1
                  *    new PopupMenu(getMenu#1*).items == &new ArrayList(PopupMenu#1)
                  */
    53          final PopupMenu menu = getMenu(menuType.toString(), configManager);
    54          
    55          ActionManager.processEvent(CoreActionType.CLIENT_POPUP_GENERATED, 
    56                  null, menuType, menu, configManager);
    57          
    58          return menu;
    59      }
    60      
    61      /**
    62       * Retrieves the menu with the specified name.
    63       * 
    64       * @param menuName The name of the menu to read
    65       * @param configManager The config manager to be used for the menu
    66       * @return The PopupMenu with the specified name
    67       */
    68      private static PopupMenu getMenu(final String menuName, final ConfigManager configManager) {
                 /* 
    P/P           *  Method: PopupMenu getMenu(String, ConfigManager)
                  * 
                  *  Preconditions:
                  *    configManager != null
                  * 
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@71 != null
                  * 
                  *  Postconditions:
                  *    return_value == &new PopupMenu(getMenu#1)
                  *    new ArrayList(PopupMenu#1) num objects == 1
                  *    new PopupMenu(getMenu#1) num objects == 1
                  *    return_value.items == &new ArrayList(PopupMenu#1)
                  * 
                  *  Test Vectors:
                  *    java.lang.String:charAt(...)@72: {0..59, 61..216-1}, {60}
                  *    java.lang.String:length(...)@72: {0}, {1..232-1}
                  *    java.util.Iterator:hasNext(...)@71: {0}, {1}
                  */
    69          final PopupMenu res = new PopupMenu();
    70          
    71          for (String item : configManager.getOptionList("popups", menuName)) {
    72              if (item.length() > 0 && item.charAt(0) == '<') {
    73                  res.addAll(getMenu(item.substring(1), configManager).getItems());
    74              } else {
    75                  res.add(getItem(item, configManager));
    76              }
    77          }
    78          
    79          return res;
    80      }
    81      
    82      /**
    83       * Creates a PopupMenuItem for the specified item.
    84       * 
    85       * @param item The item to be turned into a PopupMenuItem
    86       * @param configManager The config manager to beused for the menu
    87       * @return The corresponding PopupMenuItem
    88       */
    89      private static PopupMenuItem getItem(final String item, final ConfigManager configManager) {
    90          PopupMenuItem res;
    91          
                 /* 
    P/P           *  Method: PopupMenuItem getItem(String, ConfigManager)
                  * 
                  *  Preconditions:
                  *    (soft) configManager != null
                  *    (soft) item != null
                  * 
                  *  Presumptions:
                  *    java.lang.String:indexOf(...)@95 in {-231..-2, 0..232-2}
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.String:substring(...)._tainted)
                  *    return_value in Addr_Set{&amp;new PopupMenuItem(getItem#4),&amp;new PopupMenuItem(getItem#5),&amp;new PopupMenuItem(getItem#1)}
                  *    new ArrayList(PopupMenu#1) num objects <= 1
                  *    new PopupMenu(getMenu#1) num objects <= 1
                  *    new PopupMenu(getMenu#1).items == &amp;new ArrayList(PopupMenu#1)
                  *    new PopupMenuItem(getItem#1) num objects <= 1
                  *    new PopupMenuItem(getItem#1).divider == 1
                  *    new PopupMenuItem(getItem#1).submenu == null
                  *    new PopupMenuItem(getItem#4) num objects <= 1
                  *    new PopupMenuItem(getItem#4).divider == 0
                  *    ...
                  * 
                  *  Test Vectors:
                  *    java.lang.String:charAt(...)@105: {0..59, 61..216-1}, {60}
                  *    java.lang.String:equals(...)@92: {0}, {1}
                  *    java.lang.String:length(...)@105: {0}, {1..232-1}
                  */
    92          if ("-".equals(item)) {
    93              res = new PopupMenuItem();
    94          } else {
    95              final int colon = item.indexOf(':');
    96              
    97              if (colon == -1) {
    98                  throw new IllegalArgumentException("Invalid popup menu item: "
    99                          + item);
   100              }
   101              
   102              final String name = item.substring(0, colon);
   103              final String command = item.substring(colon + 1);
   104              
   105              if (command.length() > 0 && command.charAt(0) == '<') {
   106                  res = new PopupMenuItem(name, getMenu(command.substring(1), configManager));
   107              } else {
   108                  res = new PopupMenuItem(name, command);
   109              }
   110          }
   111          
   112          return res;
   113      }
   114      
   115  }








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