File Source: GlobalWindow.java

         /* 
    P/P   *  Method: com.dmdirc.GlobalWindow__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;
    24  
    25  import com.dmdirc.actions.wrappers.AliasWrapper;
    26  import com.dmdirc.commandparser.CommandManager;
    27  import com.dmdirc.commandparser.CommandType;
    28  import com.dmdirc.commandparser.parsers.GlobalCommandParser;
    29  import com.dmdirc.config.IdentityManager;
    30  import com.dmdirc.ui.WindowManager;
    31  import com.dmdirc.ui.input.TabCompleter;
    32  import com.dmdirc.ui.input.TabCompletionType;
    33  import com.dmdirc.ui.interfaces.InputWindow;
    34  
    35  /**
    36   * A window which can be used to execute global commands.
    37   *
    38   * @author chris
    39   */
         /* 
    P/P   *  Method: Window getFrame()
          * 
          *  Postconditions:
          *    return_value == this.window
          *    init'ed(return_value)
          */
    40  public class GlobalWindow extends WritableFrameContainer {
    41  
    42      /** The window we're using. */
    43      private final InputWindow window;
    44  
    45      /** The global window that's in use, if any. */
    46      private static GlobalWindow globalWindow;
    47  
    48      /** The tab completer we use. */
    49      private final TabCompleter tabCompleter;
    50  
    51      /** Creates a new instance of GlobalWindow. */
    52      public GlobalWindow() {
                 /* 
    P/P           *  Method: void com.dmdirc.GlobalWindow()
                  * 
                  *  Preconditions:
                  *    com/dmdirc/Main.controller != null
                  *    init'ed(com/dmdirc/actions/wrappers/AliasWrapper.me)
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.commandparser.CommandType.TYPE_GLOBAL)
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@53 != null
                  *    init'ed(com.dmdirc.ui.input.TabCompletionType.COMMAND)
                  *    com.dmdirc.ui.interfaces.InputWindow:getInputHandler(...)@64 != null
                  *    com.dmdirc.ui.interfaces.UIController:getInputWindow(...)@61 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    com/dmdirc/actions/wrappers/AliasWrapper.me == One-of{old com/dmdirc/actions/wrappers/AliasWrapper.me, &new AliasWrapper(getAliasWrapper#1)}
                  *    com/dmdirc/actions/wrappers/AliasWrapper.me != null
                  *    this.changer == &new FrameContainer$IconChanger(FrameContainer#2)
                  *    this.config != null
                  *    this.icon == &"icon"
                  *    this.listeners == &new ListenerList(FrameContainer#1)
                  *    this.notification == com/dmdirc/FrameContainer.java.awt.Color.BLACK
                  *    init'ed(this.notification)
                  *    this.tabCompleter == &new TabCompleter(GlobalWindow#1)
                  *    this.window != null
                  *    ...
                  */
    53          super("icon", IdentityManager.getGlobalConfig());
    54  
    55          tabCompleter = new TabCompleter();
    56          tabCompleter.addEntries(TabCompletionType.COMMAND,
    57                  CommandManager.getCommandNames(CommandType.TYPE_GLOBAL));
    58          tabCompleter.addEntries(TabCompletionType.COMMAND,
    59                  AliasWrapper.getAliasWrapper().getAliases());
    60  
    61          window = Main.getUI().getInputWindow(this, GlobalCommandParser.getGlobalCommandParser());
    62  
    63          window.setTitle("(Global)");
    64          window.getInputHandler().setTabCompleter(tabCompleter);
    65  
    66          WindowManager.addWindow(window);
    67  
    68          window.open();
    69      }
    70  
    71      /** {@inheritDoc} */
    72      @Override
    73      public InputWindow getFrame() {
                 /* 
    P/P           *  Method: InputWindow getFrame()
                  * 
                  *  Postconditions:
                  *    return_value == this.window
                  *    init'ed(return_value)
                  */
    74          return window;
    75      }
    76  
    77      /** {@inheritDoc} */
    78      @Override
    79      public String toString() {
                 /* 
    P/P           *  Method: String toString()
                  * 
                  *  Postconditions:
                  *    return_value == &"Global"
                  */
    80          return "Global";
    81      }
    82  
    83      /** {@inheritDoc} */
    84      @Override
    85      public void windowClosing() {
    86          // 1: Make the window non-visible
                 /* 
    P/P           *  Method: void windowClosing()
                  * 
                  *  Preconditions:
                  *    this.window != null
                  */
    87          window.setVisible(false);
    88  
    89          // 2: Remove any callbacks or listeners
    90          // 3: Trigger any actions neccessary
    91          // 4: Trigger action for the window closing
    92          // 5: Inform any parents that the window is closing
    93  
    94          // 6: Remove the window from the window manager
    95          WindowManager.removeWindow(window);
    96  
    97          // 7: Remove any references to the window and parents
    98      }
    99  
   100      /** {@inheritDoc} */
   101      @Override
   102      public Server getServer() {
                 /* 
    P/P           *  Method: Server getServer()
                  * 
                  *  Postconditions:
                  *    return_value == null
                  */
   103          return null;
   104      }
   105  
   106      /** {@inheritDoc} */
   107      @Override
   108      public void sendLine(final String line) {
                 /* 
    P/P           *  Method: void sendLine(String)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.commandparser.parsers.GlobalCommandParser:getGlobalCommandParser(...)@109 != null
                  */
   109          GlobalCommandParser.getGlobalCommandParser().parseCommand(window,
   110                  CommandManager.getCommandChar() + line);
   111      }
   112  
   113      /** {@inheritDoc} */
   114      @Override
   115      public int getMaxLineLength() {
                 /* 
    P/P           *  Method: int getMaxLineLength()
                  * 
                  *  Postconditions:
                  *    return_value == -1
                  */
   116          return -1;
   117      }
   118  
   119      /**
   120       * Retrieves the tab completer used by this global window.
   121       *
   122       * @return This global window's tab completer.
   123       */
   124      public TabCompleter getTabCompleter() {
                 /* 
    P/P           *  Method: TabCompleter getTabCompleter()
                  * 
                  *  Postconditions:
                  *    return_value == this.tabCompleter
                  *    init'ed(return_value)
                  */
   125          return tabCompleter;
   126      }
   127      
   128      /**
   129       * Initialises the global window if it's enabled in the config.
   130       */
   131      public static void init() {
                 /* 
    P/P           *  Method: void init()
                  * 
                  *  Preconditions:
                  *    (soft) com/dmdirc/Main.controller != null
                  *    (soft) init'ed(com/dmdirc/actions/wrappers/AliasWrapper.me)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@132 != null
                  * 
                  *  Postconditions:
                  *    com/dmdirc/actions/wrappers/AliasWrapper.me == One-of{old com/dmdirc/actions/wrappers/AliasWrapper.me, &new AliasWrapper(getAliasWrapper#1)}
                  *    init'ed(com/dmdirc/actions/wrappers/AliasWrapper.me)
                  *    globalWindow == One-of{old globalWindow, &new GlobalWindow(init#1)}
                  *    new AliasWrapper(getAliasWrapper#1) num objects <= 1
                  *    init'ed(new AliasWrapper(getAliasWrapper#1).actions)
                  *    init'ed(new AliasWrapper(getAliasWrapper#1).aliases)
                  *    init'ed(new AliasWrapper(getAliasWrapper#1).author)
                  *    init'ed(new AliasWrapper(getAliasWrapper#1).component)
                  *    init'ed(new AliasWrapper(getAliasWrapper#1).description)
                  *    init'ed(new AliasWrapper(getAliasWrapper#1).name)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.config.ConfigManager:getOptionBool(...)@132: {0}, {1}
                  */
   132          if (IdentityManager.getGlobalConfig().getOptionBool("general", "showglobalwindow")) {
   133              globalWindow = new GlobalWindow();
   134          }        
   135      }
   136  
   137      /**
   138       * Retrieves the global window if it has been previously opened by
   139       * {@link #init()}.
   140       *
   141       * @return A Global Window instance or null
   142       */
   143      public static GlobalWindow getGlobalWindow() {
                 /* 
    P/P           *  Method: GlobalWindow getGlobalWindow()
                  * 
                  *  Preconditions:
                  *    init'ed(globalWindow)
                  * 
                  *  Postconditions:
                  *    return_value == globalWindow
                  *    init'ed(return_value)
                  */
   144          return globalWindow;
   145      }
   146  
   147  }








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